3 * Main source module for the Citadel server
5 * Copyright (c) 1987-2011 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
22 #include <sys/types.h>
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #include <libcitadel.h>
52 #include "sysdep_decls.h"
54 #include "citserver.h"
57 #include "housekeeping.h"
61 #include "locate_host.h"
64 #include "euidindex.h"
66 #include "svn_revision.h"
67 #include "ctdl_module.h"
72 * Shut down the server
74 void cmd_down(char *argbuf) {
75 char *Reply ="%d Shutting down server. Goodbye.\n";
77 if (CtdlAccessCheck(ac_aide)) return;
79 if (!IsEmptyStr(argbuf))
82 restart_server = extract_int(argbuf, 0);
84 if (restart_server > 0)
86 Reply = "%d citserver will now shut down and automatically restart.\n";
88 if ((restart_server > 0) && !running_as_daemon)
90 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
91 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
94 cprintf(Reply, state);
98 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
100 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
101 server_shutting_down = 1;
106 * Halt the server without exiting the server process.
108 void cmd_halt(char *argbuf) {
110 if (CtdlAccessCheck(ac_aide)) return;
112 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
113 server_shutting_down = 1;
114 shutdown_and_halt = 1;
119 * Schedule or cancel a server shutdown
121 void cmd_scdn(char *argbuf)
125 char *Reply = "%d %d\n";
127 if (CtdlAccessCheck(ac_aide)) return;
129 new_state = extract_int(argbuf, 0);
130 if ((new_state == 2) || (new_state == 3))
133 if (!running_as_daemon)
135 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
136 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
140 restart_server = extract_int(argbuf, 0);
143 if ((new_state == 0) || (new_state == 1)) {
144 ScheduledShutdown = new_state;
146 cprintf(Reply, state, ScheduledShutdown);
150 /*****************************************************************************/
151 /* MODULE INITIALIZATION STUFF */
152 /*****************************************************************************/
154 CTDL_MODULE_INIT(syscmd)
157 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
158 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
159 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
161 /* return our id for the Log */