root/src/noitd.c

Revision 06f58e662d9dcb103af43ff53f3bd7e72248cea4, 2.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

prep for jlog transit over SSL

  • Property mode set to 100644
Line 
1 #include "noit_defines.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <sys/ioctl.h>
8 #include <fcntl.h>
9
10 #include "eventer/eventer.h"
11 #include "utils/noit_log.h"
12 #include "utils/noit_hash.h"
13 #include "noit_listener.h"
14 #include "noit_console.h"
15 #include "noit_jlog_listener.h"
16 #include "noit_module.h"
17 #include "noit_conf.h"
18 #include "noit_conf_checks.h"
19
20 #define APPNAME "noit"
21
22 static char *config_file = ETC_DIR "/" APPNAME ".conf";
23 static int debug = 0;
24
25 void parse_clargs(int argc, char **argv) {
26   int c;
27   while((c = getopt(argc, argv, "c:d")) != EOF) {
28     switch(c) {
29       case 'c':
30         config_file = strdup(optarg);
31         break;
32       case 'd':
33         debug++;
34         break;
35       default:
36         break;
37     }
38   }
39 }
40
41 static
42 int configure_eventer() {
43   int rv = 0;
44   noit_hash_table *table;
45   table = noit_conf_get_hash(NULL, "/" APPNAME "/eventer/config");
46   if(table) {
47     noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
48     const char *key, *value;
49     int klen;
50     while(noit_hash_next(table, &iter, &key, &klen, (void **)&value)) {
51       int subrv;
52       if((subrv = eventer_propset(key, value)) != 0)
53         rv = subrv;
54     }
55     noit_hash_destroy(table, free, free);
56     free(table);
57   }
58   return rv;
59 }
60
61 int main(int argc, char **argv) {
62   char conf_str[1024];
63
64   parse_clargs(argc, argv);
65
66   /* First initialize logging, so we can log errors */
67   noit_log_init();
68   noit_log_stream_add_stream(noit_debug, noit_stderr);
69   noit_log_stream_add_stream(noit_error, noit_stderr);
70
71   /* Next load the configs */
72   noit_conf_init(APPNAME);
73   noit_conf_checks_init(APPNAME);
74   if(noit_conf_load(config_file) == -1) {
75     fprintf(stderr, "Cannot load config: '%s'\n", config_file);
76   }
77
78   /* Reinitialize the logging system now that we have a config */
79   noit_conf_log_init(APPNAME);
80   if(debug)
81     noit_debug->enabled = 1;
82
83   /* Lastly, run through all other system inits */
84   if(!noit_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation",
85                               conf_str, sizeof(conf_str))) {
86     noitL(noit_stderr, "Cannot find '%s' in configuration\n",
87           "/" APPNAME "/eventer/@implementation");
88     exit(-1);
89   }
90   if(eventer_choose(conf_str) == -1) {
91     noitL(noit_stderr, "Cannot choose eventer %s\n", conf_str);
92     exit(-1);
93   }
94   if(configure_eventer() != 0) {
95     noitL(noit_stderr, "Cannot configure eventer\n");
96     exit(-1);
97   }
98   if(eventer_init() == -1) {
99     noitL(noit_stderr, "Cannot init eventer %s\n", conf_str);
100     exit(-1);
101   }
102   /* Initialize all of our listeners */
103   noit_console_init();
104   noit_jlog_listener_init();
105
106   noit_module_init();
107   noit_poller_init();
108   noit_listener_init(APPNAME);
109
110   eventer_loop();
111   return 0;
112 }
Note: See TracBrowser for help on using the browser.