1 // System management commands for Citadel server
3 // Copyright (c) 1987-2022 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 the server
21 void cmd_down(char *argbuf) {
22 if (CtdlAccessCheck(ac_aide)) return;
23 cprintf("%d Shutting down server. Goodbye.\n", CIT_OK + SERVER_SHUTTING_DOWN);
24 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
25 server_shutting_down = 1;
29 // Halt the server without exiting the server process.
30 void cmd_halt(char *argbuf) {
31 if (CtdlAccessCheck(ac_aide)) return;
33 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
34 server_shutting_down = 1;
35 shutdown_and_halt = 1;
39 // Schedule or cancel a server shutdown
40 void cmd_scdn(char *argbuf) {
43 char *Reply = "%d %d\n";
45 if (CtdlAccessCheck(ac_aide)) return;
47 new_state = extract_int(argbuf, 0);
48 if ((new_state == 2) || (new_state == 3)) {
50 restart_server = extract_int(argbuf, 0);
53 if ((new_state == 0) || (new_state == 1)) {
54 ScheduledShutdown = new_state;
56 cprintf(Reply, state, ScheduledShutdown);
60 // Initialization function, called from modules_init.c
61 char *ctdl_module_init_syscmd(void) {
63 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
64 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
65 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
67 // return our id for the log