]> code.citadel.org Git - citadel.git/blob - citadel/server/modules/ctdlproto/serv_syscmds.c
CtdlCheckExpress() now accepts a session context.
[citadel.git] / citadel / server / modules / ctdlproto / serv_syscmds.c
1 // System management commands for Citadel server
2 //
3 // Copyright (c) 1987-2022 by the citadel.org team
4 //
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.
7 //
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.
12
13 #include <stdio.h>
14 #include <libcitadel.h>
15
16 #include "../../serv_extensions.h"
17 #include "../../ctdl_module.h"
18
19
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;
26 }
27
28
29 // Halt the server without exiting the server process.
30 void cmd_halt(char *argbuf) {
31         if (CtdlAccessCheck(ac_aide)) return;
32
33         cprintf("%d Halting server.  Goodbye.\n", CIT_OK);
34         server_shutting_down = 1;
35         shutdown_and_halt = 1;
36 }
37
38
39 // Schedule or cancel a server shutdown
40 void cmd_scdn(char *argbuf) {
41         int new_state;
42         int state = CIT_OK;
43         char *Reply = "%d %d\n";
44
45         if (CtdlAccessCheck(ac_aide)) return;
46
47         new_state = extract_int(argbuf, 0);
48         if ((new_state == 2) || (new_state == 3)) {
49                 restart_server = 1;
50                 restart_server = extract_int(argbuf, 0);
51                 new_state -= 2;
52         }
53         if ((new_state == 0) || (new_state == 1)) {
54                 ScheduledShutdown = new_state;
55         }
56         cprintf(Reply, state, ScheduledShutdown);
57 }
58
59
60 // Initialization function, called from modules_init.c
61 char *ctdl_module_init_syscmd(void) {
62         if (!threading) {
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");
66         }
67         // return our id for the log
68         return "syscmd";
69 }