Esempio n. 1
0
int main(int argc, char** argv)
{
    printf("%s %s, Copyright 2015 by OneXSoft\n\n", APP_NAME, APP_VERSION);

    const char* cfgFile = "onecache.xml";
    if (argc == 1) {
        LOG(Logger::Message, "No config file specified. using the default config(%s)", cfgFile);
    }
    if (argc >= 2) {
        cfgFile = argv[1];
    }

    CRedisProxyCfg* cfg = CRedisProxyCfg::instance();
    if (!cfg->loadCfg(cfgFile)) {
        LOG(Logger::Error, "Failed to read config file");
        return 1;
    }

    const char* errInfo;
    if (!CRedisProxyCfgChecker::isValid(cfg, errInfo)) {
        LOG(Logger::Error, "Invalid configuration: %s", errInfo);
        return 1;
    }

    FileLogger fileLogger;
    if (fileLogger.setFileName(cfg->logFile())) {
        LOG(Logger::Message, "Using the log file(%s) output", fileLogger.fileName());
        Logger::setDefaultLogger(&fileLogger);
    }

    GlobalLogOption::__debug = cfg->debug();

    const char* pidfile = cfg->pidFile();
    bool pidfile_enabled = (strlen(pidfile) > 0);
    if (pidfile_enabled) {
        createPidFile(pidfile);
    }

    //Background
    if (cfg->daemonize()) {
        NonPortable::daemonize();
    }

    //Guard
    if (cfg->guard()) {
        NonPortable::guard(startOneCache, APP_EXIT_KEY);
    } else {
        startOneCache();
    }

    if (pidfile_enabled) {
        remove(pidfile);
    }

    return 0;
}