diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-21 00:48:24 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-21 00:48:24 +0200 |
commit | 8a679892b9e6e96b10dfeb16d1caacb096bc116f (patch) | |
tree | dd76a6cc2ccf9558d13b9c3242df7235a2ec34aa /contrib | |
parent | fixed path to examples dir (diff) |
improved install routines (added systemd service unit and initscript
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/dropnroll-launcher | 28 | ||||
-rw-r--r-- | contrib/etc/dropnroll/autostart | 2 | ||||
-rw-r--r-- | contrib/etc/dropnroll/sample/config | 31 | ||||
-rwxr-xr-x | contrib/etc/dropnroll/sample/newfile.sh | 15 | ||||
-rwxr-xr-x | contrib/initscript | 141 | ||||
-rw-r--r-- | contrib/systemd.service | 9 |
6 files changed, 226 insertions, 0 deletions
diff --git a/contrib/dropnroll-launcher b/contrib/dropnroll-launcher new file mode 100755 index 0000000..f0569f3 --- /dev/null +++ b/contrib/dropnroll-launcher @@ -0,0 +1,28 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 <instance name>" + exit 1 +fi + +INST="$1" +NAME=dropnroll +CONFIG_DIR="/etc/$NAME" +VARRUN_DIR=/var/run/$NAME + +if [ -d "$CONFIG_DIR/$INST/" ] && [ -e "$CONFIG_DIR/$INST/config" ]; then + NEWFILE='' + test -f $CONFIG_DIR/$INST/newfile.sh && NEWFILE="-x $CONFIG_DIR/$INST/newfile.sh" + CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$INST/config | sed 's/chroot\s*//'` + if [ -n "$CHROOTDIR" ] ; then + test -d $CHROOTDIR || mkdir -p $CHROOTDIR + fi + test -d $VARRUN_DIR || mkdir -p $VARRUN_DIR + DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$INST/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '` + exec dropnroll -D --write-pid $VARRUN_DIR/$INST.pid $NEWFILE $DAEMONARG +else + echo "Instance config directory does not exist or does not contain a config file" + exit 1 +fi + +exit 1 # should not be reached unless exec returns because of an error diff --git a/contrib/etc/dropnroll/autostart b/contrib/etc/dropnroll/autostart new file mode 100644 index 0000000..067d2c0 --- /dev/null +++ b/contrib/etc/dropnroll/autostart @@ -0,0 +1,2 @@ +sample +#disabled diff --git a/contrib/etc/dropnroll/sample/config b/contrib/etc/dropnroll/sample/config new file mode 100644 index 0000000..5c90d94 --- /dev/null +++ b/contrib/etc/dropnroll/sample/config @@ -0,0 +1,31 @@ +############################# +## Main options # +############################# + +## the path to the command socket +command-sock /var/run/dropnroll/sample.sock + +## Maximum Number of children (scripts) to call at once +max-children 8 + +## What to do when new files trigger the children limit +children-policy defer + +## Statically configured directories to watch +#dir /some/path +#dir /yet/another/path + + +############################# +## Expert options # +############################# + +## log to syslog with a level of 3 +log syslog:3,dropnroll-sample,daemon + +## change user and group after init +#username nobody +#groupname nogroup + +## chroot to users home directory +#chroot /var/run/dropnroll diff --git a/contrib/etc/dropnroll/sample/newfile.sh b/contrib/etc/dropnroll/sample/newfile.sh new file mode 100755 index 0000000..600b5f1 --- /dev/null +++ b/contrib/etc/dropnroll/sample/newfile.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +DIR=$1 +FILENAME=$2 +SIZE=$3 + +if [ -z "$FILENAME" ]; then + exit 1; +fi + +echo "new file of size $SIZE detected: $DIR/$FILENAME" >> /tmp/dropnroll-sample.log +sleep 5 +rm -f $DIR/$FILENAME >> /tmp/dropnroll-sample.log 2>&1 + +exit 0 diff --git a/contrib/initscript b/contrib/initscript new file mode 100755 index 0000000..aadf074 --- /dev/null +++ b/contrib/initscript @@ -0,0 +1,141 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: dropnroll +# Required-Start: $syslog +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start dropnroll daemon at boot time +# Description: Waits for files in folders and calls script for new files +### END INIT INFO +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/bin/dropnroll +CONFIG_DIR=/etc/dropnroll +NAME=dropnroll +DESC=dropnroll +VARRUN_DIR=/var/run/$NAME + +test -x $DAEMON || exit 0 + +# Include dropnroll defaults if available +if [ -f /etc/default/dropnroll ] ; then + . /etc/default/dropnroll +fi + +. /lib/lsb/init-functions + +start_dnr () { + STATUS="OK" + if [ -f $CONFIG_DIR/$DNRNAME/config ] ; then + NEWFILE='' + test -f $CONFIG_DIR/$DNRNAME/newfile.sh && NEWFILE="-x $CONFIG_DIR/$DNRNAME/newfile.sh" + CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$DNRNAME/config | sed 's/chroot\s*//'` + if [ -n "$CHROOTDIR" ] ; then + test -d $CHROOTDIR || mkdir -p $CHROOTDIR + fi + test -d $VARRUN_DIR || mkdir -p $VARRUN_DIR + chmod 777 $VARRUN_DIR + DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$DNRNAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '` + $DAEMON --write-pid $VARRUN_DIR/$DNRNAME.pid $NEWFILE $DAEMONOPTS $DAEMONARG || STATUS="FAILED" + else + STATUS="no config found" + fi + echo -n "($STATUS)" +} + +stop_dnr () { + kill `cat $PIDFILE` || true + rm $PIDFILE +} + +set -e +case "$1" in + start) + echo -n "Starting $DESC:" + if test -z "$2" ; then + if [ -f $CONFIG_DIR/autostart ] ; then + for DNRNAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do + echo -n " $DNRNAME" + start_dnr + done + else + echo " no config found" + exit 1; + fi + else + while shift ; do + [ -z "$1" ] && break + DNRNAME=$1 + echo -n " $DNRNAME" + start_dnr + done + fi + echo "." + ;; + stop) + echo -n "Stoping $DESC:" + if test -z "$2" ; then + for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do + DNRNAME=`echo $PIDFILE | cut -c20-` + DNRNAME=${DNRNAME%%.pid} + echo -n " $DNRNAME" + stop_dnr + done + else + while shift ; do + [ -z "$1" ] && break + if test -e $VARRUN_DIR/$1.pid ; then + PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null` + DNRNAME=`echo $PIDFILE | cut -c20-` + DNRNAME=${DNRNAME%%.pid} + echo -n " $DNRNAME" + stop_dnr + else + echo -n " (failure: No such tunnel is running: $1)" + fi + done + fi + echo "." + ;; + reload) + echo -n "Reloading $DESC:" + if test -z "$2" ; then + for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do + DNRNAME=`echo $PIDFILE | cut -c20-` + DNRNAME=${DNRNAME%%.pid} + echo -n " $DNRNAME" + stop_dnr + start_dnr + done + else + while shift ; do + [ -z "$1" ] && break + if test -e $VARRUN_DIR/$1.pid ; then + PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null` + DNRNAME=`echo $PIDFILE | cut -c20-` + DNRNAME=${DNRNAME%%.pid} + echo -n " $DNRNAME" + stop_dnr + start_dnr + else + echo -n " (failure: No such tunnel is running: $1)" + fi + done + fi + echo "." + ;; + restart) + SCRIPT=$0 + shift + $SCRIPT stop $* + sleep 1 + $SCRIPT start $* + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|reload}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/contrib/systemd.service b/contrib/systemd.service new file mode 100644 index 0000000..af48071 --- /dev/null +++ b/contrib/systemd.service @@ -0,0 +1,9 @@ +[Unit] +Description=Drop'N'Roll Daemon (%i) + +[Service] +ExecStart=/usr/bin/dropnroll-launcher %i +PrivateDevices=yes + +[Install] +WantedBy=multi-user.target |