#!/bin/sh # Bring up an interface. Any interface. # Author: Jim Carter, 2009-03-15 # Template Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc. # # Here's the issue: # 1. On this host there is a Kerberos KDC, but it won't start unless the # "network is up", i.e. at least one interface is up. # 2. NetworkManager starts early, but it expects to find the WEP key in # the Gnome Keyring, which is encrypted with the user's password. # 3. Kerberos has to start before the user's password can be # verified and the PAM auth step can be finished, including decrypting # the Gnome Keyring. # 4. Therefore, at least one interface has to be brought up "artificially" # before Kerberos starts. # The "Should-Start" items duplicate those of the distro-provided network # script, so it should run at the same time that script would run. ### BEGIN INIT INFO # Provides: network # Required-Start: $local_fs dbus haldaemon # Should-Start: isdn SuSEfirewall2_init firewall_J firewall6_J # Required-Stop: $local_fs dbus # Should-Stop: isdn SuSEfirewall2_init # Default-Start: 2 3 5 # Default-Stop: # Short-Description: Configure the network Jimc's way. # Description: Preload the network, make sure some interface is up so # Kerberos can start, and start NetworkManager. ### END INIT INFO . /etc/rc.status rc_reset # Address of mirror interface without and with CIDR bits MIRRORIPB=127.0.1.89/30 MIRRORIP=${MIRRORIPB%%/*} MIR_BIN=/usr/diklo/sbin/MirrorTunnel.pl NETMGR=/usr/sbin/NetworkManager # Identify our interfaces. If one is up, great, we're done. # Otherwise from among the "down" interfaces, pick one # arbitrarily. lo: is excluded because its operating mode # is "unknown". netdir=/etc/sysconfig/network # Locates all the interfaces which are up, or potentially could be up. # $1 = the action: status -> report which are up; anything else -> report # those which could be brought up. List on stdout. function findifcs () { local ifcs=`cd /sys/class/net && echo *` local f local s local rc for f in $ifcs ; do s=X`cat /sys/class/net/$f/operstate` if [ "$s" != "Xup" -a "$s" != "Xdown" ] ; then continue ; fi if [ X$1 = Xstatus ] ; then rc=0 s=`ip addr show dev $f | grep 'inet'` if [ -z "$s" ] ; then rc=1 ; fi s=`ip link show eth0 | grep '<.*UP.*>'` if [ -z "$s" ] ; then rc=1 ; fi if [ $rc -eq 0 ] ; then echo -n "$f " ; fi else if [ ! -r $netdir/ifcfg-$f ] ; then continue ; fi . $netdir/ifcfg-$f if [ -z "$IPADDR" ] ; then continue ; fi IPADDR='' echo -n "$f " fi done } # Bring up an interface. Arg(s) are output from `findifcs status`. The first # of these is brought up. function startifc () { local ifc=$1 . $netdir/ifcfg-$ifc ip addr add $IPADDR/32 scope host dev $ifc ip link set $ifc up } # This function starts/stops a fake network interface. # Command line arg should be the action ("start", "stop", etc.). The mirror # is started or stopped; on any other action (e.g. "status") it is only # checked. Exit code is 0 if the mirror is running (except for "stop", if # it was running and was stopped, or was not running); nonzero otherwise. function startmirror () { local action=$1 if [ ! -x "$MIR_BIN" ] ; then return 4 ; fi local f ifc addr phase local mipre=`echo $MIRRORIP | sed -e 's/\./\\\\./g'` # When starting, repeat this once a second until mirror is up. for phase in 1 2 3 4 5 6 7 8 9 10 ; do # Is the mirror tunnel already running? Bypass if so. for f in /sys/class/net/* ; do ifc=${f##*/} addr=`ip addr show dev $ifc | grep "inet *$mipre"` if [ -n "$addr" ] ; then if [ "$action" = "stop" ] ; then killproc $MIR_BIN fi return 0 fi done if [ "$action" = "stop" ] ; then return 0 ; fi # Detect if mirror was started and died. if [ "$action" != "start" ] ; then return 4 ; fi if [ $phase = 1 ] ; then startproc $MIR_BIN $MIRRORIPB fi sleep 1 # Go around again and make sure the mirror started. done return 4 # Trying to start, and it didn't start } case "$1" in start ) for f in 1 2 ; do echo -n "DEBUG check network manager: " if checkproc $NETMGR ; then echo "OK" break else echo "Not running, try to start it" startproc $NETMGR sleep 2 fi done echo -n "Start mirror tunnel " if startmirror $1 ; then rc_status -v else rc_failed fi ;; stop) echo -n "Stop mirror tunnel " if startmirror $1 ; then rc_status -v else rc_failed fi echo -n "Stop NetworkManager " killproc $NETMGR rc_status -v ;; status) echo -n "Checking processes: " for f in $NETMGR $MIR_BIN ; do echo -n "(${f##*/} " if checkproc $f ; then echo -n "OK) " else rc_status echo -n " missing) " fi done rc_status -v echo -n "Checking if network is up " ifcs=`findifcs status` if [ -n "$ifcs" ] ; then echo -n "($ifcs OK) " rc_status -v else echo -n "(it isn't) " rc_status -u fi ;; reload|force-reload) echo -n "Reload network (can't, use restart instead) " rc_failed 3 rc_status -v ;; restart|try-restart|condrestart ) $0 stop $0 start rc_status ;; *) echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" exit 1 ;; esac rc_exit