1 // System management commands for Citadel server
3 // Copyright (c) 1987-2021 by the citadel.org team
5 // This program is open source software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License, version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
14 #include <libcitadel.h>
16 #include "serv_extensions.h"
17 #include "ctdl_module.h"
20 // Shut down or restart the server
21 void cmd_down(char *argbuf) {
22 char *Reply ="%d Shutting down server. Goodbye.\n";
24 if (CtdlAccessCheck(ac_aide)) return;
26 if (!IsEmptyStr(argbuf)) {
28 restart_server = extract_int(argbuf, 0);
30 if (restart_server > 0) {
31 Reply = "%d citserver will now shut down and automatically restart.\n";
33 cprintf(Reply, state);
36 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
38 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
39 server_shutting_down = 1;
43 // Halt the server without exiting the server process.
44 void cmd_halt(char *argbuf) {
45 if (CtdlAccessCheck(ac_aide)) return;
47 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
48 server_shutting_down = 1;
49 shutdown_and_halt = 1;
53 // Schedule or cancel a server shutdown
54 void cmd_scdn(char *argbuf) {
57 char *Reply = "%d %d\n";
59 if (CtdlAccessCheck(ac_aide)) return;
61 new_state = extract_int(argbuf, 0);
62 if ((new_state == 2) || (new_state == 3)) {
64 restart_server = extract_int(argbuf, 0);
67 if ((new_state == 0) || (new_state == 1)) {
68 ScheduledShutdown = new_state;
70 cprintf(Reply, state, ScheduledShutdown);
74 // ****************************************************************************
75 // * MODULE INITIALIZATION STUFF *
76 // ****************************************************************************
78 CTDL_MODULE_INIT(syscmd)
81 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
82 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
83 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
85 // return our id for the log