3 * Main source module for the Citadel server
5 * Copyright (c) 1987-2018 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.
17 #include <libcitadel.h>
19 #include "serv_extensions.h"
20 #include "ctdl_module.h"
24 * Shut down the server
26 void cmd_down(char *argbuf) {
27 char *Reply ="%d Shutting down server. Goodbye.\n";
29 if (CtdlAccessCheck(ac_aide)) return;
31 if (!IsEmptyStr(argbuf))
34 restart_server = extract_int(argbuf, 0);
36 if (restart_server > 0)
38 Reply = "%d citserver will now shut down and automatically restart.\n";
40 if ((restart_server > 0) && !running_as_daemon)
42 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
43 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
46 cprintf(Reply, state);
50 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
52 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
53 server_shutting_down = 1;
58 * Halt the server without exiting the server process.
60 void cmd_halt(char *argbuf) {
62 if (CtdlAccessCheck(ac_aide)) return;
64 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
65 server_shutting_down = 1;
66 shutdown_and_halt = 1;
71 * Schedule or cancel a server shutdown
73 void cmd_scdn(char *argbuf)
77 char *Reply = "%d %d\n";
79 if (CtdlAccessCheck(ac_aide)) return;
81 new_state = extract_int(argbuf, 0);
82 if ((new_state == 2) || (new_state == 3))
85 if (!running_as_daemon)
87 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
88 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
92 restart_server = extract_int(argbuf, 0);
95 if ((new_state == 0) || (new_state == 1)) {
96 ScheduledShutdown = new_state;
98 cprintf(Reply, state, ScheduledShutdown);
102 /*****************************************************************************/
103 /* MODULE INITIALIZATION STUFF */
104 /*****************************************************************************/
106 CTDL_MODULE_INIT(syscmd)
109 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
110 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
111 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
113 /* return our id for the Log */