]> git.pld-linux.org Git - packages/dhcdbd.git/blob - dhcdbd.init
- always remove lockfile. otherwise it's impossible to start daemon if stop fails...
[packages/dhcdbd.git] / dhcdbd.init
1 #!/bin/sh
2 #
3 # dhcdbd        DHCP Client D-BUS Daemon
4 #
5 # chkconfig:    345 89 11
6 # description:  dhcdbd provides D-BUS control of the ISC DHCP client, dhclient,
7 #               and D-BUS access to the DHCP options obtained by dhclient
8 #               for each IPv4 interface.
9 # processname:  dhcdbd
10 # pidfile:      /var/run/dhcdbd.pid
11 # config:       /etc/dbus-1/system.d/dhcdbd.conf
12 #
13 # $Id$
14
15 # Source function library
16 . /etc/rc.d/init.d/functions
17
18 # Get network config
19 . /etc/sysconfig/network
20
21 # Get service config
22 [ -f /etc/sysconfig/dhcdbd ] && . /etc/sysconfig/dhcdbd
23
24 # Check that networking is up.
25 if is_yes "${NETWORKING}"; then
26         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
27                 msg_network_down dhcdbd
28                 exit 1
29         fi
30 else
31         exit 0
32 fi
33
34 start() {
35         if [ -f /var/lock/subsys/messagebus ]; then
36                 if [ ! -f /var/lock/subsys/dhcdbd ]; then
37                         msg_starting dhcdbd
38                         daemon /usr/sbin/dhcdbd --system
39                         RETVAL=$?
40                         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcdbd
41                 else
42                         msg_already_running dhcdbd
43                 fi
44         else
45                 msg_not_running messagebus
46         fi
47 }
48
49 stop() {
50         msg_stopping dhcdbd
51         if [ -f /var/run/dhcdbd.pid ]; then
52                 checkpid `cat /var/run/dhcdbd.pid` >/dev/null 2>&1
53                 if [ $? -eq 1 ]; then
54                         rm -f /var/lock/subsys/dhcdbd /var/run/dhcdbd.pid >/dev/null 2>&1
55                         died
56                         exit 0
57                 fi
58         fi
59         if [ -f /var/lock/subsys/messagebus ]; then
60                 if [ -f /var/lock/subsys/dhcdbd ]; then
61                         /usr/bin/dbus-send \
62                                 --system \
63                                 --dest=com.redhat.dhcp \
64                                 --type=method_call \
65                                 --print-reply \
66                                 --reply-timeout=20000 \
67                                 /com/redhat/dhcp \
68                                 com.redhat.dhcp.quit >/dev/null 2>&1
69                         if [ $? -eq 0 ]; then
70                                 ok
71                         else
72                                 fail
73                         fi
74                         rm -f /var/lock/subsys/dhcdbd /var/run/dhcdbd.pid >/dev/null 2>&1
75                 else
76                         msg_not_running dhcdbd
77                 fi
78         else
79                 msg_not_running messagebus
80         fi
81 }
82
83 condrestart() {
84         if [ -f /var/lock/subsys/dhcdbd ]; then
85                 stop
86                 start
87         else
88                 msg_not_running dhcdbd
89                 RETVAL=$1
90         fi
91 }
92
93 RETVAL=0
94 # See how we were called.
95 case "$1" in
96   start)
97         start
98         ;;
99   stop)
100         stop
101         ;;
102   restart)
103         stop
104         start
105         ;;
106   try-restart)
107         condrestart 0
108         ;;
109   force-reload)
110         condrestart 7
111         ;;
112   status)
113         status dhcdbd
114         if [ $? -eq 0 ]; then
115                 pid=`cat /var/run/dhcdbd.pid`
116                 if [ $? -eq 0 -a -n "$pid" ]; then
117                         sender=`/usr/bin/dbus-send \
118                                         --system \
119                                         --dest=com.redhat.dhcp \
120                                         --type=method_call \
121                                         --print-reply \
122                                         --reply-timeout=20000 \
123                                         /com/redhat/dhcp \
124                                         com.redhat.dhcp.ping |
125                                 grep 'sender=' | sed 's/^.*sender=//;s/\ .*$//'`
126                         if [ $? -eq 0 ]; then
127                                 echo 'it is listening on '$sender
128                         fi
129                 fi
130         fi
131         ;;
132   *)
133         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
134         exit 3
135         ;;
136 esac
137
138 exit $RETVAL
This page took 0.056428 seconds and 3 git commands to generate.