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) {
37 Reply = "%d citserver will now shut down and automatically restart.\n";
39 cprintf(Reply, state);
42 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
44 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
45 server_shutting_down = 1;
50 * Halt the server without exiting the server process.
52 void cmd_halt(char *argbuf) {
54 if (CtdlAccessCheck(ac_aide)) return;
56 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
57 server_shutting_down = 1;
58 shutdown_and_halt = 1;
63 * Schedule or cancel a server shutdown
65 void cmd_scdn(char *argbuf)
69 char *Reply = "%d %d\n";
71 if (CtdlAccessCheck(ac_aide)) return;
73 new_state = extract_int(argbuf, 0);
74 if ((new_state == 2) || (new_state == 3)) {
76 restart_server = extract_int(argbuf, 0);
79 if ((new_state == 0) || (new_state == 1)) {
80 ScheduledShutdown = new_state;
82 cprintf(Reply, state, ScheduledShutdown);
86 /*****************************************************************************/
87 /* MODULE INITIALIZATION STUFF */
88 /*****************************************************************************/
90 CTDL_MODULE_INIT(syscmd)
93 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
94 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
95 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
97 /* return our id for the Log */