summaryrefslogtreecommitdiff
path: root/etc/init.d/opennhrp.init
blob: 848851610f8af139a24e645ff6c86bd1a6e6b129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#! /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 -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

# Exclude from systemd
_SYSTEMCTL_SKIP_REDIRECT=yes

# 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
: