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