* New HALT command shuts down server but suspends instead of exiting.
authorArt Cancro <ajc@citadel.org>
Thu, 6 Jul 2006 02:44:20 +0000 (02:44 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 6 Jul 2006 02:44:20 +0000 (02:44 +0000)
* setup.c: fixed a citadel.config path problem that prevented alternative dir installations
from working properly

citadel/citserver.c
citadel/citserver.h
citadel/setup.c
citadel/sysdep.c
citadel/sysdep_decls.h
citadel/techdoc/protocol.txt

index 411773d08cf3971e99e9c7b7e442fc8a8a527189..dca5ce0ea02c5e1faf77b00db0ed774b2b67aed4 100644 (file)
@@ -185,6 +185,15 @@ void master_cleanup(int exitcode) {
        dump_heap();
 #endif
 
+       /* If the operator requested a halt but not an exit, halt here. */
+       if (shutdown_and_halt) {
+               lprintf(CTDL_NOTICE, "citserver: Halting server without exiting.\n");
+               fflush(stdout); fflush(stderr);
+               while(1) {
+                       sleep(32767);
+               }
+       }
+
        /* Now go away. */
        lprintf(CTDL_NOTICE, "citserver: Exiting with status %d\n", exitcode);
        fflush(stdout); fflush(stderr);
@@ -765,6 +774,18 @@ void cmd_down(void) {
        time_to_die = 1;
 }
 
+/*
+ * Halt the server without exiting the server process.
+ */
+void cmd_halt(void) {
+
+       if (CtdlAccessCheck(ac_aide)) return;
+
+       cprintf("%d Halting server.  Goodbye.\n", CIT_OK);
+       time_to_die = 1;
+       shutdown_and_halt = 1;
+}
+
 /*
  * Schedule or cancel a server shutdown
  */
@@ -1234,6 +1255,10 @@ void do_command_loop(void) {
                cmd_down();
        }
 
+       else if (!strncasecmp(cmdbuf,"HALT",4)) {
+               cmd_halt();
+       }
+
        else if (!strncasecmp(cmdbuf,"SCDN",4)) {
                cmd_scdn(&cmdbuf[5]);
        }
index dd599cb3ec5b560a92dd31b1fab709e84a54bc4f..f09f3214e4c928e304252d04a06186c3dad5f39d 100644 (file)
@@ -27,6 +27,7 @@ void cmd_more (void);
 void cmd_echo (char *etext);
 void cmd_ipgm (char *argbuf);
 void cmd_down (void);
+void cmd_halt (void);
 void cmd_scdn (char *argbuf);
 void cmd_extn (char *argbuf);
 void do_command_loop(void);
index 8a8effd78c57f331357218e4bacaa0438e381739..7c6e6f121781cb0f762801f703f3be3bf84789a7 100644 (file)
@@ -85,7 +85,7 @@ char *setup_text[] = {
 "specify a directory other than the default, you will need to\n"
 "specify the -h flag to the server when you start it up.\n",
 #else
-"Enter the subdirectoryname for an alternating installation of "
+"Enter the subdirectory name for an alternate installation of "
 "Citadel. To do a default installation just leave it blank."
 "If you specify a directory other than the default, you will need to\n"
 "specify the -h flag to the server when you start it up.\n"
@@ -929,13 +929,7 @@ void write_config_to_disk(void)
        FILE *fp;
        int fd;
 
-       if ((fd = creat(
-#ifndef HAVE_ETC_DIR
-                                       "."
-#else
-                                       ETC_DIR
-#endif
-                                       "/citadel.config", S_IRUSR | S_IWUSR)) == -1) {
+       if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
                display_error("setup: cannot open citadel.config");
                cleanup(1);
        }
@@ -1142,20 +1136,26 @@ int main(int argc, char *argv[])
 
        home=(setup_directory[1]!='\0');
        relh=home&(setup_directory[1]!='/');
-       if (!relh) safestrncpy(ctdl_home_directory, setup_directory,
-                                                                  sizeof ctdl_home_directory);
-       else
-               safestrncpy(relhome, ctdl_home_directory,
-                                       sizeof relhome);
+       if (!relh) {
+               safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
+       }
+       else {
+               safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
+       }
 
        calc_dirs_n_files(relh, home, relhome, ctdldir);
        
        enable_home=(relh|home);
 
-       if ((home) && (chdir(setup_directory) != 0)) {
-               important_message("Citadel Setup",
-                         "The directory you specified does not exist.");
-               cleanup(errno);
+       if (home) {
+               if (chdir(setup_directory) == 0) {
+                       strcpy(file_citadel_config, "./citadel.config");
+               }
+               else {
+                       important_message("Citadel Setup",
+                               "The directory you specified does not exist.");
+                       cleanup(errno);
+               }
        }
 
        /* Determine our host name, in case we need to use it as a default */
index 33fde1e5157cf9106575fa8cfbef3fd64d6a1c53..7d65e6c8a646f605b643f4a215b36033a91f5df6 100644 (file)
@@ -154,6 +154,7 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
  */
 
 volatile int time_to_die = 0;
+volatile int shutdown_and_halt = 0;
 
 static RETSIGTYPE signal_cleanup(int signum) {
        lprintf(CTDL_DEBUG, "Caught signal %d; shutting down.\n", signum);
index c805176a0f5a5d3cf8ad0da10e11297243347585..d92d28e5710c96fc205c9679d6db48b7a37e87a7 100644 (file)
@@ -74,6 +74,8 @@ void create_worker(void);
 
 extern int num_sessions;
 extern volatile int time_to_die;
+extern volatile int shutdown_and_halt;
+
 extern int verbosity;
 extern int rescan[];
 
index b368ae7e475a136686b4875233654e96c15d353b..712a887222d30ae048730cff2d750686e064bad5 100644 (file)
@@ -1666,6 +1666,14 @@ otherwise, it returns OK followed by a number representing the current state
 of the flag.
 
 
+ HALT   (HALT the server without shutting it down)
+ Identical to the DOWN command, except instead of exiting, the server process
+cleans up and then suspends indefinitely.  This could potentially be useful for
+shutdown scripts that don't want init to automatically respawn another citserver
+process.
+
+
  EMSG   (Enter a system MeSsaGe)
 
  This is the opposite of the MESG command - it allows the creation and editing