示例#1
0
bool mq_store_init(const char *log_path, const char *data_path)
{
    memset(&g_info, '\0', sizeof(app_info_t));
    memset(&g_last_info, '\0', sizeof(app_info_t));

    /* initial configure. */
    strcpy(g_mq_conf.data_file_path, data_path);
    strcpy(g_mq_conf.output_log_path, log_path);
#ifdef DISABLE_STORE_SPACE
    // g_mq_conf.res_store_space = 0;
#endif

    /* log open. */
    log_config_t log_conf;
    log_init_config(&log_conf);
    strcpy(log_conf.log_path, g_mq_conf.output_log_path);
    // log_conf.log_level = LOG_DEBUG;
    log_conf.log_level = LOG_INFO;
    if (log_init(&log_conf) != 0) {
        log_error("mq log init error.");
        return false;
    }

    /* UCMQ store open */
    log_info("Initial mq store.");
    if (!mq_qm_open_store())
    {
        log_error("Store Open fail");
        return false;
    }

    /* Get sum of all queue unread count */
    g_info.count = mq_qm_get_store_count();
    log_info("All queue's total unread msg count[%"PRIu64"]", g_info.count);

    return true;
}
示例#2
0
文件: main.c 项目: 26597925/ucmq
int main(int argc, char *argv[])
{
    int     opt_char;
    int     ret_code;
    bool    daemon_flag = false;

    static const char *short_opts = "c:dhv";
    struct option long_opts[] = {
        {"help",   no_argument, 0, 'h'},
        {"version",no_argument, 0, 'v'},
        {"deamon", no_argument, 0, 'd'},
        {"config", required_argument, 0, 'c'},
        {0, 0, 0, 0}
    };

    while ((opt_char = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1)
    {
        switch (opt_char)
        {
            case 'c':
                SET_STR_OPT(g_mq_conf.conf_file);
                break;
            case 'd':
                daemon_flag = true;
                break;
            case 'v':
                print_version();
                return 0;
            case 'h':
            default :
                print_usage();
                return 0; 
        }
    }

    /* If arguments contain -c, the config file was already processed */
    if (!read_conf_file())
    {    
        fprintf(stderr, "ERROR: Read config fail, Please use the right conf\n");
        return 1;
    }    

    /* Init log */
    {
        log_config_t mq_log;

        log_init_config(&mq_log);
        strcpy(mq_log.log_path, g_mq_conf.output_log_path);
        strcpy(mq_log.log_file,"ucmq_log");
        if (strcmp(g_mq_conf.output_log_level, "TRACE") == 0)
        {
            mq_log.log_level = 0;
        }
        else if (strcmp(g_mq_conf.output_log_level, "DEBUG") == 0)
        {
            mq_log.log_level = 10;
        }
        else if (strcmp(g_mq_conf.output_log_level, "INFO") == 0)
        {
            mq_log.log_level = 100;
        }
        else if (strcmp(g_mq_conf.output_log_level, "WARN") == 0)
        {
            mq_log.log_level = 1000;
        }
        else if (strcmp(g_mq_conf.output_log_level, "ERROR") == 0)
        {
            mq_log.log_level = 10000;
        }
        else if (strcmp(g_mq_conf.output_log_level, "FATAL") == 0)
        {
            mq_log.log_level = 65535;
        }
        else
        {
            mq_log.log_level = 100;
        }
        log_init(&mq_log);
    }

    if (daemon_flag)
    {
        /* Set daemon */
        set_daemon();
        set_signal_handle();
        log_info("<%s> Startup ... Daemon mode %s", argv[0], "on");
        ret_code = main_entrance();
        log_info("<%s> ShutDown Ok", argv[0]);
    }
    else
    {
        set_signal_handle();
        log_info("<%s> Startup ... Daemon mode %s", argv[0], "off");
        ret_code = main_entrance();
        log_info("<%s> ShutDown Ok", argv[0]);
    }

    return ret_code;
}