#!/bin/sh # # NetworkManager: NetworkManager daemon # # description: This is a daemon for automatically switching network \ # connections to the best available connection. \ # # processname: NetworkManager # pidfile: /var/run/NetworkManager.pid # # Inhale the configuration. Ahem. . /etc/rc.d/rc.inet1.conf prefix=/usr exec_prefix=/usr sbindir=${exec_prefix}/sbin NETWORKMANAGER_BIN=${sbindir}/NetworkManager # Sanity checks. [ -x $NETWORKMANAGER_BIN ] || exit 0 # We need /sbin/ip [ -x /sbin/ip ] || exit 0 PIDFILE=/var/run/NetworkManager.pid interface_sanity() { local interfaces=0 # This makes extra passes. Get over it. for idx in 0 1 2 3 4 5 6; do if [ "${USE_DHCP[$idx]}" = "yes" ]; then (( interfaces++ )) continue fi if [ -n "${IPADDR[$idx]}" ]; then # NM isn't usable with statically configured interfaces interfaces=2 continue fi done # NetworkManager 0.6.x only handles a single, DHCP-enabled interface. if [ $interfaces -gt 1 ]; then echo "More than one interface or statically-configured interface detected." exit fi exit 1 } nm_start() { if [ "`pgrep dbus-daemon`" = "" ]; then echo "D-BUS must be running to start NetworkManager" return fi if [ "`pgrep hald`" = "" ]; then echo "HAL must be running to start NetworkManager" return fi # Just in case the pidfile is still there, we may need to nuke it. if [ -e "$PIDFILE" ]; then rm -f $PIDFILE fi echo "Starting NetworkManager daemon: $NETWORKMANAGER_BIN" $NETWORKMANAGER_BIN } nm_status() { local pidlist=`cat $PIDFILE 2>/dev/null` if [ -z "$pidlist" ]; then return 1 fi local command=`ps -p $pidlist -o comm=` if [ "$command" != 'NetworkManager' ]; then return 1 fi } dhcdbd_status() { if [ ! -x /etc/rc.d/rc.dhcdbd ]; then return 1 fi local response=`/etc/rc.d/rc.dhcdbd status 2>/dev/null` if [ "${response%%"not running."}" != "$response" ]; then return 1 fi } nm_stop() { echo -en "Stopping NetworkManager: " local pidlist=`cat $PIDFILE 2>/dev/null` if [ ! -z "$pidlist" ]; then kill $pidlist &>/dev/null rm -f $PIDFILE &>/dev/null echo "stopped" exit fi echo "not running" } nm_restart() { nm_stop nm_start } case "$1" in 'start') if ( ! interface_sanity ); then echo "NetworkManager will not be started." exit fi if ( ! dhcdbd_status ); then echo "NetworkManager requires DHCDBD and it is not enabled." exit fi if ( ! nm_status ); then nm_start else echo "NetworkManager is already running (will not start it twice)." fi ;; 'stop') nm_stop ;; 'restart') nm_restart ;; 'status') if ( nm_status ); then echo "NetworkManager is currently running" else echo "NetworkManager is not running." fi ;; *) echo "usage $0 start|stop|status|restart" esac # vim: ts=2