summaryrefslogtreecommitdiff
path: root/scripts/vyatta-protocol
blob: 3d354d8d2d06c821fe4ff2ef2ffae41cb4ec358e (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
#! /bin/bash
#
# This is special script for start,stop,restart of quagga daemons
#
progname=$0
usage() {
    echo "Usage: $progname {start|stop|restart} {bgpd|ospfd|ripd|ripngd}"
    exit 1;
}

if [ $# -lt 2 ]; then
    usage
fi

daemon=$2
exe_file=/usr/sbin/vyatta-$daemon

pid_dir=/var/run/vyatta/quagga
pid_file=$pid_dir/${daemon}.pid
log_dir=/var/log/vyatta/quagga

if [ ! -x $exe_file ]; then
    echo "Unknown daemon $daemon"
    exit 1;
fi

case "$1" in
    start)
	sudo start-stop-daemon --start --quiet \
	    --chdir $log_dir --exec $exe_file \
	    -- -d -P 0 -i $pid_dir/${daemon}.pid
	sudo start-stop-daemon --start --quiet \
	    --chdir $log_dir \
	    --exec /usr/sbin/vyatta-watchquagga \
	    -- -p $pid_dir/watch-${daemon}.pid \
               -dz -r "/opt/vyatta/sbin/vyatta-quagga restart %s" $daemon
	;;

    stop) 
	sudo start-stop-daemon --stop --quiet --oknodo --retry 2 \
	    --pidfile $pid_dir/watch-${daemon}.pid
	sudo rm -f $pid_dir/watch-${daemon}.pid
	sudo start-stop-daemon --stop --quiet --oknodo --retry 2 \
	    --exec $exe_file
	sudo rm -f $pid_dir/${daemon}.pid
	;;

    restart)
	# Restart daemon
	sudo start-stop-daemon --stop --quiet --oknodo --exec $exe_file
	sudo start-stop-daemon --start --quiet \
	    --chdir $log_dir --exec $exe_file \
	    -- -d -P 0 -i $pid_dir/${daemon}.pid

	# Begin reloading transaction
	/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin || exit 1

	# In case of error undo
	trap "/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end" EXIT HUP INT QUIT TERM

	# Save current configuration
	tmp=/tmp/${daemon}-restart.$$
	/opt/vyatta/sbin/vyatta-save-config.pl $tmp || exit 1

	# Erase active configuration for that protocol
	rm -fr /opt/vyatta/config/active/protocols/${daemon/%d/}

	# Reload causing configuration to activate - implies commit
	# remove tmp file if successful
	/opt/vyatta/sbin/vyatta-load-config.pl $tmp || exit 1

	rm $tmp

	;;
    *)
	usage;;
esac