summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-21 00:48:24 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-09-21 00:48:24 +0200
commit8a679892b9e6e96b10dfeb16d1caacb096bc116f (patch)
treedd76a6cc2ccf9558d13b9c3242df7235a2ec34aa
parentfixed path to examples dir (diff)
improved install routines (added systemd service unit and initscript
-rwxr-xr-xcontrib/dropnroll-launcher28
-rw-r--r--contrib/etc/dropnroll/autostart (renamed from etc/dropnroll/autostart)0
-rw-r--r--contrib/etc/dropnroll/sample/config (renamed from etc/dropnroll/sample/config)23
-rwxr-xr-xcontrib/etc/dropnroll/sample/newfile.sh (renamed from etc/dropnroll/sample/newfile.sh)0
-rwxr-xr-xcontrib/initscript141
-rw-r--r--contrib/systemd.service9
-rw-r--r--src/Makefile27
-rwxr-xr-xsrc/configure29
8 files changed, 235 insertions, 22 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/etc/dropnroll/autostart b/contrib/etc/dropnroll/autostart
index 067d2c0..067d2c0 100644
--- a/etc/dropnroll/autostart
+++ b/contrib/etc/dropnroll/autostart
diff --git a/etc/dropnroll/sample/config b/contrib/etc/dropnroll/sample/config
index 98758be..5c90d94 100644
--- a/etc/dropnroll/sample/config
+++ b/contrib/etc/dropnroll/sample/config
@@ -5,20 +5,15 @@
## the path to the command socket
command-sock /var/run/dropnroll/sample.sock
-## change user and group after init
-#username nobody
-#groupname nogroup
+## 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
-#############################
-## Debug options #
-#############################
-
-## don't run in background
-#nodaemonize
-
-## additional log to standard output with a level of 5
-#log stdout:5
+## Statically configured directories to watch
+#dir /some/path
+#dir /yet/another/path
#############################
@@ -28,5 +23,9 @@ command-sock /var/run/dropnroll/sample.sock
## 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/etc/dropnroll/sample/newfile.sh b/contrib/etc/dropnroll/sample/newfile.sh
index 600b5f1..600b5f1 100755
--- a/etc/dropnroll/sample/newfile.sh
+++ b/contrib/etc/dropnroll/sample/newfile.sh
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
diff --git a/src/Makefile b/src/Makefile
index 77619cf..886872e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -79,6 +79,11 @@ manpage:
INSTALL_TARGETS := install-bin install-etc
REMOVE_TARGETS := remove-bin remove-etc
+ifdef SYSTEMDDIR
+INSTALL_TARGETS += install-systemd
+REMOVE_TARGETS += remove-systemd
+endif
+
ifdef MANDIR
INSTALL_TARGETS += install-man
REMOVE_TARGETS += remove-man
@@ -95,7 +100,15 @@ install-bin: $(EXECUTABLE)
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(EXECUTABLE) $(DESTDIR)$(BINDIR)
+install-systemd:
+ $(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)
+ $(INSTALL) -m 644 ../contrib/systemd.service $(DESTDIR)$(SYSTEMDDIR)/$(EXECUTABLE).service
+ $(INSTALL) -d $(DESTDIR)$(BINDIR)
+ $(INSTALL) -m 755 ../contrib/$(EXECUTABLE)-launcher $(DESTDIR)$(BINDIR)
+
install-etc:
+ $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d/
+ $(INSTALL) -m 755 ../contrib/initscript $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
$(INSTALL) -d $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)
@ echo "example configurations can be found at $(EXAMPLESDIR)/$(EXECUTABLE)" > $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/README
@@ -105,8 +118,8 @@ install-man: manpage
install-examples:
$(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)
- $(INSTALL) -m 644 etc/dropnroll/autostart $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/autostart
- @( cd 'etc/dropnroll/' ; \
+ $(INSTALL) -m 644 ../contrib/etc/dropnroll/autostart $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/autostart
+ @( cd '../contrib/etc/dropnroll/' ; \
for dir in `ls`; do \
if [ -d $$dir ]; then \
echo "install $$dir configuration" ; \
@@ -128,13 +141,17 @@ remove: $(REMOVE_TARGETS)
remove-bin:
rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)
-remove-etc:
+remove-systemd:
+ rm -f $(DESTDIR)$(SYSTEMDDIR)/$(EXECUTABLE).service
-remove-examples:
- rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
+remove-etc:
+ rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
remove-man:
rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
+remove-examples:
+ rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
+
purge: remove
rm -rf $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/
diff --git a/src/configure b/src/configure
index 50e3239..f092fef 100755
--- a/src/configure
+++ b/src/configure
@@ -26,15 +26,14 @@ EBUILD_COMPAT=0
USE_CLANG=0
-CFLAGS='-g -O2'
-LDFLAGS='-g -Wall -O2'
-
PREFIX='/usr/local'
BINDIR=''
ETCDIR=''
+SYSTEMDDIR=''
+INSTALLSYSTEMD=1
MANDIR=''
INSTALLMANPAGE=1
-EXAMPLESDIR='../'
+EXAMPLESDIR=''
INSTALLEXAMPLES=1
print_usage() {
@@ -43,10 +42,13 @@ print_usage() {
echo " --prefix=<PREFIX> the installation prefix (default: /usr/local)"
echo " --bindir=<DIR> the path to the bin directory (default: $PREFIX/bin)"
echo " --sysconfdir=<DIR> the path to the system configuration directory (default: $PREFIX/etc"
+ echo " --systemddir=<DIR> the path to the systemd service unit directory (default: /usr/lib/systemd/system)"
+ echo " --no-systemd dont't install systemd service unit"
echo " --mandir=<DIR> the path to the system man pages (default: $PREFIX/share/man)"
echo " --no-manpage dont't install manpage"
echo " --examplesdir=<DIR> the path to the examples files (default: $PREFIX/share/examples)"
echo " --no-examples dont't install example files"
+ echo " --use-clang use clang/llvm as compiler/linker"
}
for arg
@@ -67,6 +69,12 @@ do
--sysconfdir=*)
ETCDIR=${arg#--sysconfdir=}
;;
+ --systemddir=*)
+ SYSTEMDDIR=${arg#--systemddir=}
+ ;;
+ --no-systemd)
+ INSTALLSYSTEMD=0
+ ;;
--mandir=*)
MANDIR=${arg#--mandir=}
;;
@@ -123,7 +131,7 @@ case $TARGET in
LDFLAGS=$LDFLAGS' -L/usr/local/lib'
;;
*)
- echo "Plattform not supported"
+ echo "platform not supported"
exit 1;
;;
esac
@@ -132,6 +140,10 @@ if [ -z "$BINDIR" ]; then
BINDIR=$PREFIX/bin
fi
+if [ -z "$SYSTEMDDIR" ]; then
+ SYSTEMDDIR=/usr/lib/systemd/system
+fi
+
if [ -z "$ETCDIR" ]; then
ETCDIR=$PREFIX/etc
fi
@@ -160,6 +172,13 @@ BINDIR := $BINDIR
ETCDIR := $ETCDIR
EOF
+if [ $INSTALLSYSTEMD -eq 1 ]; then
+ echo "SYSTEMDDIR := $SYSTEMDDIR" >> include.mk
+ echo "installing systemd service unit"
+else
+ echo "not installing system service unit"
+fi
+
if [ $INSTALLMANPAGE -eq 1 ]; then
echo "MANDIR := $MANDIR" >> include.mk
echo "installing manpage"