]> git.pld-linux.org Git - packages/gammu.git/blob - gammu-smsd.init
- bash-completion.pc is needed
[packages/gammu.git] / gammu-smsd.init
1 #!/bin/sh
2 #
3 # gammu-smsd            Start/stop the Gammu SMS Daemon.
4 #
5 # chkconfig:    2345 89 11
6 #
7 # description:  Gammu SMS Daemon receives and sends SMS through \
8 #               a GSM modem
9 #
10
11 # Get service config
12 [ -f /etc/sysconfig/gammu-smsd ] && . /etc/sysconfig/gammu-smsd
13
14 CONFIG_SMSD_INSTANCES=$SMSD_INSTANCES
15
16 [ -n "$2" ] && SMSD_INSTANCES="$2"
17
18 # no configured instances. exit silently
19 if [ -z "$SMSD_INSTANCES" ]; then
20         case "$1" in
21         start|stop|restart|reload|force-reload)
22                 exit 0
23                 ;;
24         esac
25 fi
26
27 # Source function library
28 . /etc/rc.d/init.d/functions
29
30
31 # check if SMSD instance $1 s up
32 instanceup() {
33         local instance="$1"
34         local pidfile=/var/run/gammu-smsd/$instance.pid
35         local pid=$(cat $pidfile 2>/dev/null)
36         kill -0 $pid 2>/dev/null
37         return $?
38 }
39
40 # check if all of the configured SMSD instances are up
41 instancesup() {
42         ret=0
43         for instance in $CONFIG_SMSD_INSTANCES; do
44                 instanceup $instance && continue
45                 ret=1
46         done
47         return $ret
48 }
49
50 # check if any of the configured SMSD instances is up
51 anyinstancesup() {
52         ret=1
53         for instance in $CONFIG_SMSD_INSTANCES; do
54                 instanceup $instance && return 0
55         done
56         return $ret
57 }
58
59 start() {
60         # Check if the service is already running?
61         if ! instancesup; then
62                 msg_starting "Gammu SMSD"; started
63                 for instance in $SMSD_INSTANCES; do
64                         config="/etc/gammu-smsd/$instance.conf"
65                         if [ ! -f "$config" ]; then
66                                 nls "Invalid Gammu SMSD instance \`%s': missing config: %s" "$instance" "$config"
67                                 fail
68                                 RET=1
69                         else    
70                                 GAMMU_SMSD_OPTS=""
71                                 show "Starting Gammu SMSD instance %s" "$instance"
72                                 if instanceup "$instance" ; then
73                                         started
74                                         continue
75                                 fi
76                                 daemon --pidfile /var/run/gammu-smsd/$instance.pid \
77                                         /usr/bin/gammu-smsd --config /etc/gammu-smsd/${instance}.conf \
78                                                 --pid /var/run/gammu-smsd/$instance.pid \
79                                                 --user gammu-smsd \
80                                                 --daemon \
81                                                  ${GAMMU_SMSD_OPTS}
82
83                                 RET=$?
84                         fi
85                         [ $RETVAL -eq 0 ] && RETVAL=$RET
86                 done
87                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/gammu-smsd
88         else
89                 msg_already_running "Gammu SMSD"
90         fi
91 }
92
93 stop() {
94         if anyinstancesup; then
95                 # Stop daemons.
96                 msg_stopping "Gammu SMSD"; started
97                 for instance in $SMSD_INSTANCES; do
98                         pidfile=/var/run/gammu-smsd/$instance.pid
99                         [ -f "$pidfile" ] || continue
100                         pid=$(cat "$pidfile")
101                         show "Stopping Gammu SMSD instance %s" "$instance"; busy
102                         killproc --pidfile "$pidfile" || err=1
103                         rm -f "$pidfile" >/dev/null 2>&1
104                 done
105                 anyinstancesup || rm -f /var/lock/subsys/gammu-smsd >/dev/null 2>&1
106         else
107                 msg_not_running "Gammu SMSD"
108         fi
109 }
110
111 RETVAL=0
112 # See how we were called.
113 case "$1" in
114   start)
115         start
116         ;;
117   stop)
118         stop
119         ;;
120   reload|force-reload)
121         if instancesup; then
122                 msg_reloading "Gammu SMSD"; started
123                 for instance in $SMSD_INSTANCES; do
124                         show "Reloading Gammu SMSD instance %s" "$instance"
125                         killproc --pidfile gammu-smsd/$instance.pid gammu-smsd -HUP
126                         [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
127                 done
128         else
129                 msg_not_running "Gammu SMSD"
130                 exit 7
131         fi
132         ;;
133   restart)
134         stop
135         sleep 1
136         start
137         exit $?
138         ;;
139   status)
140         nls "Configured Gammu SMSD instances:"
141         echo " $SMSD_INSTANCES"
142         nls "Currently running Gammu SMSD instances:"
143         for pidfile in /var/run/gammu-smsd/*.pid; do
144                 [ -f "$pidfile" ] || continue
145                 instance=${pidfile#/var/run/gammu-smsd/}
146                 instance=${instance%.pid}
147                 instanceup $instance && echo -n " $instance($(cat $pidfile))"
148         done
149         echo ""
150         instancesup
151         exit $?
152         ;;
153   *)
154         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
155         exit 3
156         ;;
157 esac
158
159 exit $RETVAL
This page took 0.045218 seconds and 3 git commands to generate.