blob: 1bd2c16caffcf5470aa75268dad157c8bea7e10c [file] [log] [blame]
xf.li86118912025-03-19 20:07:27 -07001#! /bin/sh
2#
3### BEGIN INIT INFO
4# Provides: radvd
5# Required-Start: $remote_fs $named $syslog
6# Required-Stop: $remote_fs $named $syslog
7# Default-Start: 3 5
8# Default-Stop: 0 1 2 6
9# Description: router advertisement daemon
10### END INIT INFO
11
12# Source function library.
13. /etc/init.d/functions
14
15PATH=/sbin:/bin:/usr/sbin:/usr/bin
16DAEMON=/usr/sbin/radvd
17NAME=radvd
18DESC=radvd
19CONFIG=/etc/radvd.conf
20SAVED_SETTINGS=/var/run/radvd/saved-settings
21PIDFILE=/var/run/radvd/radvd.pid
22OPTIONS="-u radvd -p $PIDFILE"
23
24test -x $DAEMON || exit 0
25
26set -e
27
28# Check for IPv6 support in kernel
29if test \! -e /proc/sys/net/ipv6; then
30 echo "IPv6 support must be enabled in the kernel for $DESC to work."
31 exit
32fi
33
34save_settings()
35{
36 local file=$1
37
38 rm -f $file
39 for if_conf in /proc/sys/net/ipv6/conf/*; do
40 echo -e "$if_conf/forwarding\t `cat $if_conf/forwarding`" >> $file
41 done
42 return 0
43}
44
45restore_settings()
46{
47 file=$1
48
49 if [ ! -f $file ]; then
50 echo "$0: warning: cannot restore settings"
51 return
52 fi
53
54 (
55 while read f value; do
56 if [ -w $f ]; then
57 echo $value > $f
58 fi
59 done
60 ) < $file
61}
62
63chkconfig() {
64 if [ ! -e $CONFIG -o ! -s $CONFIG ]; then
65 echo ""
66 echo "* $CONFIG does not exist or is empty."
67 echo "* See /usr/share/doc/radvd/radvd.conf.example for a simple"
68 echo "* configuration suitable for most systems, and radvd.conf(5)"
69 echo "* for configuration file syntax. radvd will *not* be started."
70 exit 0
71 fi
72}
73
74case "$1" in
75 start)
76 echo -n "Starting $DESC: "
77 mkdir -p /var/run/$NAME
78 chkconfig
79 save_settings $SAVED_SETTINGS
80
81 # We must enable IPv6 forwarding for radvd to work
82 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
83
84 # Check for stale pidfile; radvd won't start if one is lying around
85 if [ -f $PIDFILE ] && ! ps `cat $PIDFILE` > /dev/null; then
86 rm -f $PIDFILE
87 fi
88 if ! start-stop-daemon --oknodo --start --pidfile $PIDFILE \
89 --exec $DAEMON -- $OPTIONS; then
90 echo "failed." && exit 1
91 fi
92 echo "$NAME."
93 ;;
94 stop)
95 echo -n "Stopping $DESC: "
96 if ! [ -f $PIDFILE ] ; then
97 echo "not running."
98 exit 0
99 fi
100 start-stop-daemon --oknodo --stop --pidfile $PIDFILE \
101 --exec $DAEMON
102 restore_settings $SAVED_SETTINGS
103 rm -f $SAVED_SETTINGS
104 echo "$NAME."
105 ;;
106 status)
107 status $DAEMON;
108 exit $?
109 ;;
110 reload|force-reload)
111 echo "Reloading $DESC configuration files."
112 start-stop-daemon --stop --signal HUP --quiet --pidfile \
113 $PIDFILE --exec $DAEMON
114 ;;
115 restart)
116 chkconfig
117 echo -n "Restarting $DESC: "
118 if ! start-stop-daemon --stop --quiet --pidfile \
119 $PIDFILE --exec $DAEMON; then
120 # stop failed, so we were not running
121 save_settings $SAVED_SETTINGS
122 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
123 fi
124 sleep 1
125 start-stop-daemon --start --quiet --pidfile \
126 $PIDFILE --exec $DAEMON -- $OPTIONS
127 echo "$NAME."
128 ;;
129 *)
130 N=/etc/init.d/$NAME
131 echo "Usage: $N {start|stop|status|restart|reload|force-reload}" >&2
132 exit 1
133 ;;
134esac
135
136exit 0