3 # gammu-smsd Start/stop the Gammu SMS Daemon.
5 # chkconfig: 2345 89 11
7 # description: Gammu SMS Daemon receives and sends SMS through \
12 [ -f /etc/sysconfig/gammu-smsd ] && . /etc/sysconfig/gammu-smsd
14 CONFIG_SMSD_INSTANCES=$SMSD_INSTANCES
16 [ -n "$2" ] && SMSD_INSTANCES="$2"
18 # no configured instances. exit silently
19 if [ -z "$SMSD_INSTANCES" ]; then
21 start|stop|restart|reload|force-reload)
27 # Source function library
28 . /etc/rc.d/init.d/functions
31 # check if SMSD instance $1 s up
34 local pidfile=/var/run/gammu-smsd/$instance.pid
35 local pid=$(cat $pidfile 2>/dev/null)
36 kill -0 $pid 2>/dev/null
40 # check if all of the configured SMSD instances are up
43 for instance in $CONFIG_SMSD_INSTANCES; do
44 instanceup $instance && continue
50 # check if any of the configured SMSD instances is up
53 for instance in $CONFIG_SMSD_INSTANCES; do
54 instanceup $instance && return 0
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"
71 show "Starting Gammu SMSD instance %s" "$instance"
72 if instanceup "$instance" ; then
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 \
85 [ $RETVAL -eq 0 ] && RETVAL=$RET
87 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/gammu-smsd
89 msg_already_running "Gammu SMSD"
94 if anyinstancesup; then
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
105 anyinstancesup || rm -f /var/lock/subsys/gammu-smsd >/dev/null 2>&1
107 msg_not_running "Gammu SMSD"
112 # See how we were called.
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
129 msg_not_running "Gammu SMSD"
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))"
154 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"