Permalink
Browse files

Item14476: fix init scripts; add systemd service

  • Loading branch information...
1 parent 3dda14a commit d10ec798b95e1cfe648020e7fc18c0ad31cdfef5 MichaelDaum committed Sep 13, 2017
@@ -103,7 +103,7 @@ Another great Foswiki extension from the <a style="text-decoration:none" href="h
Many thanks to the following sponsors for supporting this work:
* [[http://Kontextwork.de][KontextWork]]
- * [[http://www.fu-berlin.de/][Freie Universität Berlin]]
+ * [[http://www.fu-berlin.de/][Freie Universit&auml;t Berlin]]
---++ Change History
@@ -101,7 +101,8 @@ sub run {
# Need handlers, or FCGI pumps these into the void
$SIG{__WARN__} = sub { print STDERR "WARN ", @_ };
- $SIG{__DIE__} = sub { print STDERR "DIE ", @_ };
+
+ # $SIG{__DIE__} = sub { print STDERR "DIE ", @_ };
# Pull in FCGI environment
my $request =
@@ -21,3 +21,4 @@ tools/http_daemon.pl 0755 Stand-alone web server
tools/webdav.fcgi 0755 FCGI daemon script
tools/virtualhosts-webdav.fcgi 0755 FCGI daemon script
tools/foswiki-dav.init-script 0755
+tools/systemd/foswiki-dav.service 0755
@@ -7,21 +7,25 @@
# Should-Stop: fam
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
-# Short-Description: Start the foswiki backend server.
+# Short-Description: Start the foswiki webdav connector server.
### END INIT INFO
-DESC="Foswiki WebDAV Connector"
+DESC="Foswiki WebDAV connector"
NAME=foswiki-dav
PATH=/sbin:/bin:/usr/sbin:/usr/bin
USER=www-data
-GRPOUP=www-data
+GROUP=www-data
+HOME=/var/www
FOSWIKI_ROOT=/var/www/foswiki
FOSWIKI_FCGI=webdav.fcgi
FOSWIKI_BIND=127.0.0.1:9001
FOSWIKI_CHILDREN=5
+FOSWIKI_MAX_REQUESTS=-1
+FOSWIKI_MAX_SIZE=300000
+FOSWIKI_CHECK_SIZE=10
FOSWIKI_PIDFILE=/var/run/$NAME.pid
FOSWIKI_TRACE=0
FOSWIKI_FILESYSTEM=Foswiki
@@ -31,28 +35,60 @@ if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
fi
+if [ ! -d $FOSWIKI_ROOT ]; then
+ exit
+fi
+
+cd $HOME || exit 3
+
+export HOME
+
+if [ -d $HOME/.plenv ]; then
+ export PATH="$HOME/.plenv/bin:$PATH"
+ eval "$(plenv init -)"
+fi
+
+if [ -d $HOME/local/lib ]; then
+ export LD_LIBRARY_PATH=$HOME/local/lib
+fi
+
FOSWIKI_DAEMON=$FOSWIKI_ROOT/tools/$FOSWIKI_FCGI
-FOSWIKI_DAEMON_OPTS="-n $FOSWIKI_CHILDREN -l $FOSWIKI_BIND -p $FOSWIKI_PIDFILE -d -q -t $FOSWIKI_TRACE -fs $FOSWIKI_FILESYSTEM"
+FOSWIKI_DAEMON_OPTS="-n $FOSWIKI_CHILDREN -l $FOSWIKI_BIND -p $FOSWIKI_PIDFILE -d -q -t $FOSWIKI_TRACE -fs $FOSWIKI_FILESYSTEM -c $FOSWIKI_CHECK_SIZE -x $FOSWIKI_MAX_REQUESTS -s $FOSWIKI_MAX_SIZE"
start() {
log_daemon_msg "Starting $DESC" $NAME
- :> $FOSWIKI_PIDFILE
- chown $USER:$GROUP $FOSWIKI_PIDFILE
- if ! start-stop-daemon --start --oknodo --quiet \
- --chuid $USER:$GROUP \
- --chdir $FOSWIKI_ROOT/bin \
- --pidfile $FOSWIKI_PIDFILE \
- --exec $FOSWIKI_DAEMON -- $FOSWIKI_DAEMON_OPTS
+ if test -f $FOSWIKI_PIDFILE; then
+ log_failure_msg "There's a $DESC already running."
+ else
+ :> $FOSWIKI_PIDFILE
+ chown $USER:$GROUP $FOSWIKI_PIDFILE
+ if ! start-stop-daemon --start --oknodo --quiet \
+ --chuid $USER:$GROUP \
+ --chdir $FOSWIKI_ROOT/bin \
+ --pidfile $FOSWIKI_PIDFILE \
+ --exec $FOSWIKI_DAEMON -- $FOSWIKI_DAEMON_OPTS
+ then
+ log_end_msg 1
+ else
+ log_end_msg 0
+ fi
+ fi
+}
+
+force_stop() {
+ log_daemon_msg "Killing $DESC" $NAME
+ if start-stop-daemon --stop --signal KILL --retry 30 --oknodo --quiet --pidfile $FOSWIKI_PIDFILE
then
- log_end_msg 1
- else
+ rm -f $FOSWIKI_PIDFILE
log_end_msg 0
+ else
+ log_end_msg 1
fi
}
stop() {
log_daemon_msg "Stopping $DESC" $NAME
- if start-stop-daemon --stop --retry 30 --oknodo --quiet --pidfile $FOSWIKI_PIDFILE
+ if start-stop-daemon --stop --signal TERM --retry 30 --oknodo --quiet --pidfile $FOSWIKI_PIDFILE
then
rm -f $FOSWIKI_PIDFILE
log_end_msg 0
@@ -84,6 +120,9 @@ case "$1" in
stop)
stop
;;
+ force-stop)
+ force_stop
+ ;;
reload)
reload
;;
@@ -95,7 +134,7 @@ case "$1" in
status
;;
*)
- echo "Usage: $NAME {start|stop|restart|reload|status}"
+ echo "Usage: $NAME {start|stop|force-stop|restart|reload|status}"
exit 1
;;
esac
@@ -0,0 +1,60 @@
+# SystemD start file for Foswiki
+#
+# Note that you need to replace the path in 'WorkingDirectory'
+# to suite your needs if you don't use the default path
+# as there is no variable substitution possible for that setting
+
+[Unit]
+Description=Foswiki WebDAV
+
+[Service]
+Environment=FOSWIKI_ROOT=/var/www/foswiki
+Environment=FOSWIKI_FCGI=webdav.fcgi
+Environment=FOSWIKI_BIND=127.0.0.1:9002
+Environment=FOSWIKI_CHILDREN=3
+Environment=FOSWIKI_MAX_REQUESTS=-1
+Environment=FOSWIKI_MAX_SIZE=300000
+Environment=FOSWIKI_CHECK_SIZE=10
+Environment=FOSWIKI_TRACE=0
+Environment=FOSWIKI_FILESYSTEM=Foswiki
+
+
+# Optional, overrides settings above
+EnvironmentFile=-/etc/default/foswiki-dav
+
+# The User, Group, PIDFile and WorkingDirectory cannot be specified by Environment variables. Update as needed.
+# Typical settings:
+# RedHat, Fedora, CentOS, Gentoo, Mandriva USER=apache GROUP=apache
+# debian, Ubuntu, Kubuntu USER=www-data GROUP=www-data
+# Suse: USER=wwwrun GROUP=www
+# FreeBSD: USER=www GROUP=wwwadmin
+User=www-data
+Group=www-data
+
+# If changing pidfile, be sure to also update the -p argument on the ExecStart command
+# The PIDFile directory must exist and be writable by the User:Group specified above
+PIDFile=/var/www/foswiki/working/foswiki-dav.pid
+#PIDFile=/var/run/foswiki/foswiki-dav.pid # conventional location
+
+# Doesn't seem to support variable substitution. Should be ${FOSWIKI_ROOT}/bin/
+WorkingDirectory=/var/www/foswiki/bin/
+
+# Starts foswiki fcgi service
+ExecStart=/usr/bin/perl ${FOSWIKI_ROOT}/tools/${FOSWIKI_FCGI} \
+ -n $FOSWIKI_CHILDREN \
+ -l $FOSWIKI_BIND \
+ -c $FOSWIKI_CHECK_SIZE \
+ -x $FOSWIKI_MAX_REQUESTS \
+ -s $FOSWIKI_MAX_SIZE \
+ -t $FOSWIKI_TRACE \
+ -fs ${FOSWIKI_FILESYSTEM} \
+ -p $FOSWIKI_ROOT/working/foswiki-dav.pid \
+ -d -q
+
+
+Type=forking
+Restart=always
+SyslogIdentifier=foswiki-dav
+
+[Install]
+WantedBy=multi-user.target

0 comments on commit d10ec79

Please sign in to comment.