From bd8eccf0e5b4ecf3932bac89b85fb4c526dfd5a7 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 8 Feb 2015 08:09:44 +0000 Subject: [PATCH] add init script for http server --- debian/changelog | 7 +++++ debian/liber.default | 9 ++++++ debian/liber.init | 70 +++++++++++++++++++++++++++++++++++++++++++ debian/liber.postinst | 31 +++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 debian/liber.default create mode 100755 debian/liber.init create mode 100755 debian/liber.postinst diff --git a/debian/changelog b/debian/changelog index 1f738b9..a3f9691 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +liber (0.1p6) unstable; urgency=medium + + * Fixed issues with user input. + * Init script for the HTTP daemon. + + -- ale <ale@incal.net> Sat, 07 Feb 2015 09:47:16 +0000 + liber (0.1p5) unstable; urgency=low * Built with updated Bleve and Go. diff --git a/debian/liber.default b/debian/liber.default new file mode 100644 index 0000000..2b126d4 --- /dev/null +++ b/debian/liber.default @@ -0,0 +1,9 @@ + +# Uncomment this line to start the HTTP interface daemon. +#ENABLE_SERVER=true + +# Set the address (host:port) to listen on. +#ADDR=:4040 + +# Directory where books are stored. +#BOOK_DIR=/var/lib/liber/books diff --git a/debian/liber.init b/debian/liber.init new file mode 100755 index 0000000..08ac676 --- /dev/null +++ b/debian/liber.init @@ -0,0 +1,70 @@ +#!/bin/sh +# +### BEGIN INIT INFO +# Provides: liber +# Required-Start: $remote_fs $time +# Required-Stop: $remote_fs $time +# Should-Start: $network +# Should-Stop: $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: ebook collection server +# Description: Ebook collection server. +### END INIT INFO + +NAME=liber +DESC="Liber" +DAEMON=/usr/bin/liber +PIDFILE=/var/run/liber.pid +ENABLE_SERVER=false +USER=liber +ADDR=:4040 +BOOK_DIR=/var/lib/liber/books +DAEMON_OPTS= + +[ -r /etc/default/$NAME ] && . /etc/default/$NAME +[ -x "$DAEMON" ] || exit 0 +if [ "$ENABLE_SERVER" != "true" ]; then + echo "$NAME disabled, set ENABLE_SERVER=true in /etc/default/$NAME to enable it" >&2 + exit 0 +fi + +. /lib/lsb/init-functions + +do_start() { + DAEMON_OPTS="--http-server=$ADDR --book-dir=$BOOK_DIR $DAEMON_OPTS" + + log_daemon_msg "Starting $DESC" "$NAME" + start-stop-daemon --start --quiet --background \ + --pidfile $PIDFILE --make-pidfile --chuid $USER \ + --exec /bin/sh -- -c \ + "$DAEMON $DAEMON_OPTS 2>&1 | logger -t liber" + log_end_msg $? +} + +do_stop() { + log_daemon_msg "Stopping $DESC" "$NAME" + start_stop_daemon --stop --quiet --oknodo \ + --pidfile $PIDFILE --user $USER + log_end_msg $? +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" >&2 + exit 3 + ;; +esac + +exit 0 diff --git a/debian/liber.postinst b/debian/liber.postinst new file mode 100755 index 0000000..5101812 --- /dev/null +++ b/debian/liber.postinst @@ -0,0 +1,31 @@ +#!/bin/sh + +case "$1" in + configure) + OLDVERSION="$2" + # see below + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + exit 0 + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +adduser --quiet --system --home /var/lib/liber --no-create-home --ingroup nogroup liber + +for dir in /var/lib/liber /var/lib/liber/books; do + test -d $dir || mkdir $dir + chmod 700 $dir + chown liber:nogroup $dir +done + +update-rc.d liber defaults >/dev/null + +exit 0 -- GitLab