]> git.proxmox.com Git - mirror_frr.git/blob - tools/frrinit.sh.in
Merge pull request #5348 from ton31337/fix/bgp_dampening_per_afi_safi_7.1
[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 self="`dirname $0`"
34 if [ -r "$self/frrcommon.sh" ]; then
35 . "$self/frrcommon.sh"
36 else
37 . "@CFG_SBIN@/frrcommon.sh"
38 fi
39
40 case "$1" in
41 start)
42 daemon_list daemons
43 watchfrr_options="$watchfrr_options $daemons"
44 daemon_start watchfrr
45 ;;
46 stop)
47 daemon_stop watchfrr
48 all_stop --reallyall
49 exit ${still_running:-0}
50 ;;
51
52 restart|force-reload)
53 daemon_stop watchfrr
54 all_stop --reallyall
55
56 daemon_list daemons
57 watchfrr_options="$watchfrr_options $daemons"
58 daemon_start watchfrr
59 ;;
60
61 status)
62 fail=0
63 print_status watchfrr || fail=1
64 all_status || fail=1
65 exit $fail
66 ;;
67
68 reload)
69 if [ ! -x "$RELOAD_SCRIPT" ]; then
70 log_failure_msg "The frr-pythontools package is required for reload functionality."
71 exit 1
72 fi
73
74 # systemd doesn't set WATCHDOG_USEC for reload commands.
75 watchfrr_pidfile="$V_PATH/watchfrr.pid"
76 watchfrr_pid="`cat \"$watchfrr_pidfile\"`"
77 if [ -d "/proc/$watchfrr_pid" ]; then
78 wdt="`tr '\0' '\n' < /proc/$watchfrr_pid/environ | grep '^WATCHDOG_USEC='`"
79 wdt="${wdt#WATCHDOG_USEC=}"
80 [ -n "$wdt" ] && : ${WATCHDOG_USEC:=$wdt}
81 [ -n "$WATCHDOG_USEC" ] && export WATCHDOG_USEC
82 fi
83
84 # restart watchfrr to pick up added daemons.
85 # NB: This will NOT cause the other daemons to be restarted.
86 daemon_list daemons
87 watchfrr_options="$watchfrr_options $daemons"
88 daemon_stop watchfrr && \
89 daemon_start watchfrr
90
91 # make systemd not kill watchfrr after ExecReload completes
92 # 3 goats were sacrificed to restore sanity after coding this
93 watchfrr_pid="`cat \"$watchfrr_pidfile\"`"
94 if [ -f "/proc/$watchfrr_pid/cgroup" -a -d "/sys/fs/cgroup/systemd" ]; then
95 cg="`egrep '^[0-9]+:name=systemd:' \"/proc/$watchfrr_pid/cgroup\"`"
96 cg="${cg#*:*:}"
97
98 cgmain="$cg"
99 cgmain="${cgmain%/.control}"
100 cgmain="${cgmain%/control}"
101
102 [ -n "$cg" -a "$cg" != "$cgmain" ] && \
103 echo "$watchfrr_pid" > "/sys/fs/cgroup/systemd/$cgmain/tasks"
104 fi
105
106 NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}"
107 [ ! -r $NEW_CONFIG_FILE ] && log_failure_msg "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
108 "$RELOAD_SCRIPT" --reload "$NEW_CONFIG_FILE"
109 exit $?
110 ;;
111
112 *)
113 log_failure_msg "Unknown command: $1" >&2
114 exit 1
115 esac