]> git.pld-linux.org Git - packages/gammu.git/blame - gammu-smsd.init
- up to 1.36.5
[packages/gammu.git] / gammu-smsd.init
CommitLineData
202fe725 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
14CONFIG_SMSD_INSTANCES=$SMSD_INSTANCES
15
16[ -n "$2" ] && SMSD_INSTANCES="$2"
17
18# no configured instances. exit silently
19if [ -z "$SMSD_INSTANCES" ]; then
20 case "$1" in
21 start|stop|restart|reload|force-reload)
22 exit 0
23 ;;
24 esac
25fi
26
27# Source function library
28. /etc/rc.d/init.d/functions
29
30
31# check if SMSD instance $1 s up
32instanceup() {
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
41instancesup() {
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
51anyinstancesup() {
52 ret=1
53 for instance in $CONFIG_SMSD_INSTANCES; do
54 instanceup $instance && return 0
55 done
56 return $ret
57}
58
59start() {
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
93stop() {
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
111RETVAL=0
112# See how we were called.
113case "$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 ;;
157esac
158
159exit $RETVAL
This page took 0.06983 seconds and 4 git commands to generate.