Install tids init script
authorSam Hartman <hartmans@debian.org>
Fri, 26 Sep 2014 14:46:47 +0000 (10:46 -0400)
committerSam Hartman <hartmans@debian.org>
Fri, 26 Sep 2014 14:55:13 +0000 (10:55 -0400)
Patch by Stefan Paetow;modified slightly for Debian conventions.

debian/changelog
debian/moonshot-trust-router.dirs [new file with mode: 0644]
debian/moonshot-trust-router.install
debian/moonshot-trust-router.tids.init [new file with mode: 0644]
debian/rules
debian/tids-wrapper [new file with mode: 0644]

index ff9cb0b..6f25b12 100644 (file)
@@ -1,8 +1,9 @@
 moonshot-trust-router (1.4-1) unstable; urgency=medium
 
   * New Upstream version
+  * Install tids init script, thanks Stefan Paetow
 
- -- Sam Hartman <hartmans@debian.org>  Fri, 26 Sep 2014 10:02:06 -0400
+ -- Sam Hartman <hartmans@debian.org>  Fri, 26 Sep 2014 10:45:18 -0400
 
 moonshot-trust-router (1.3.1-1) unstable; urgency=medium
 
diff --git a/debian/moonshot-trust-router.dirs b/debian/moonshot-trust-router.dirs
new file mode 100644 (file)
index 0000000..7cee9c9
--- /dev/null
@@ -0,0 +1 @@
+usr/lib/trust_router
index 2a9d09f..486899a 100644 (file)
@@ -3,3 +3,4 @@ usr/bin/trust_router
 usr/share/trust_router/*
 lib/systemd/system/*
 
+debian/tids-wrapper usr/lib/trust_router
diff --git a/debian/moonshot-trust-router.tids.init b/debian/moonshot-trust-router.tids.init
new file mode 100644 (file)
index 0000000..0a61af4
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+### BEGIN INIT INFO
+# Provides: tids
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 4 6
+# Required-Start: $freeradius
+# Required-Stop:
+# Should-Start: $network
+# Short-Description: Starts Moonshot TIDS
+# Description: Starts the Moonshot Temporary ID Service
+### END INIT INFO
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+. /lib/lsb/init-functions
+
+[ -z "$HOME" ] && export HOME=/
+
+usage() {
+    echo "Usage: $0 {start|stop|status}"
+}
+
+# Load the configuration
+[ -f /etc/default/trust_router ] || exit 0
+. /etc/default/trust_router
+TIDS_PIDDIR=/var/run/trust_router
+TIDS_LOGDIR=/var/log/trust_router
+
+# Create the PID and LOG directories
+[ -d "$TIDS_PIDDIR" ] || mkdir -p $TIDS_PIDDIR && chown $TIDS_USER:$TIDS_GROUP $TIDS_PIDDIR
+[ -d "$TIDS_LOGDIR" ] || mkdir -p $TIDS_LOGDIR && chown $TIDS_USER:$TIDS_GROUP $TIDS_LOGDIR
+
+# Some variables
+prog=/usr/lib/trust_router/tids-wrapper
+PIDFILE="$TIDS_PIDDIR/tids.pid"
+LOGFILE="$TIDS_LOGDIR/tids.log"
+
+# Does the trust router and wrapper exist
+[ -x /usr/bin/tids ] || exit 5
+[ -x $prog ] || exit 5
+
+[ -f "$LOGFILE" ] || touch $LOGFILE && chown $TIDS_USER:$TIDS_GROUP $LOGFILE
+
+OPTIONS="$PIDFILE $LOGFILE $ipaddr $gssname $hostname $/var/lib/trust_router/keys"
+
+case $1 in
+    start)
+        if [ -f ${PIDFILE} ] ;
+        then
+                OLD_PID=$(cat "$PIDFILE")
+
+                if [ -d "/proc/$OLD_PID" ] ;
+                then
+                        echo "Error: TIDS already running" ; exit 1
+                else
+                        rm $PIDFILE
+                fi
+        fi
+
+        timestamp=$(date)
+        echo "$timestamp Starting TIDS..." >> $LOGFILE
+        log_daemon_msg "Starting TIDS" "tids"
+        start-stop-daemon --start --chuid $TIDS_USER --pidfile $PIDFILE --oknodo --startas $prog $OPTIONS
+        status=$?
+        log_end_msg $status
+        ;;
+    stop)
+        timestamp=$(date)
+        echo "$timestamp Stopping TIDS..." >> $LOGFILE
+        log_daemon_msg "Stopping TIDS" "tids"
+        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
+        status=$?
+        log_end_msg $status
+        rm -f $PIDFILE
+        ;;
+    status)
+        if [ -f $PIDFILE ] ;
+        then
+                PID=$(cat "$PIDFILE")
+
+                if [ -d "/proc/$PID" ] ;
+                then
+                        echo "TIDS is running (pid $PID)"
+                else
+                        if [ -e $PIDFILE ] ; then
+                                echo "TIDS appears to be dead but its PID file exists"
+                        else
+                                echo "TIDS appears to be stopped"
+                        fi
+                fi
+        else
+                echo "TIDS appears to be stopped"
+        fi
+        exit 0
+        ;;
+    reload | force-reload | condrestart | try-restart)
+        usage
+        exit 3
+        ;;
+    *)
+        usage
+        exit 2
+        ;;
+esac
index 3410785..0aa145d 100755 (executable)
@@ -18,3 +18,6 @@ override_dh_auto_configure:
 
 override_dh_strip:
        dh_strip --dbg-package=moonshot-trust-router-dbg
+
+override_dh_installinit:
+       dh_installinit --name tids
diff --git a/debian/tids-wrapper b/debian/tids-wrapper
new file mode 100644 (file)
index 0000000..831cb3a
--- /dev/null
@@ -0,0 +1,14 @@
+#! /usr/bin/env bash
+
+PIDFILE=$1
+LOGFILE=$2
+shift 2
+
+unset DISPLAY
+/usr/bin/tids $@ >> $LOGFILE 2>&1 &
+BGPID=$!
+RET=$?
+
+echo $BGPID > $PIDFILE
+
+exit $RET