static int child_main() { /* reload our config, to make sure we have the most current */ if(mtev_conf_load(NULL) == -1) { mtevL(mtev_error, "Cannot load config: '%s'\n", config_file); exit(2); } eventer_init(); mtev_console_init(APPNAME); mtev_capabilities_listener_init(); mtev_events_rest_init(); mtev_listener_init(APPNAME); mtev_dso_init(); mtev_dso_post_init(); mtev_websocket_client_callbacks callbacks = { websocket_ready_handler, websocket_msg_handler, websocket_cleanup_handler }; (void)mtev_websocket_client_new("127.0.0.1", 8888, "/", "echo-protocol", &callbacks); /* Lastly, spin up the event loop */ eventer_loop(); return 0; }
static int child_main() { /* reload our config, to make sure we have the most current */ if(mtev_conf_load(NULL) == -1) { mtevL(mtev_error, "Cannot load config: '%s'\n", config_file); exit(2); } eventer_init(); mtev_console_init(APPNAME); mtev_http_rest_init(); mtev_capabilities_listener_init(); mtev_events_rest_init(); mtev_listener_init(APPNAME); mtev_dso_init(); mtev_dso_post_init(); mtev_http_rest_register("GET", "/", "^(.*)$", my_rest_handler); /* for 'echo-protocol' see websocket_client.js */ mtev_http_rest_websocket_register("/", "^(.*)$", "echo-protocol", my_websocket_msg_handler); /* Lastly, spin up the event loop */ eventer_loop(); return 0; }
static int child_main() { int log_flags; mtev_conf_section_t section; char *err = NULL; cli_stdout = mtev_log_stream_new_on_fd("stdout", 1, NULL); log_flags = mtev_log_stream_get_flags(mtev_stderr); log_flags &= ~(MTEV_LOG_STREAM_FACILITY|MTEV_LOG_STREAM_TIMESTAMPS); mtev_log_stream_set_flags(mtev_stderr, log_flags); /* reload our config, to make sure we have the most current */ if(mtev_conf_load(NULL) == -1) { mtevL(mtev_error, "Cannot load config: '%s'\n", config_file); if(needs_unlink) unlink(config_file); exit(2); } mtev_conf_security_init(APPNAME, droptouser, droptogroup, NULL); if(mtev_conf_write_file(&err) != 0) { if(err) { mtevL(mtev_stderr, "Error: '%s'\n", err); free(err); } mtevL(mtev_stderr, "Permissions issue, are you running as the right user?\n"); exit(2); } if(needs_unlink) unlink(config_file); /* update the lua module */ section = mtev_conf_get_section(NULL, "/cli/modules/generic[@name=\"lua_general\"]/config"); if(!section || !mtev_conf_set_string(section, "lua_module", lua_file)) { mtevL(mtev_stderr, "Cannot set target lua module, invalid config.\n"); exit(2); } eventer_init(); mtev_dso_init(); mtev_dso_post_init(); if(mtev_dso_load_failures() > 0) { mtevL(mtev_stderr, "Failed to initialize.\n"); exit(2); } if(interactive) { mtev_console_init(APPNAME); mtev_console_conf_init(APPNAME); eventer_set_fd_nonblocking(STDIN_FILENO); if(mtev_console_std_init(STDIN_FILENO, STDOUT_FILENO)) { mtevL(mtev_stderr, "Failed to initialize IO\n"); exit(2); } } /* Lastly, spin up the event loop */ eventer_loop(); return 0; }
static int child_main() { char conf_str[1024]; char stratcon_version[80]; mtev_watchdog_child_heartbeat(); /* Next (re)load the configs */ if(mtev_conf_load(config_file) == -1) { fprintf(stderr, "Cannot load config: '%s'\n", config_file); exit(2); } mtev_log_reopen_all(); mtevL(noit_notice, "process starting: %d\n", (int)getpid()); mtev_log_go_asynch(); /* Lastly, run through all other system inits */ if(!mtev_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation", conf_str, sizeof(conf_str))) { mtevL(noit_stderr, "Cannot find '%s' in configuration\n", "/" APPNAME "/eventer/@implementation"); exit(2); } if(eventer_choose(conf_str) == -1) { mtevL(noit_stderr, "Cannot choose eventer %s\n", conf_str); exit(2); } if(configure_eventer() != 0) { mtevL(noit_stderr, "Cannot configure eventer\n"); exit(2); } if(eventer_init() == -1) { mtevL(noit_stderr, "Cannot init eventer %s\n", conf_str); exit(2); } /* rotation init requires, eventer_init() */ mtev_conf_log_init_rotate(APPNAME, mtev_false); mtev_watchdog_child_eventer_heartbeat(); mtev_console_init(APPNAME); mtev_console_conf_init(); mtev_http_rest_init(); mtev_reverse_socket_init(reverse_prefix, reverse_prefix_cns); mtev_reverse_socket_acl(mtev_reverse_socket_denier); mtev_events_rest_init(); stratcon_realtime_http_init(APPNAME); mtev_capabilities_listener_init(); noit_build_version(stratcon_version, sizeof(stratcon_version)); mtev_capabilities_add_feature("stratcon", stratcon_version); mtev_listener_init(APPNAME); mtev_dso_init(); mtev_dso_post_init(); if(strict_module_load && mtev_dso_load_failures() > 0) { mtevL(noit_stderr, "Failed to load some modules and -M given.\n"); exit(2); } if(stratcon_datastore_get_enabled()) stratcon_datastore_init(); /* Drop privileges */ mtev_conf_security_init(APPNAME, droptouser, droptogroup, chrootpath); stratcon_jlog_streamer_init(APPNAME); if(stratcon_iep_get_enabled()) stratcon_iep_init(); if(stratcon_datastore_get_enabled()) { /* Write our log out, and setup a watchdog to write it out on change. */ stratcon_datastore_saveconfig(NULL); mtev_conf_coalesce_changes(10); /* 10 seconds of no changes before we write */ } else mtev_conf_coalesce_changes(INT_MAX); mtev_conf_watch_and_journal_watchdog(stratcon_datastore_saveconfig, NULL); eventer_loop(); return 0; }