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.
22 #include <sys/types.h>
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #include <libcitadel.h>
52 #include "sysdep_decls.h"
54 #include "citserver.h"
57 #include "housekeeping.h"
61 #include "locate_host.h"
64 #include "euidindex.h"
66 #include "svn_revision.h"
67 #include "ctdl_module.h"
69 void cmd_log_get(char *argbuf)
76 if (CtdlAccessCheck(ac_aide)) return;
78 cprintf("%d Log modules enabled:\n", LISTING_FOLLOWS);
80 Pos = GetNewHashPos(LogDebugEntryTable, 0);
82 while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) {
83 LogDebugEntry *E = (LogDebugEntry*)vptr;
84 cprintf("%s|%d\n", ch, *E->LogP);
90 void cmd_log_set(char *argbuf)
97 if (CtdlAccessCheck(ac_aide)) return;
99 wlen = extract_token(which, argbuf, 0, '|', sizeof(which));
100 if (wlen < 0) wlen = 0;
101 lset = extract_int(argbuf, 1);
102 if (lset != 0) lset = 1;
103 if (GetHash(LogDebugEntryTable, which, wlen, &vptr) &&
106 LogDebugEntry *E = (LogDebugEntry*)vptr;
108 cprintf("%d %s|%d\n", CIT_OK, which, lset);
111 cprintf("%d Log setting %s not known\n",
118 * Shut down the server
120 void cmd_down(char *argbuf) {
121 char *Reply ="%d Shutting down server. Goodbye.\n";
123 if (CtdlAccessCheck(ac_aide)) return;
125 if (!IsEmptyStr(argbuf))
128 restart_server = extract_int(argbuf, 0);
130 if (restart_server > 0)
132 Reply = "%d citserver will now shut down and automatically restart.\n";
134 if ((restart_server > 0) && !running_as_daemon)
136 syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n");
137 Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n";
140 cprintf(Reply, state);
144 cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN);
146 CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
147 server_shutting_down = 1;
152 * Halt the server without exiting the server process.
154 void cmd_halt(char *argbuf) {
156 if (CtdlAccessCheck(ac_aide)) return;
158 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
159 server_shutting_down = 1;
160 shutdown_and_halt = 1;
165 * Schedule or cancel a server shutdown
167 void cmd_scdn(char *argbuf)
171 char *Reply = "%d %d\n";
173 if (CtdlAccessCheck(ac_aide)) return;
175 new_state = extract_int(argbuf, 0);
176 if ((new_state == 2) || (new_state == 3))
179 if (!running_as_daemon)
181 syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n");
182 Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n";
186 restart_server = extract_int(argbuf, 0);
189 if ((new_state == 0) || (new_state == 1)) {
190 ScheduledShutdown = new_state;
192 cprintf(Reply, state, ScheduledShutdown);
196 * Manually initiate log file cull.
198 void cmd_cull(char *argbuf) {
199 if (CtdlAccessCheck(ac_internal)) return;
201 cprintf("%d Database log file cull completed.\n", CIT_OK);
206 /*****************************************************************************/
207 /* MODULE INITIALIZATION STUFF */
208 /*****************************************************************************/
210 CTDL_MODULE_INIT(syscmd)
213 CtdlRegisterProtoHook(cmd_log_get, "LOGP", "Print Log-parameters");
214 CtdlRegisterProtoHook(cmd_log_set, "LOGS", "Set Log-parameters");
216 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
217 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
218 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
220 CtdlRegisterProtoHook(cmd_cull, "CULL", "Cull database logs");
222 /* return our id for the Log */