5 kx #!/bin/sh
5 kx #
5 kx # NetworkManager: NetworkManager daemon
5 kx #
5 kx # description: This is a daemon for automatically switching network \
5 kx # connections to the best available connection. \
5 kx #
5 kx # processname: NetworkManager
5 kx # pidfile: /var/run/NetworkManager/NetworkManager.pid
5 kx #
5 kx
5 kx prefix=/usr
5 kx exec_prefix=/usr
5 kx sbindir=${exec_prefix}/sbin
5 kx
5 kx NETWORKMANAGER_BIN=${sbindir}/NetworkManager
5 kx
5 kx # Sanity checks.
5 kx [ -x $NETWORKMANAGER_BIN ] || exit 0
5 kx
5 kx PIDFILE=/var/run/NetworkManager/NetworkManager.pid
5 kx
5 kx nm_start()
5 kx {
5 kx if [ "`pgrep dbus-daemon`" = "" ]; then
5 kx echo "D-BUS must be running to start NetworkManager"
5 kx return
5 kx fi
5 kx
5 kx # Just in case the pidfile is still there, we may need to nuke it.
5 kx if [ -e "$PIDFILE" ]; then
5 kx rm -f $PIDFILE
5 kx fi
5 kx
5 kx echo "Starting NetworkManager daemon: $NETWORKMANAGER_BIN"
5 kx XDG_CACHE_HOME=/root/.cache $NETWORKMANAGER_BIN
5 kx }
5 kx
5 kx nm_status()
5 kx {
5 kx local pidlist=`cat $PIDFILE 2>/dev/null`
5 kx if [ -z "$pidlist" ]; then
5 kx return 1
5 kx fi
5 kx local command=`ps -p $pidlist -o comm=`
5 kx if [ "$command" != 'NetworkManager' ]; then
5 kx return 1
5 kx fi
5 kx }
5 kx
5 kx nm_stop()
5 kx {
5 kx echo -en "Stopping NetworkManager: "
5 kx # Shut down any DHCP connections, otherwise the processes will be orphaned
5 kx # and the connections will not come up when NetworkManager restarts.
5 kx if ps ax | grep /sbin/dhcpcd | grep -q libexec/nm-dhcp ; then
5 kx ps ax | grep /sbin/dhcpcd | grep libexec/nm-dhcp | while read line ; do
5 kx kill -HUP $(echo $line | cut -b 1-5)
5 kx done
5 kx fi
5 kx if ps ax | grep /sbin/dhclient | grep -q /var/lib/NetworkManager ; then
5 kx ps ax | grep /sbin/dhclient | grep /var/lib/NetworkManager | while read line ; do
5 kx kill -HUP $(echo $line | cut -b 1-5)
5 kx done
5 kx fi
5 kx local pidlist=`cat $PIDFILE 2>/dev/null`
5 kx if [ ! -z "$pidlist" ]; then
5 kx kill $pidlist &>/dev/null
5 kx sleep 3
5 kx rm -f $PIDFILE &>/dev/null
5 kx fi
5 kx # If wpa_supplicant is running here, it needs to be shut down as well.
5 kx # Since you're asking for NetworkManager to shut down, we have to assume
5 kx # that wpa_supplicant was started by it.
5 kx if [ -r /var/run/wpa_supplicant.pid ]; then
5 kx kill $(cat /var/run/wpa_supplicant.pid)
5 kx elif [ -r /run/wpa_supplicant.pid ]; then
5 kx kill $(cat /run/wpa_supplicant.pid)
5 kx fi
5 kx echo "stopped";
5 kx sleep 3
5 kx }
5 kx
5 kx nm_restart()
5 kx {
5 kx nm_stop
5 kx nm_start
5 kx }
5 kx
5 kx case "$1" in
5 kx 'start')
5 kx if ( ! nm_status ); then
5 kx nm_start
5 kx else
5 kx echo "NetworkManager is already running (will not start it twice)."
5 kx fi
5 kx ;;
5 kx 'stop')
5 kx nm_stop
5 kx ;;
5 kx 'restart')
5 kx nm_restart
5 kx ;;
5 kx 'status')
5 kx if ( nm_status ); then
5 kx echo "NetworkManager is currently running"
5 kx else
5 kx echo "NetworkManager is not running."
5 kx fi
5 kx ;;
5 kx *)
5 kx echo "usage $0 start|stop|status|restart"
5 kx esac