File: rc.networkmanager-dispatcher.in

package info (click to toggle)
network-manager 0.6.4-6%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 6,528 kB
  • ctags: 3,016
  • sloc: ansic: 33,692; sh: 9,574; makefile: 721
file content (99 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# NetworkManagerDispatcher:   NetworkManagerDispatcher daemon
#
# description:  This is a daemon for automatically switching network \
#               connections to the best available connection. \
#
# processname: NetworkManagerDispatcher
# pidfile: /var/run/NetworkManagerDispatcher.pid
#

prefix=@prefix@
exec_prefix=@prefix@
sbindir=@sbindir@

NETWORKMANAGER_BIN=${sbindir}/NetworkManagerDispatcher

# Sanity checks.
[ -x $NETWORKMANAGER_BIN ] || exit 0

# We need /sbin/ip
[ -x /sbin/ip ] || exit 0

PIDFILE=/var/run/NetworkManagerDispatcher.pid

nm_start()
{
	if [ "`pgrep dbus-daemon`" = "" ]; then
    echo "D-BUS must be running to start NetworkManagerDispatcher"
    return
	fi
  
	if [ "`pgrep hald`" = "" ]; then
	 echo "HAL must be running to start NetworkManagerDispatcher"
	 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 NetworkManagerDispatcher 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" != 'NetworkManagerDispatcher' ]; then
    return 1
  fi
}

nm_stop()
{
  echo -en "Stopping NetworkManagerDispatcher: "
  local pidlist=`cat $PIDFILE 2>/dev/null`
  if [ ! -z "$pidlist" ]; then
    kill $pidlist &>/dev/null
    rm -f $PIDFILE &>/dev/null
	fi
  echo "stopped";
}

nm_restart()
{
  nm_stop
  nm_start
}

case "$1" in
'start')
  if ( ! nm_status ); then
    nm_start
  else
    echo "NetworkManagerDispatcher is already running (will not start it twice)."
  fi
		;;
'stop')
  nm_stop
		;;
'restart')
  nm_restart
		;;
'status')
  if ( nm_status ); then
    echo "NetworkManagerDispatcher is currently running"
  else
    echo "NetworkManagerDispatcher is not running."
  fi
		;;
*)
  echo "usage $0 start|stop|status|restart"
esac