* buildpackages can create deb source tarballs now.
authorWilfried Göesgens <willi@citadel.org>
Thu, 28 Dec 2006 12:16:59 +0000 (12:16 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 28 Dec 2006 12:16:59 +0000 (12:16 +0000)
* we don't ship setup in debs anymore.
* have port 8504 as default for without ssl in debs
* deamonize by ourselfs, remove ctdlsvc
* modified setup to use -d in the init script

webcit/Makefile.in
webcit/buildpackages
webcit/ctdlsvc.c [deleted file]
webcit/debian/citadel-webcit.templates
webcit/debian/control
webcit/debian/rules
webcit/debian/webcit.init
webcit/setup.c
webcit/webserver.c

index 0512e25cea4a5facd8ca32c869e6251b1ac9739c..64d7c10c0dfc53355d9697e7edff153d7c5a207a 100644 (file)
@@ -21,13 +21,13 @@ SUBDIRS=$(LIB_SUBDIRS) $(PROG_SUBDIRS)
 
 # End of configuration section
 
-all: all-progs-recursive webserver setup ctdlsvc
+all: all-progs-recursive webserver setup
 
 
 .SUFFIXES: .cpp .c .o
 
 clean:
-       rm -f *.o webcit webserver ctdlsvc
+       rm -f *.o webcit webserver
        rm -fr locale/*
 
 distclean: clean
@@ -39,9 +39,6 @@ setup: setup.o tools.o
        $(CC) setup.o tools.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) $(SETUP_LIBS) -o setup
 
-ctdlsvc: ctdlsvc.o
-       $(CC) ctdlsvc.o -o ctdlsvc
-
 webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        cookie_conversion.o locate_host.o floors.o summary.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \
@@ -96,7 +93,6 @@ install:
        for i in \
                webserver \
                setup \
-               ctdlsvc \
                `find static -type f | grep -v .svn` \
                `find tiny_mce -type f | grep -v .svn` \
                `find locale -type f | grep -v .svn` \
index 3f10f911a231ee76b335cb93649f78125b9e901f..f1eb9fd4b7c8476f587276989282a55972855045 100755 (executable)
@@ -48,7 +48,11 @@ case $1 in
                        mv /tmp/webcit_changelog debian/changelog
                        
                fi
-               fakeroot dpkg-buildpackage
+               if test "$2" == "src"; then
+                   cd ..; dpkg-source -b "webcit-$WEBCIT_VERSION"
+               else
+                   fakeroot dpkg-buildpackage
+               fi
        ;;
        *)
                echo "Not yet implemented. we have: debian "
diff --git a/webcit/ctdlsvc.c b/webcit/ctdlsvc.c
deleted file mode 100644 (file)
index a734c0a..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * $Id: $
- *
- * This is just a quick little hack to start a program in the background,
- * and automatically restart it if it exits with a nonzero exit status.
- *
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-
-char *pidfilename = NULL;
-pid_t current_child = 0;
-
-void graceful_shutdown(int signum) {
-       kill(current_child, signum);
-       if (pidfilename != NULL) {
-               unlink(pidfilename);
-       }
-       exit(0);
-}
-       
-
-int main(int argc, char **argv)
-{
-       pid_t child = 0;
-       int status = 0;
-       FILE *fp;
-       int nullfd;
-
-       --argc;
-       ++argv;
-
-       pidfilename = argv[0];
-       --argc;
-       ++argv;
-
-       if (access(argv[0], X_OK)) {
-               fprintf(stderr, "%s: cannot execute\n", argv[0]);
-               exit(1);
-       }
-
-       /* Close stdin/stdout/stderr and replace them with /dev/null.
-        * We don't just call close() because we don't want these fd's
-        * to be reused for other files.
-        */
-       nullfd = open("/dev/null", O_RDWR);
-       if (nullfd < 0) {
-               fprintf(stderr, "/dev/null: %s\n", strerror(errno));
-               exit(2);
-       }
-       dup2(nullfd, 0);
-       dup2(nullfd, 1);
-       dup2(nullfd, 2);
-       close(nullfd);
-
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
-
-       child = fork();
-       if (child != 0) {
-               fp = fopen(pidfilename, "w");
-               if (fp != NULL) {
-                       fprintf(fp, "%d\n", child);
-                       fclose(fp);
-               }
-               exit(0);
-       }
-
-       do {
-               current_child = fork();
-
-               signal(SIGTERM, graceful_shutdown);
-       
-               if (current_child < 0) {
-                       perror("fork");
-                       exit(errno);
-               }
-       
-               else if (current_child == 0) {
-                       exit(execvp(argv[0], &argv[0]));
-               }
-       
-               else {
-                       waitpid(current_child, &status, 0);
-               }
-
-       } while (status != 0);
-
-       unlink(pidfilename);
-       exit(0);
-}
-
index 8e35ea99fd9da739dcabecb5140e53ac534e01cf..d8587f58f5a3ddfabd55d57d460b15b051f6f2ff 100644 (file)
@@ -1,6 +1,6 @@
 Template: citadel/WebcitHttpPort
 Type: string
-Default: 2020
+Default: 8504
 Description: Webcit HTTP Port
   Select the Port, which the plain HTTP webcit server should listen on. -1 to disable.
 
index 66136ff8d22c0e0f5d7cc9e857b43d5f4ba4bb6b..aae257cd57c2c86091ce5bb743b6ba2a7248bc1d 100644 (file)
@@ -2,13 +2,13 @@ Source: webcit
 Section: unknown
 Priority: optional
 Maintainer: Wilfried Goesgens <citadel@outgesourced.org>
-Build-Depends: debhelper (>= 4.0.0), libical0-dev
+Build-Depends: debhelper (>= 4.0.0), libical0-dev, gettext
 Standards-Version: 3.6.1
 
 Package: citadel-webcit
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}, debconf
-Sugests: citadel-server
+Suggests: citadel-server
 Description: Webcit, the Webfrontend to the Citadel.
  WebCit puts a web-based front end on Citadel, allowing 
  users to access the system from any web browser. And 
index d07ffaee477e9ba1301d7e4b68a81e9943f0201f..61bb40a95ebba8a177c0cddc9548ea7b179ac340 100755 (executable)
@@ -82,10 +82,8 @@ install: build
                $(CURDIR)/debian/citadel-webcit/usr/share/locale
        cd $(CURDIR)/debian/citadel-webcit/usr/share/doc/citadel-webcit/examples/; \
                                md5sum `find -type f |grep -v md5sums `>md5sums; 
-       mv $(CURDIR)/debian/webcit/var/lib/citadel/www/setup \
-               $(CURDIR)/debian/citadel-webcit/usr/lib/citadel-webcit/
-       mv $(CURDIR)/debian/webcit/var/lib/citadel/www/ctdlsvc \
-               $(CURDIR)/debian/citadel-webcit/usr/lib/citadel-webcit/
+# we don't use the setup anymore, omit it.
+       rm -f $(CURDIR)/debian/webcit/var/lib/citadel/www/setup
        mv $(CURDIR)/debian/webcit/var/lib/citadel/www/webserver \
                $(CURDIR)/debian/citadel-webcit/usr/sbin/
 
index c963a30c8df8261a1cc067312264a02102714e63..c8a8726217d9fc69fcb50646acb18dbd19d8fe0d 100644 (file)
@@ -23,7 +23,6 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="Citadel Groupware Webserver "
 NAME=webserver
 DAEMON=/usr/sbin/$NAME
-CTDLSVC=/usr/lib/citadel-webcit/ctdlsvc
 DAEMON_ARGS=""
 PIDFILE=$RUNDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/webcit
@@ -90,8 +89,8 @@ do_start()
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
-       if $CTDLSVC $PIDFILE.$1 $DAEMON \
-               -p$@ -t$LOGDIR/access.${1}.log ; then
+       if $DAEMON -d$PIDFILE.$1 \
+           -p$@ -t$LOGDIR/access.${1}.log ; then
            return 0
        else
            return 2
@@ -112,10 +111,10 @@ do_stop()
        #   2 if daemon could not be stopped
        #   other if a failure occurred
 
-        for i in   $PIDFILE.*; do
+        for i in $PIDFILE.*; do if test -f $i; then
            kill `cat $i`
            rm -f $i
-       done
+       fi; done
 
        #while test -d /proc/`cat $PIDFILE`; do
        #    /usr/bin/printf  '.'
index 3e13ebe7f2f7da2c3f9cc5110e814fd19dd7bbb7..8022ca0d271839995f307110f200d5d1b497d0f2 100644 (file)
@@ -393,14 +393,13 @@ void install_init_scripts(void)
        fprintf(fp,     "CTDL_HOSTNAME=%s\n", hostname);
        fprintf(fp,     "CTDL_PORTNAME=%s\n", portname);
        fprintf(fp,     "\n"
-                       "test -x $WEBCIT_DIR/ctdlsvc || exit 0\n"
                        "test -d /var/run || exit 0\n"
                        "\n"
                        "case \"$1\" in\n"
                        "\n"
                        "start)         echo -n \"Starting WebCit... \"\n"
-                       "               if $WEBCIT_DIR/ctdlsvc /var/run/webcit.pid "
-                                                       "$WEBCIT_DIR/webserver "
+                       "               if   $WEBCIT_DIR/webserver "
+                                                       "-d/var/run/webcit.pid "
                                                        "-t/dev/null "
                                                        "-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
@@ -410,8 +409,8 @@ void install_init_scripts(void)
                        "               fi\n");
 #ifdef HAVE_OPENSSL
        fprintf(fp,     "               echo -n \"Starting WebCit SSL... \"\n"
-                       "               if $WEBCIT_DIR/ctdlsvc /var/run/webcit-ssl.pid "
-                                                       "$WEBCIT_DIR/webserver "
+                       "               if  $WEBCIT_DIR/webserver "
+                                                       "-d/var/run/webcit-ssl.pid "
                                                        "-t/dev/null "
                                                        "-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
index f90e445c7ce4d12aef4662542004e2dc388b0c0b..038ab57ae2c19cc6d18ae89facc2967943222502 100644 (file)
@@ -445,25 +445,110 @@ int client_getln(int sock, char *buf, int bufsiz)
        return (retval);
 }
 
+/**
+ * \brief shut us down the regular way.
+ * param signum the signal we want to forward
+ */
+pid_t current_child;
+void graceful_shutdown(int signum) {
+       kill(current_child, signum);
+       exit(0);
+}
+
 
 /**
  * \brief      Start running as a daemon.  
  *
  * param       do_close_stdio          Only close stdio if set.
  */
-void start_daemon(int do_close_stdio)
+
+/*
+ * Start running as a daemon.
+ */
+void start_daemon(int do_close_stdio, char *pid_file) 
 {
-       if (do_close_stdio) {
-               /* close(0); */
-               close(1);
-               close(2);
+       int status = 0;
+       pid_t child = 0;
+       FILE *fp;
+       int do_restart = 0;
+
+       current_child = 0;
+
+       /* Close stdin/stdout/stderr and replace them with /dev/null.
+        * We don't just call close() because we don't want these fd's
+        * to be reused for other files.
+        */
+       chdir("/");
+
+       child = fork();
+       if (child != 0) {
+               fp = fopen(pid_file, "w");
+               if (fp != NULL) {
+                       fprintf(fp, "%d\n", child);
+                       fclose(fp);
+               }
+               exit(0);
        }
+       
        signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
-       if (fork() != 0) {
-               exit(0);
+
+       setsid();
+       umask(0);
+       if (do_close_stdio) {
+               freopen("/dev/null", "r", stdin);
+               freopen("/dev/null", "w", stdout);
+               freopen("/dev/null", "w", stderr);
        }
+       do {
+               current_child = fork();
+
+               signal(SIGTERM, graceful_shutdown);
+       
+               if (current_child < 0) {
+                       perror("fork");
+                       exit(errno);
+               }
+       
+               else if (current_child == 0) {
+                       return; /* continue starting citadel. */
+               }
+       
+               else {
+                       waitpid(current_child, &status, 0);
+               }
+
+               do_restart = 0;
+
+               /* Did the main process exit with an actual exit code? */
+               if (WIFEXITED(status)) {
+
+                       /* Exit code 0 means the watcher should exit */
+                       if (WEXITSTATUS(status) == 0) {
+                               do_restart = 0;
+                       }
+
+                       /* Exit code 101-109 means the watcher should exit */
+                       else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
+                               do_restart = 0;
+                       }
+
+                       /* Any other exit code means we should restart. */
+                       else {
+                               do_restart = 1;
+                       }
+               }
+
+               /* Any other type of termination (signals, etc.) should also restart. */
+               else {
+                       do_restart = 1;
+               }
+
+       } while (do_restart);
+
+       unlink(pid_file);
+       exit(WEXITSTATUS(status));
 }
 
 /**
@@ -521,6 +606,7 @@ int main(int argc, char **argv)
        int home_specified=0;
        char relhome[PATH_MAX]="";
        char webcitdir[PATH_MAX] = DATADIR;
+       char pidfile[PATH_MAX] = "";
        char *hdir;
        const char *basedir;
 #ifdef ENABLE_NLS
@@ -533,9 +619,9 @@ int main(int argc, char **argv)
 
        /** Parse command line */
 #ifdef HAVE_OPENSSL
-       while ((a = getopt(argc, argv, "h:i:p:t:x:dcfs")) != EOF)
+       while ((a = getopt(argc, argv, "h:i:p:t:x:d:cfs")) != EOF)
 #else
-       while ((a = getopt(argc, argv, "h:i:p:t:x:dcf")) != EOF)
+       while ((a = getopt(argc, argv, "h:i:p:t:x:d:cf")) != EOF)
 #endif
                switch (a) {
                case 'h':
@@ -551,6 +637,8 @@ int main(int argc, char **argv)
                        home=1;
                        break;
                case 'd':
+                       hdir = strdup(optarg);
+                       safestrncpy(pidfile, hdir,sizeof pidfile);
                        running_as_daemon = 1;
                        break;
                case 'i':
@@ -612,7 +700,7 @@ int main(int argc, char **argv)
 
        /* daemonize, if we were asked to */
        if (running_as_daemon) {
-               start_daemon(0);
+               start_daemon(0, pidfile);
        }
 
        /** Tell 'em who's in da house */