3 * Main source module for the Citadel server
5 * Copyright (c) 1987-2011 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"
22 void cmd_log_get(char *argbuf)
29 if (CtdlAccessCheck(ac_aide)) return;
31 cprintf("%d Log modules enabled:\n", LISTING_FOLLOWS);
33 Pos = GetNewHashPos(LogDebugEntryTable, 0);
35 while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) {
36 LogDebugEntry *E = (LogDebugEntry*)vptr;
37 cprintf("%s|%d\n", ch, *E->LogP);
43 void cmd_log_set(char *argbuf)
50 if (CtdlAccessCheck(ac_aide)) return;
52 wlen = extract_token(which, argbuf, 0, '|', sizeof(which));
53 if (wlen < 0) wlen = 0;
54 lset = extract_int(argbuf, 1);
55 if (lset != 0) lset = 1;
56 if (GetHash(LogDebugEntryTable, which, wlen, &vptr) &&
59 LogDebugEntry *E = (LogDebugEntry*)vptr;
61 cprintf("%d %s|%d\n", CIT_OK, which, lset);
64 cprintf("%d Log setting %s not known\n",
71 * Shut down the server
73 void cmd_down(char *argbuf) {
74 char *Reply ="%d Shutting down server. Goodbye.\n";
76 if (CtdlAccessCheck(ac_aide)) return;
78 if (!IsEmptyStr(argbuf))
81 restart_server = extract_int(argbuf, 0);
83 if (restart_server > 0)
85 Reply = "%d citserver will now shut down and automatically restart.\n";
87 if ((restart_server > 0) && !running_as_daemon)
89 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
90 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
93 cprintf(Reply, state);
97 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
99 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
100 server_shutting_down = 1;
105 * Halt the server without exiting the server process.
107 void cmd_halt(char *argbuf) {
109 if (CtdlAccessCheck(ac_aide)) return;
111 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
112 server_shutting_down = 1;
113 shutdown_and_halt = 1;
118 * Schedule or cancel a server shutdown
120 void cmd_scdn(char *argbuf)
124 char *Reply = "%d %d\n";
126 if (CtdlAccessCheck(ac_aide)) return;
128 new_state = extract_int(argbuf, 0);
129 if ((new_state == 2) || (new_state == 3))
132 if (!running_as_daemon)
134 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
135 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
139 restart_server = extract_int(argbuf, 0);
142 if ((new_state == 0) || (new_state == 1)) {
143 ScheduledShutdown = new_state;
145 cprintf(Reply, state, ScheduledShutdown);
149 * Manually initiate log file cull.
151 void cmd_cull(char *argbuf) {
152 if (CtdlAccessCheck(ac_internal)) return;
154 cprintf("%d Database log file cull completed.\n", CIT_OK);
159 /*****************************************************************************/
160 /* MODULE INITIALIZATION STUFF */
161 /*****************************************************************************/
163 CTDL_MODULE_INIT(syscmd)
166 CtdlRegisterProtoHook(cmd_log_get, "LOGP", "Print Log-parameters");
167 CtdlRegisterProtoHook(cmd_log_set, "LOGS", "Set Log-parameters");
169 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
170 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
171 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
173 CtdlRegisterProtoHook(cmd_cull, "CULL", "Cull database logs");
175 /* return our id for the Log */