forked from viabtc/viabtc_exchange_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathac_main.c
96 lines (79 loc) · 2.1 KB
/
ac_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Description:
* History: [email protected], 2016/04/19, create
*/
# include "ac_config.h"
# include "ac_server.h"
# include "ut_title.h"
# include "ut_signal.h"
const char *version = "0.1.0";
nw_timer cron_timer;
static void on_cron_check(nw_timer *timer, void *data)
{
dlog_check_all();
if (signal_exit) {
nw_loop_break();
}
}
static int init_process(void)
{
if (settings.process.file_limit) {
if (set_file_limit(settings.process.file_limit) < 0) {
return -__LINE__;
}
}
if (settings.process.core_limit) {
if (set_core_limit(settings.process.core_limit) < 0) {
return -__LINE__;
}
}
return 0;
}
static int init_log(void)
{
default_dlog = dlog_init(settings.log.path, DLOG_SHIFT_BY_DAY, 100*1024*1024, 10, 7);
if (default_dlog == NULL)
return -__LINE__;
default_dlog_flag = dlog_read_flag(settings.log.flag);
return 0;
}
int main(int argc, char *argv[])
{
printf("process: %s version: %s, compile date: %s %s\n", "blockmaster", version, __DATE__, __TIME__);
if (argc != 2) {
printf("usage: %s config.json\n", argv[0]);
exit(EXIT_FAILURE);
}
if (process_exist("alertcenter.exe") != 0) {
printf("process exist\n");
exit(EXIT_FAILURE);
}
process_title_init(argc, argv);
process_title_set("alertcenter.exe");
int ret;
ret = load_config(argv[1]);
if (ret < 0) {
error(EXIT_FAILURE, errno, "load config fail: %d", ret);
}
ret = init_process();
if (ret < 0) {
error(EXIT_FAILURE, errno, "init process fail: %d", ret);
}
ret = init_log();
if (ret < 0) {
error(EXIT_FAILURE, errno, "init log fail: %d", ret);
}
daemon(1, 1);
process_keepalive();
ret = init_server();
if (ret < 0) {
error(EXIT_FAILURE, errno, "init server fail: %d", ret);
}
nw_timer_set(&cron_timer, 0.1, true, on_cron_check, NULL);
nw_timer_start(&cron_timer);
log_vip("server start");
dlog_stderr("server start");
nw_loop_run();
log_vip("server stop");
return 0;
}