Finished converting Citadel setup to ctdlsvc + initscripts.
authorArt Cancro <ajc@citadel.org>
Tue, 28 Nov 2006 16:42:09 +0000 (16:42 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 28 Nov 2006 16:42:09 +0000 (16:42 +0000)
citadel/Makefile.in
citadel/ctdlsvc.c
citadel/setup.c

index e7562db07a00ac6d28595c9dcca20c55ebaa008c..aa06e58dabd9d1339826a45e48eccad649c116c2 100644 (file)
@@ -26,7 +26,7 @@ all: $(TARGETS)
 EXEEXT=@EXEEXT@
 
 CLIENT_TARGETS=citadel$(EXEEXT) whobbs$(EXEEXT) stress$(EXEEXT)
-SERVER_TARGETS=citserver setup $(CHKPWD)
+SERVER_TARGETS=citserver setup ctdlsvc $(CHKPWD)
 SERV_MODULES=serv_chat.o \
        serv_upgrade.o \
        serv_smtp.o \
@@ -102,7 +102,7 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c citadel.c citadel_ipc.c \
        serv_newuser.c serv_pas2.c serv_pop3.c serv_rwho.c serv_smtp.c \
        serv_spam.c serv_test.c serv_mrtg.c serv_spam.c serv_upgrade.c \
        serv_vandelay.c serv_vcard.c serv_managesieve.c server_main.c \
-       serv_sieve.c setup.c snprintf.c \
+       serv_sieve.c setup.c ctdlsvc.c snprintf.c \
        stress.c support.c sysdep.c tools.c user_ops.c userlist.c \
        whobbs.c vcard.c serv_notes.c serv_fulltext.c ft_wordbreaker.c \
        crc16.c journaling.c citadel_dirs.c
@@ -158,6 +158,9 @@ citmail: citmail.o config.o citadel_dirs.o
 setup: setup.o tools.o citadel_dirs.o
        $(CC) setup.o tools.o citadel_dirs.o $(LDFLAGS) -o setup $(LIBS) $(SETUP_LIBS)
 
+ctdlsvc: ctdlsvc.o citadel_dirs.o
+       $(CC) ctdlsvc.o citadel_dirs.o $(LDFLAGS) -o ctdlsvc $(SETUP_LIBS)
+
 chkpwd: chkpwd.o auth.o config.o citadel_dirs.o
        $(CC) chkpwd.o auth.o config.o citadel_dirs.o $(LDFLAGS) -o chkpwd $(chkpwd_LIBS)
        chmod 4755 chkpwd
index 865efc29854a0cb49790ec8de89209242e8e2314..69f60327c898f226a23a7468d5e5294ba4ecddca 100644 (file)
@@ -17,7 +17,7 @@
 char *pidfilename = NULL;
 pid_t current_child = 0;
 
-RETSIGTYPE graceful_shutdown(int signum) {
+void graceful_shutdown(int signum) {
        kill(current_child, signum);
        if (pidfilename != NULL) {
                unlink(pidfilename);
index bf973e266374b425a33c0414a7acaf2d22d41335..08673310b5007ec170d0bcdf519cb906d8a24d36 100644 (file)
@@ -357,8 +357,8 @@ void check_services_entry(void)
        FILE *sfp;
 
        if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
-               for (i=0; i<=3; ++i) {
-                       progress("Adding service entry...", i, 3);
+               for (i=0; i<=2; ++i) {
+                       progress("Adding service entry...", i, 2);
                        if (i == 0) {
                                sfp = fopen("/etc/services", "a");
                                if (sfp == NULL) {
@@ -439,6 +439,72 @@ void delete_inittab_entry(void)
 }
 
 
+/*
+ * install_init_scripts()  -- Try to configure to start Citadel at boot
+ *
+ */
+void install_init_scripts(void)
+{
+       FILE *fp;
+
+       if (yesno("Would you like to automatically start Citadel at boot?\n") == 0) {
+               return;
+       }
+
+       fp = fopen("/etc/init.d/citadel", "w");
+       if (fp == NULL) {
+               display_error("Cannot create /etc/init.d/citadel");
+               return;
+       }
+
+       fprintf(fp,     "#!/bin/sh\n"
+                       "\n"
+                       "CITADEL_DIR=%s\n", setup_directory);
+       fprintf(fp,     "\n"
+                       "test -x $CITADEL_DIR/ctdlsvc || exit 0\n"
+                       "test -d /var/run || exit 0\n"
+                       "\n"
+                       "case \"$1\" in\n"
+                       "\n"
+                       "start)         echo -n \"Starting Citadel... \"\n"
+                       "               if $CITADEL_DIR/ctdlsvc /var/run/citadel.pid "
+                                                       "$CITADEL_DIR/citserver "
+                                                       "-t/dev/null\n"
+                       "               then\n"
+                       "                       echo \"ok\"\n"
+                       "               else\n"
+                       "                       echo \"failed\"\n"
+                       "               fi\n");
+       fprintf(fp,     "               ;;\n"
+                       "stop)          echo -n \"Stopping Citadel... \"\n"
+                       "               if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
+                       "                       echo \"ok\"\n"
+                       "               else\n"
+                       "                       echo \"failed\"\n"
+                       "               fi\n"
+                       "               rm -f /var/run/citadel.pid 2>/dev/null\n");
+       fprintf(fp,     "               ;;\n"
+                       "*)             echo \"Usage: $0 {start|stop}\"\n"
+                       "               exit 1\n"
+                       "               ;;\n"
+                       "esac\n"
+       );
+
+       fclose(fp);
+       chmod("/etc/init.d/citadel", 0755);
+
+       /* Set up the run levels. */
+       system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
+       system("for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/citadel /etc/rc$x.d/S79citadel ; done 2>/dev/null");
+       system("for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/citadel /etc/rc$x.d/K30citadel ; done 2>/dev/null");
+
+}
+
+
+
+
+
+
 /*
  * On systems which use xinetd, see if we can offer to install Citadel as
  * the default telnet target.
@@ -994,6 +1060,15 @@ int main(int argc, char *argv[])
        /* Determine our host name, in case we need to use it as a default */
        uname(&my_utsname);
 
+       /* Try to stop Citadel if we can */
+       if (!access("/etc/init.d/citadel", X_OK)) {
+               for (a=0; a<=2; ++a) {
+                       progress("Stopping the Citadel service...", a, 2);
+                       if (a == 0) system("/etc/init.d/citadel stop >/dev/null 2>&1");
+                       sleep(1);
+               }
+       }
+
        /* Make sure Citadel is not running. */
        if (test_server() == 0) {
                important_message("Citadel Setup",
@@ -1267,16 +1342,36 @@ NEW_INST:
        sleep(1);
        progress("Setting file permissions", 4, 4);
 
-       /* See if we can start the Citadel service. */
-       /* FIXME do this */
+       /* 
+        * If we're running on SysV, install init scripts.
+        */
+       if (!access("/var/run", W_OK)) {
+               install_init_scripts();
+
+               if (!access("/etc/init.d/citadel", X_OK)) {
+                       for (a=0; a<=2; ++a) {
+                               progress("Starting the Citadel service...", a, 2);
+                               if (a == 0) system("/etc/init.d/citadel start >/dev/null 2>&1");
+                               sleep(1);
+                       }
+               }
+
+               if (test_server() == 0) {
+                       important_message("Setup finished",
+                               "Setup of the Citadel server is complete.\n"
+                               "If you will be using WebCit, please run its\n"
+                               "setup program now; otherwise, run './citadel'\n"
+                               "to log in.\n");
+               }
+               else {
+                       important_message("Setup failed",
+                               "Setup is finished, but the Citadel server failed to start.\n"
+                               "Go back and check your configuration.\n"
+                       );
+               }
 
-       if (test_server() == 0) {
-               important_message("Setup finished",
-                       "Setup of the Citadel server is complete.\n"
-                       "If you will be using WebCit, please run its\n"
-                       "setup program now; otherwise, run './citadel'\n"
-                       "to log in.\n");
        }
+
        else {
                important_message("Setup finished",
                        "Setup is finished.  You may now start the server.");