* 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
# 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
$(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 \
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` \
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 "
+++ /dev/null
-/*
- * $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);
-}
-
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.
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
$(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/
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
# 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
# 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 '.'
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"
" 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"
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));
}
/**
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
/** 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':
home=1;
break;
case 'd':
+ hdir = strdup(optarg);
+ safestrncpy(pidfile, hdir,sizeof pidfile);
running_as_daemon = 1;
break;
case 'i':
/* daemonize, if we were asked to */
if (running_as_daemon) {
- start_daemon(0);
+ start_daemon(0, pidfile);
}
/** Tell 'em who's in da house */