]> git.proxmox.com Git - mirror_frr.git/blob - tools/frrinit.sh.in
2396b1a3260f2a443edc5e9d9d2d1adfec9308f0
[mirror_frr.git] / tools / frrinit.sh.in
1 #!/bin/bash
2 #
3 ### BEGIN INIT INFO
4 # Provides: frr
5 # Required-Start: $local_fs $network $remote_fs $syslog
6 # Required-Stop: $local_fs $network $remote_fs $syslog
7 # Default-Start: 2 3 4 5
8 # Default-Stop: 0 1 6
9 # Short-Description: start and stop the FRR routing suite
10 # Description: FRR is a routing suite for IP routing protocols like
11 # BGP, OSPF, RIP and others. This script contols the main
12 # "watchfrr" daemon.
13 ### END INIT INFO
14 #
15 # This is the main init script for FRR. It mostly wraps frrcommon.sh which
16 # provides the actual functions to start/stop/restart things.
17 #
18
19 if [ -r "/lib/lsb/init-functions" ]; then
20 . /lib/lsb/init-functions
21 else
22 log_success_msg() {
23 echo "$@"
24 }
25 log_warning_msg() {
26 echo "$@" >&2
27 }
28 log_failure_msg() {
29 echo "$@" >&2
30 }
31 fi
32
33 # "/usr/lib/frr/frrinit.sh start somenamespace"
34 FRR_PATHSPACE="$2"
35
36 self="`dirname $0`"
37 if [ -r "$self/frrcommon.sh" ]; then
38 . "$self/frrcommon.sh"
39 else
40 . "@CFG_SBIN@/frrcommon.sh"
41 fi
42
43 case "$1" in
44 start)
45 daemon_list daemons
46 watchfrr_options="$watchfrr_options $daemons"
47 daemon_start watchfrr
48 ;;
49 stop)
50 daemon_stop watchfrr
51 all_stop --reallyall
52 exit ${still_running:-0}
53 ;;
54
55 restart|force-reload)
56 daemon_stop watchfrr
57 all_stop --reallyall
58
59 daemon_list daemons
60 watchfrr_options="$watchfrr_options $daemons"
61 daemon_start watchfrr
62 ;;
63
64 status)
65 fail=0
66 print_status watchfrr || fail=1
67 all_status || fail=1
68 exit $fail
69 ;;
70
71 reload)
72 if [ ! -x "$RELOAD_SCRIPT" ]; then
73 log_failure_msg "The frr-pythontools package is required for reload functionality."
74 exit 1
75 fi
76
77 # systemd doesn't set WATCHDOG_USEC for reload commands.
78 watchfrr_pidfile="$V_PATH/watchfrr.pid"
79 watchfrr_pid="`cat \"$watchfrr_pidfile\"`"
80 watchfrr_cmdline="`tr '\0' '\n' < /proc/$watchfrr_pid/cmdline`"
81 if [ -d "/proc/$watchfrr_pid" ]; then
82 wdt="`tr '\0' '\n' < /proc/$watchfrr_pid/environ | grep '^WATCHDOG_USEC='`"
83 wdt="${wdt#WATCHDOG_USEC=}"
84 [ -n "$wdt" ] && : ${WATCHDOG_USEC:=$wdt}
85 [ -n "$WATCHDOG_USEC" ] && export WATCHDOG_USEC
86 fi
87
88 # restart watchfrr to pick up added daemons.
89 # NB: This will NOT cause the other daemons to be restarted.
90 daemon_list enabled_daemons disabled_daemons
91 watchfrr_options="$watchfrr_options $enabled_daemons"
92 daemon_stop watchfrr && \
93 daemon_start watchfrr
94
95 # If we disable an arbitrary daemon and do reload,
96 # disabled daemon is still running and we should stop it.
97 for daemon in $disabled_daemons; do
98 if grep -q "$daemon" <<< "$watchfrr_cmdline"; then
99 daemon_stop "$daemon" &
100 pids="$pids $!"
101 fi
102 done
103
104 for pid in $pids; do
105 wait "$pid"
106 done
107
108 # make systemd not kill watchfrr after ExecReload completes
109 # 3 goats were sacrificed to restore sanity after coding this
110 watchfrr_pid="`cat \"$watchfrr_pidfile\"`"
111 if [ -f "/proc/$watchfrr_pid/cgroup" -a -d "/sys/fs/cgroup/systemd" ]; then
112 cg="`egrep '^[0-9]+:name=systemd:' \"/proc/$watchfrr_pid/cgroup\"`"
113 cg="${cg#*:*:}"
114
115 cgmain="$cg"
116 cgmain="${cgmain%/.control}"
117 cgmain="${cgmain%/control}"
118
119 [ -n "$cg" -a "$cg" != "$cgmain" ] && \
120 echo "$watchfrr_pid" > "/sys/fs/cgroup/systemd/$cgmain/tasks"
121 fi
122
123 NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}"
124 [ ! -r $NEW_CONFIG_FILE ] && log_failure_msg "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
125 "$RELOAD_SCRIPT" --reload --bindir "$D_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$NEW_CONFIG_FILE" `echo $nsopt`
126 exit $?
127 ;;
128
129 *)
130 echo "Usage:"
131 echo " ${0} <start|stop|restart|force-reload|reload|status> [namespace]"
132 echo " ${0} stop namespace1"
133 exit 1
134 ;;
135 esac