Changed init script not to use initlog.
[bpdyndnsd] / scripts / bpdyndnsd
1 #! /bin/sh
2 #
3 # bpdyndnsd
4 #
5 # chkconfig: 35 80 20
6 # description: Bullet proof dynamic DNS update daemon.
7 # processname: bpdyndnsd
8 # config: /etc/bpdyndnsd/bpdyndnsd.conf
9 # pidfile: /var/run/bpdyndnsd.pid
10
11 # Source function library.
12 . /etc/rc.d/init.d/functions
13
14 # Configuration
15 . /etc/sysconfig/bpdyndnsd
16
17 # Prog name
18 progname="bpdyndnsd (dynamic DNS update daemon)"
19 # User and group
20 user=bpdyndnsd
21 group=bpdyndnsd
22 # Binary file
23 prog=/usr/bin/bpdyndnsd
24 # PID file
25 pidfile=/var/run/bpdyndnsd.pid
26
27 test -x ${prog} || exit 0
28 test -e /etc/bpdyndnsd/bpdyndnsd.conf || exit 0
29
30 ##
31 ## tool functions:
32 ##
33
34 is_running() {
35     [ -f ${path_pidfile} ] || return 1
36     pid_from_file=`head -n1 ${path_pidfile}`
37     [ -L /proc/${pid_from_file}/exe ] || return 1
38     [ "`readlink /proc/${pid_from_file}/exe`" = "${path_prg}" ]
39 }
40 # eo is_running
41
42
43 ##
44 ## the functions:
45 ##
46
47 start() {
48     [ -f /var/lock/subsys/bpdyndnsd ] && stop
49
50     if [ $START_BPDYNDNSD -eq 1 ]; then
51         # Check if this is really bpdyndnsd's pid file
52         if [ -f $pidfile ]; then
53             if ! grep -s -q "bpdyndnsd" /proc/`cat $pidfile`/cmdline; then
54             echo "Unlinking non-bpdyndnsd pid file"
55             rm -f $pidfile
56             fi
57         fi
58
59         echo -n "Starting $progname: "
60         $prog --daemon_mode 1 --syslog 1;
61         RETVAL=$?
62         [ $RETVAL -eq 0 ] && success || failure
63         echo
64         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/bpdyndnsd
65     fi
66 }
67
68 stop() {
69     if [ ! -f /var/lock/subsys/bpdyndnsd ]; then
70         return 0
71     fi
72
73     echo -n "Stopping $progname: "
74     killproc bpdyndnsd
75     RETVAL=$?
76     [ $RETVAL -eq 0 ] && success || failure
77     echo
78     [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/bpdyndnsd
79 }
80
81 reload() {
82     echo -n "Reloading $progname: "
83     killproc bpdyndnsd -HUP
84     RETVAL=$?
85     [ $RETVAL -eq 0 ] && success || failure
86     echo
87 }
88
89 restart() {
90     stop
91     start
92 }
93
94
95 ##
96 ## determine what we should do:
97 ##
98 case "$1" in
99     start)
100         start
101         ;;
102     stop)
103         stop
104         ;;
105     status)
106         status $prog
107         RETVAL=$?
108         ;;
109     restart)
110         restart
111         ;;
112     reload)
113         reload
114         ;;
115     condrestart)
116         [ -f /var/lock/subsys/bpdyndnsd ] && restart || : 
117         ;;
118     *)
119         echo "Usage: bpdyndnsd {start|stop|status|restart|reload|condrestart}"
120         RETVAL=1
121 esac
122
123 exit $RETVAL