#include #include #include #include #include #include "myconf.h" #include "utils.h" extern int myapp_run(myconf_t*); static char doc[] = "xce_controller"; static char args_doc[] = ""; const char* argp_program_version = MK_VERSION("xce v0.0.1-", STR(VERSION_COMMIT_ID)); const char* argp_program_bug_address = BUG_EMAIL; struct arguments { char* config; char* logdir; char* clusterconf; int verbose; }; static struct argp_option options[] = { { "config", 'c', "FILE", 0, "Load initial configuration from FILE" }, { "logdir", 'd', "DIR", 0, "Directory for log file" }, { "verbose", 'v', 0, 0, "Produce verbose logs" }, { "clusterconf", 'f', "FILE", 0, "Load Cluster Configuration from FILE" }, { 0 } }; static error_t parse_opt(int key, char* arg, struct argp_state* state) { struct arguments* arguments = state->input; switch (key) { case 'c': arguments->config = arg; break; case 'd': arguments->logdir = arg; break; case 'v': arguments->verbose++; break; case 'f': arguments->clusterconf = arg; break; default: return ARGP_ERR_UNKNOWN; } return 0; } static struct argp argp = { options, parse_opt, args_doc, doc }; static char* verbose_to_loglevel(int verbose) { char* loglevel = "info"; switch (verbose) { case 1: loglevel = "debug"; break; case 2: loglevel = "debug2"; break; case 3: loglevel = "debug3"; break; default: if (verbose > 3) { loglevel = "debug3"; } break; } return loglevel; } int main(int argc, char* argv[]) { struct arguments arguments; myconf_t myconf; char* logdir = "/tmp"; char* loglevel = "info"; int logsize = 64 * 1024 * 1024; int logcount = 10; char* myname = "xce_controller"; 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.verbose != 0) { loglevel = verbose_to_loglevel(arguments.verbose); } mylog_init(logdir, myname, loglevel, logsize, logcount); myconf.cluster_config = NULL; myconf.conffile = arguments.clusterconf; myapp_run(&myconf); mylog_fini(); return 0; }