summaryrefslogtreecommitdiff
path: root/etc/init.d/opennhrp.init
diff options
context:
space:
mode:
Diffstat (limited to 'etc/init.d/opennhrp.init')
-rwxr-xr-xetc/init.d/opennhrp.init135
1 files changed, 135 insertions, 0 deletions
diff --git a/etc/init.d/opennhrp.init b/etc/init.d/opennhrp.init
new file mode 100755
index 0000000..ec9154c
--- /dev/null
+++ b/etc/init.d/opennhrp.init
@@ -0,0 +1,135 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: opennhrp
+# Required-Start: $all
+# Required-Stop: $all
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: RFC 2332 2333 daemon
+# Description: This file suports one instance of opennhrp
+### END INIT INFO
+
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Next Hop Resolution Protocol"
+NAME=opennhrp
+DAEMON=/usr/sbin/$NAME
+PIDPATH=/var/run
+PIDFILE=$PIDPATH/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+CTRLPATH=/var/run
+CTRLPIPE=$CTRLPATH/$NAME.socket
+HOOK_DIR=/etc/commit/post-hooks.d
+NHRP_HOOK=$HOOK_DIR/vyatta-nhrp-hook
+
+CONFFILE=/etc/opennhrp/opennhrp.conf
+SCRIPTFILE=/etc/opennhrp/opennhrp-script
+
+DAEMON_ARGS=" -d -v -a $CTRLPIPE -c $CONFFILE -s $SCRIPTFILE -p $PIDFILE"
+# -a /var/run/opennhrp/ctrl -c /etc/opennhrp/opennhrp.conf -s /etc/opennhrp/opennhrp-script -d -p /var/run/opennhrp/pid
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ mkdir -p $PIDPATH
+ mkdir -p $CTRLPATH
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null
+ RETVAL=$?
+ if [ ! $RETVAL -eq 0 ]; then return $RETVAL; fi
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
+ return $?
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
+ rm -f $PIDFILE
+ return $?
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
+ return $?
+}
+
+#
+# Function that makes preparations for starting opennhrp
+#
+do_prepare() {
+ if [ -d $HOOK_DIR ] && [ ! -f $NHRP_HOOK ]; then
+ touch $NHRP_HOOK
+ chmod 755 $NHRP_HOOK
+ cat <<SCRIPT_EOF >>$NHRP_HOOK
+#!/bin/sh
+NHRP_UP=/opt/vyatta/sbin/vyatta-update-nhrp.pl
+if [ -f \$NHRP_UP ]; then
+sudo \$NHRP_UP --post_commit
+fi
+SCRIPT_EOF
+ fi
+}
+
+case "$1" in
+ start)
+ log_daemon_msg "Preparing $DESC" "$NAME"
+ do_prepare
+ RETVAL=$?
+ log_end_msg $RETVAL
+ ;;
+ stop)
+ log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ RETVAL=$?
+ log_end_msg $RETVAL
+ ;;
+ reload|force-reload)
+ if [ -e $PIDFILE ]; then
+ log_daemon_msg "Reloading $DESC" "$NAME"
+ do_reload
+ RETVAL=$?
+ log_end_msg $RETVAL
+ else
+ log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ RETVAL=$?
+ log_end_msg $RETVAL
+ fi
+ ;;
+ restart)
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ RETVAL=$?
+ if [ ! $RETVAL -eq 0 ]; then exit $RETVAL; fi
+ sleep 1
+ do_start
+ RETVAL=$?
+ log_end_msg $RETVAL
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
+ exit 3
+ ;;
+esac
+
+#exit with return code of the last command
+exit $RETVAL
+:
+