]>
Commit | Line | Data |
---|---|---|
3ec95567 | 1 | #!/bin/bash |
ea4d91bf DL |
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 | ||
33606a15 DL |
33 | # "/usr/lib/frr/frrinit.sh start somenamespace" |
34 | FRR_PATHSPACE="$2" | |
35 | ||
ea4d91bf DL |
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 | ||
9c251d37 DL |
77 | # systemd doesn't set WATCHDOG_USEC for reload commands. |
78 | watchfrr_pidfile="$V_PATH/watchfrr.pid" | |
79 | watchfrr_pid="`cat \"$watchfrr_pidfile\"`" | |
80 | if [ -d "/proc/$watchfrr_pid" ]; then | |
81 | wdt="`tr '\0' '\n' < /proc/$watchfrr_pid/environ | grep '^WATCHDOG_USEC='`" | |
82 | wdt="${wdt#WATCHDOG_USEC=}" | |
83 | [ -n "$wdt" ] && : ${WATCHDOG_USEC:=$wdt} | |
84 | [ -n "$WATCHDOG_USEC" ] && export WATCHDOG_USEC | |
85 | fi | |
86 | ||
ea4d91bf DL |
87 | # restart watchfrr to pick up added daemons. |
88 | # NB: This will NOT cause the other daemons to be restarted. | |
89 | daemon_list daemons | |
90 | watchfrr_options="$watchfrr_options $daemons" | |
91 | daemon_stop watchfrr && \ | |
92 | daemon_start watchfrr | |
93 | ||
9c251d37 DL |
94 | # make systemd not kill watchfrr after ExecReload completes |
95 | # 3 goats were sacrificed to restore sanity after coding this | |
96 | watchfrr_pid="`cat \"$watchfrr_pidfile\"`" | |
97 | if [ -f "/proc/$watchfrr_pid/cgroup" -a -d "/sys/fs/cgroup/systemd" ]; then | |
98 | cg="`egrep '^[0-9]+:name=systemd:' \"/proc/$watchfrr_pid/cgroup\"`" | |
99 | cg="${cg#*:*:}" | |
100 | ||
101 | cgmain="$cg" | |
102 | cgmain="${cgmain%/.control}" | |
103 | cgmain="${cgmain%/control}" | |
104 | ||
105 | [ -n "$cg" -a "$cg" != "$cgmain" ] && \ | |
106 | echo "$watchfrr_pid" > "/sys/fs/cgroup/systemd/$cgmain/tasks" | |
107 | fi | |
108 | ||
ea4d91bf DL |
109 | NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}" |
110 | [ ! -r $NEW_CONFIG_FILE ] && log_failure_msg "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1 | |
33606a15 | 111 | "$RELOAD_SCRIPT" --reload "$NEW_CONFIG_FILE" `echo $nsopt` |
ea4d91bf DL |
112 | exit $? |
113 | ;; | |
114 | ||
115 | *) | |
116 | log_failure_msg "Unknown command: $1" >&2 | |
117 | exit 1 | |
118 | esac |