reshape controller startup
This commit is contained in:
parent
9f91f3df80
commit
a665ccd4fe
5 changed files with 32 additions and 33 deletions
|
|
@ -15,17 +15,15 @@ const char* argp_program_version = MK_VERSION("xce v0.0.1-", STR(VERSION_CO
|
|||
const char* argp_program_bug_address = BUG_EMAIL;
|
||||
|
||||
struct arguments {
|
||||
char* config;
|
||||
char* logdir;
|
||||
char* clusterconf;
|
||||
char* logfile;
|
||||
char* workdir;
|
||||
int verbose;
|
||||
};
|
||||
|
||||
static struct argp_option options[] = {
|
||||
{ "config", 'c', "FILE", 0, "Load initial configuration from FILE" },
|
||||
{ "logdir", 'd', "DIR", 0, "Directory for log file" },
|
||||
{ "workdir", 'w', "DIR", 0, "The work directory of xce controller"},
|
||||
{ "logfile", 'l', "FILE", 0, "The full path of log file" },
|
||||
{ "verbose", 'v', 0, 0, "Produce verbose logs" },
|
||||
{ "clusterconf", 'f', "FILE", 0, "Load Cluster Configuration from FILE" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
|
@ -36,17 +34,14 @@ static error_t parse_opt(int key,
|
|||
struct arguments* arguments = state->input;
|
||||
|
||||
switch (key) {
|
||||
case 'c':
|
||||
arguments->config = arg;
|
||||
break;
|
||||
case 'd':
|
||||
arguments->logdir = arg;
|
||||
case 'l':
|
||||
arguments->logfile = arg;
|
||||
break;
|
||||
case 'v':
|
||||
arguments->verbose++;
|
||||
break;
|
||||
case 'f':
|
||||
arguments->clusterconf = arg;
|
||||
case 'w':
|
||||
arguments->workdir = arg;
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
|
|
@ -90,33 +85,39 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
struct arguments arguments;
|
||||
myconf_t myconf;
|
||||
char* logdir = "/tmp";
|
||||
char* logfile = "/tmp/xce_controller.log";
|
||||
char* loglevel = "info";
|
||||
int logsize = 64 * 1024 * 1024;
|
||||
int logcount = 10;
|
||||
char* myname = "xce_controller";
|
||||
char conf_file[XCE_MAXPATH_LEN+1];
|
||||
|
||||
memset(&arguments, 0x0, sizeof(arguments));
|
||||
|
||||
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
||||
|
||||
if (arguments.clusterconf == NULL) {
|
||||
tlog_error("no cluster configuration specified. please use -f to specify cluster configuration file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arguments.logdir != NULL) {
|
||||
logdir = arguments.logdir;
|
||||
if (arguments.logfile != NULL) {
|
||||
logfile = arguments.logfile;
|
||||
}
|
||||
|
||||
if (arguments.verbose != 0) {
|
||||
loglevel = verbose_to_loglevel(arguments.verbose);
|
||||
}
|
||||
|
||||
mylog_init(logdir, myname, loglevel, logsize, logcount);
|
||||
|
||||
mylog_init(logfile, loglevel, logsize, logcount);
|
||||
|
||||
if (arguments.workdir == NULL) {
|
||||
INFO("no cluster work directory specified. The default work directory `"
|
||||
DEFAULT_WORKDIR
|
||||
"' will be used.");
|
||||
arguments.workdir = DEFAULT_WORKDIR;
|
||||
}
|
||||
|
||||
memset(&conf_file, 0x0, sizeof(conf_file));
|
||||
snprintf(conf_file, XCE_MAXPATH_LEN,
|
||||
"%s/conf/current_config", arguments.workdir);
|
||||
|
||||
myconf.cluster_config = NULL;
|
||||
myconf.conffile = arguments.clusterconf;
|
||||
myconf.conffile = conf_file;
|
||||
|
||||
myapp_run(&myconf);
|
||||
|
||||
|
|
|
|||
|
|
@ -2311,7 +2311,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
struct arguments arguments;
|
||||
char* buf;
|
||||
char* logdir = "/tmp";
|
||||
char* logfile = "/tmp/xce_test.log";
|
||||
char* loglevel = "info";
|
||||
int logsize = 64 * 1024 * 1024;
|
||||
int logcount = 10;
|
||||
|
|
@ -2323,7 +2323,7 @@ int main(int argc, char* argv[])
|
|||
loglevel = verbose_to_loglevel(arguments.verbose);
|
||||
}
|
||||
|
||||
mylog_init(logdir, "xce_test", loglevel, logsize, logcount);
|
||||
mylog_init(logfile, loglevel, logsize, logcount);
|
||||
|
||||
signal(SIGINT, sigbreak);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#define _CONFIG_H_
|
||||
|
||||
#define BUG_EMAIL "rshen@shenrs.eu"
|
||||
#define DEFAULT_WORKDIR "/tmp/xce"
|
||||
|
||||
#define XCE_MAXNAME_LEN (64)
|
||||
#define XCE_MAXHOSTNAME_LEN (256) /* hostname suggest to 256 */
|
||||
#define XCE_MAXDESC_LEN (4096) /* enlarge to 4096 */
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ extern capn_text chars_to_text(const char*);
|
|||
extern int parse_argv(char*, char***);
|
||||
extern void free_argv(char**, int);
|
||||
extern void freeup_kvs(int, xce_kv_t*);
|
||||
extern int mylog_init(char*, char*, char*, int, int);
|
||||
extern int mylog_init(char*, char*, int, int);
|
||||
extern void mylog_fini(void);
|
||||
extern int mylog_setlevel(char*);
|
||||
extern void set_error(char*, char*, int, int);
|
||||
|
|
|
|||
|
|
@ -292,18 +292,14 @@ static int my_tlog_format(char* buff,
|
|||
/* return total length */
|
||||
return total_len;
|
||||
}
|
||||
int mylog_init(char* logdir,
|
||||
char* id,
|
||||
int mylog_init(char* logfile,
|
||||
char* loglvl,
|
||||
int max_log_size,
|
||||
int max_log_count)
|
||||
{
|
||||
char logfile[XCE_MAXPATH_LEN];
|
||||
int flag = 0;
|
||||
int rc = 0;
|
||||
|
||||
snprintf(logfile, sizeof(logfile),
|
||||
"%s/%s.log", logdir, id);
|
||||
if (isatty(STDERR_FILENO)) {
|
||||
flag = TLOG_SCREEN_COLOR;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue