1#! /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 chkconfig 78 save_settings $SAVED_SETTINGS 79 80 # We must enable IPv6 forwarding for radvd to work 81 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding 82 83 # Check for stale pidfile; radvd won't start if one is lying around 84 if [ -f $PIDFILE ] && ! ps `cat $PIDFILE` > /dev/null; then 85 rm -f $PIDFILE 86 fi 87 if ! start-stop-daemon --oknodo --start --pidfile $PIDFILE \ 88 --exec $DAEMON -- $OPTIONS; then 89 echo "failed." && exit 1 90 fi 91 echo "$NAME." 92 ;; 93 stop) 94 echo -n "Stopping $DESC: " 95 if ! [ -f $PIDFILE ] ; then 96 echo "not running." 97 exit 0 98 fi 99 start-stop-daemon --oknodo --stop --pidfile $PIDFILE \ 100 --exec $DAEMON 101 restore_settings $SAVED_SETTINGS 102 rm -f $SAVED_SETTINGS 103 echo "$NAME." 104 ;; 105 status) 106 status $DAEMON; 107 exit $? 108 ;; 109 reload|force-reload) 110 echo "Reloading $DESC configuration files." 111 start-stop-daemon --stop --signal HUP --quiet --pidfile \ 112 $PIDFILE --exec $DAEMON 113 ;; 114 restart) 115 chkconfig 116 echo -n "Restarting $DESC: " 117 if ! start-stop-daemon --stop --quiet --pidfile \ 118 $PIDFILE --exec $DAEMON; then 119 # stop failed, so we were not running 120 save_settings $SAVED_SETTINGS 121 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding 122 fi 123 sleep 1 124 start-stop-daemon --start --quiet --pidfile \ 125 $PIDFILE --exec $DAEMON -- $OPTIONS 126 echo "$NAME." 127 ;; 128 *) 129 N=/etc/init.d/$NAME 130 echo "Usage: $N {start|stop|status|restart|reload|force-reload}" >&2 131 exit 1 132 ;; 133esac 134 135exit 0 136