175
191
int min_wait = Setting_get_int("limits.tick_timer", 10);
176
192
taskdelay(min_wait * 1000);
178
// don't bother if these are all 0
179
int min_ping = Setting_get_int("limits.min_ping", DEFAULT_MIN_PING);
180
int min_write_rate = Setting_get_int("limits.min_write_rate", DEFAULT_MIN_READ_RATE);
181
int min_read_rate = Setting_get_int("limits.min_read_rate", DEFAULT_MIN_WRITE_RATE);
183
if(min_ping > 0 || min_write_rate > 0 || min_read_rate > 0) {
184
int cleared = Register_cleanout();
187
log_warn("Timeout task killed %d tasks, waiting %d seconds for more.", cleared, min_wait);
189
debug("No connections timed out.");
194
// avoid doing this during a reload attempt
196
// don't bother if these are all 0
197
int min_ping = Setting_get_int("limits.min_ping", DEFAULT_MIN_PING);
198
int min_write_rate = Setting_get_int("limits.min_write_rate", DEFAULT_MIN_READ_RATE);
199
int min_read_rate = Setting_get_int("limits.min_read_rate", DEFAULT_MIN_WRITE_RATE);
201
if(min_ping > 0 || min_write_rate > 0 || min_read_rate > 0) {
202
int cleared = Register_cleanout();
205
log_warn("Timeout task killed %d tasks, waiting %d seconds for more.", cleared, min_wait);
207
debug("No connections timed out.");
211
// do a server queue cleanup to get rid of dead servers
212
Server_queue_cleanup();
195
218
int attempt_chroot_drop(Server *srv)
199
222
if(Unixy_chroot(srv->chroot) == 0) {
200
223
log_info("All loaded up, time to turn into a server.");
202
check(access("/run", F_OK) == 0, "/run directory doesn't exist in %s or isn't owned right.", bdata(srv->chroot));
203
check(access("/tmp", F_OK) == 0, "/tmp directory doesn't exist in %s or isn't owned right.", bdata(srv->chroot));
224
log_info("-- Starting " VERSION ". Copyright (C) Zed A. Shaw. Licensed BSD.\n");
225
log_info("-- Look in %s for startup messages and errors.", bdata(srv->error_log));
205
227
rc = Unixy_daemonize();
206
228
check(rc == 0, "Failed to daemonize, looks like you're hosed.");
296
321
Setting_destroy();
299
log_info("Removing pid file %s", bdata(srv->pid_file));
300
rc = unlink((const char *)srv->pid_file->data);
301
check(rc != -1, "Failed to unlink pid_file: %s", bdata(srv->pid_file));
324
if(access((char *)srv->pid_file->data, F_OK) == 0) {
325
log_info("Removing pid file %s", bdata(srv->pid_file));
326
rc = unlink((const char *)srv->pid_file->data);
327
check(rc != -1, "Failed to unlink pid_file: %s", bdata(srv->pid_file));
330
rc = Server_queue_destroy();
331
check(rc == 0, "Failed cleaning up the server run queue.");
310
const int TICKER_TASK_STACK = 16 * 1024;
342
void reload_task(void *data)
344
RELOAD_TASK = taskself();
345
struct ServerTask *srv = data;
352
log_info("Reload requested, will load %s from %s", bdata(srv->db_file), bdata(srv->server_id));
353
Server *old_srv = Server_queue_latest();
354
Server *new_srv = reload_server(old_srv, bdata(srv->db_file), bdata(srv->server_id));
355
check(new_srv, "Failed to load the new configuration, exiting.");
357
// for this to work handlers need to die more gracefully
358
Server_queue_push(new_srv);
360
log_info("Shutdown requested, goodbye.");
312
370
void taskmain(int argc, char **argv)
314
372
dbg_set_log(stderr);
317
check(argc == 3 || argc == 4, "usage: mongrel2 config.sqlite server_uuid [config_module.so]");
375
check(argc == 3 || argc == 4, "usage: %s config.sqlite server_uuid [config_module.so]", m2program);
320
log_info("Using configuration module %s to load configs.",
378
log_info("Using configuration module %s to load configs.", argv[3]);
322
379
rc = Config_module_load(argv[3]);
323
380
check(rc != -1, "Failed to load the config module: %s", argv[3]);
326
SERVER = load_server(argv[1], argv[2], NULL);
327
check(SERVER, "Aborting since can't load server.");
385
Server *srv = load_server(argv[1], argv[2], NULL);
386
check(srv != NULL, "Aborting since can't load server.");
387
Server_queue_push(srv);
329
389
SuperPoll_get_max_fd();
331
rc = clear_pid_file(SERVER);
391
rc = clear_pid_file(srv);
332
392
check(rc == 0, "PID file failure, aborting rather than trying to start.");
334
rc = attempt_chroot_drop(SERVER);
394
rc = attempt_chroot_drop(srv);
335
395
check(rc == 0, "Major failure in chroot/droppriv, aborting.");
339
Control_port_start();
340
399
taskcreate(tickertask, NULL, TICKER_TASK_STACK);
343
log_info("Starting " VERSION ". Copyright (C) Zed A. Shaw. Licensed BSD.");
344
Server_start(SERVER);
347
log_info("Reload requested, will load %s from %s", argv[2], argv[1]);
348
Server *new_srv = reload_server(SERVER, argv[1], argv[2]);
349
check(new_srv, "Failed to load the new configuration, exiting.");
351
// for this to work handlers need to die more gracefully
354
log_info("Shutdown requested, goodbye.");
359
complete_shutdown(SERVER);
401
struct ServerTask *srv_data = calloc(1, sizeof(struct ServerTask));
402
srv_data->db_file = bfromcstr(argv[1]);
403
srv_data->server_id = bfromcstr(argv[2]);
405
taskcreate(reload_task, srv_data, RELOAD_TASK_STACK);
408
check(rc != -1, "Server had a failure and exited early.");
409
log_info("Server run exited, goodbye.");
411
srv = Server_queue_latest();
412
complete_shutdown(srv);