|
@@ -0,0 +1,152 @@
|
|
1
|
+#!/bin/sh /etc/rc.common
|
|
2
|
+# Copyright (C) 2014 OpenWrt.org
|
|
3
|
+# smsd initscript openwrt mod
|
|
4
|
+
|
|
5
|
+START=99
|
|
6
|
+STOP=99
|
|
7
|
+
|
|
8
|
+EXTRA_COMMANDS="status"
|
|
9
|
+EXTRA_HELP=" status View pid and service status "
|
|
10
|
+
|
|
11
|
+# Set USER and GROUP, if necessary:
|
|
12
|
+USER=""
|
|
13
|
+GROUP=""
|
|
14
|
+
|
|
15
|
+# If an unpriviledged user is selected, make sure that next two
|
|
16
|
+# files are writable by that user:
|
|
17
|
+PIDFILE="/var/run/smsd.pid"
|
|
18
|
+INFOFILE="/var/run/smsd.working"
|
|
19
|
+# Logfile can also be defined in here:
|
|
20
|
+LOGFILE="/var/log/smsd.log"
|
|
21
|
+
|
|
22
|
+DAEMON=/usr/local/bin/smsd
|
|
23
|
+# A program which turns power off for couple of seconds:
|
|
24
|
+RESETMODEMS=/usr/local/bin/smsd_resetmodems
|
|
25
|
+NAME=smsd
|
|
26
|
+PSOPT=""
|
|
27
|
+
|
|
28
|
+# Set/edit this before starting service !!!!!
|
|
29
|
+WRT_SPOOL=/var/spool
|
|
30
|
+
|
|
31
|
+# Maximum time to stop smsd, after that it gets killed hardly:
|
|
32
|
+MAXWAIT=45
|
|
33
|
+
|
|
34
|
+boot() {
|
|
35
|
+ start
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+start() {
|
|
39
|
+ test -x $DAEMON || exit 0
|
|
40
|
+
|
|
41
|
+ echo "Creating minimum spool directories"
|
|
42
|
+ mkdir -p $WRT_SPOOL
|
|
43
|
+ mkdir -p $WRT_SPOOL/sms
|
|
44
|
+ mkdir -p $WRT_SPOOL/sms/incoming
|
|
45
|
+ mkdir -p $WRT_SPOOL/sms/outgoing
|
|
46
|
+ mkdir -p $WRT_SPOOL/sms/checked
|
|
47
|
+ mkdir -p $WRT_SPOOL/sms/failed
|
|
48
|
+ mkdir -p $WRT_SPOOL/sms/sent
|
|
49
|
+
|
|
50
|
+ echo -n "Starting SMS Daemon: "
|
|
51
|
+ MSG="."
|
|
52
|
+ ARGS="-n MAINPROCESS -p$PIDFILE -i$INFOFILE"
|
|
53
|
+ [ "x$USER" != x ] && ARGS="$ARGS -u$USER"
|
|
54
|
+ [ "x$GROUP" != x ] && ARGS="$ARGS -g$GROUP"
|
|
55
|
+ [ "x$LOGFILE" != x ] && ARGS="$ARGS -l$LOGFILE"
|
|
56
|
+ PID=`cat $PIDFILE 2>/dev/null`
|
|
57
|
+ if [ "x$PID" != x ]; then
|
|
58
|
+ if kill -0 $PID 2>/dev/null; then
|
|
59
|
+ MSG=" already running ($PID)."
|
|
60
|
+ else
|
|
61
|
+ PID=""
|
|
62
|
+ fi
|
|
63
|
+ fi
|
|
64
|
+ if [ "x$PID" = x ]; then
|
|
65
|
+ if ps $PSOPT | grep $NAME | grep -v grep >/dev/null; then
|
|
66
|
+ MSG=" already running."
|
|
67
|
+ else
|
|
68
|
+ $DAEMON $ARGS
|
|
69
|
+ sleep 1
|
|
70
|
+ PIDS=`ps $PSOPT | grep $NAME | grep -v grep`
|
|
71
|
+ [ "x$PIDS" = x ] && MSG=" failed."
|
|
72
|
+ fi
|
|
73
|
+ fi
|
|
74
|
+ echo "$NAME$MSG"
|
|
75
|
+}
|
|
76
|
+
|
|
77
|
+stop() {
|
|
78
|
+ if ps $PSOPT | grep $NAME | grep -v grep >/dev/null; then
|
|
79
|
+ PID=`cat $PIDFILE 2>/dev/null`
|
|
80
|
+ if [ "x$PID" != x ]; then
|
|
81
|
+ P=`kill -0 $PID 2>/dev/null`
|
|
82
|
+ [ "x$P" != x ] && PID=""
|
|
83
|
+ fi
|
|
84
|
+ if [ "x$PID" != x ]; then
|
|
85
|
+ kill $PID
|
|
86
|
+ else
|
|
87
|
+ kill `ps $PSOPT | grep $NAME | grep -v grep | awk '{print $1}'` >/dev/null 2>&1
|
|
88
|
+ fi
|
|
89
|
+ sleep 1
|
|
90
|
+ if ps $PSOPT | grep $NAME | grep -v grep >/dev/null; then
|
|
91
|
+ echo "Allowing $NAME to terminate gracefully within $MAXWAIT seconds"
|
|
92
|
+ infofound=0
|
|
93
|
+ dots=0
|
|
94
|
+ seconds=0
|
|
95
|
+ while ps $PSOPT | grep $NAME | grep -v grep >/dev/null; do
|
|
96
|
+ if [ $infofound -lt 1 ]; then
|
|
97
|
+ if [ -f $INFOFILE ]; then
|
|
98
|
+ infofound=1
|
|
99
|
+ if [ $dots -gt 0 ]; then
|
|
100
|
+ echo ""
|
|
101
|
+ dots=0
|
|
102
|
+ fi
|
|
103
|
+ $ECHO -n "$NAME is currently "
|
|
104
|
+ cat $INFOFILE
|
|
105
|
+ echo "Time counting is now disabled and we will wait until this job is complete."
|
|
106
|
+ fi
|
|
107
|
+ fi
|
|
108
|
+ [ $infofound -lt 1 ] && seconds=`expr $seconds + 1`
|
|
109
|
+ echo -n "."
|
|
110
|
+ dots=`expr $dots + 1`
|
|
111
|
+ if [ "$seconds" -ge $MAXWAIT ]; then
|
|
112
|
+ if [ $dots -gt 0 ]; then
|
|
113
|
+ echo ""
|
|
114
|
+ dots=0
|
|
115
|
+ fi
|
|
116
|
+ echo "Timeout occured, killing $NAME hardly."
|
|
117
|
+ kill -9 `ps $PSOPT | grep $NAME | grep -v grep | awk '{print $1}'` >/dev/null 2>&1
|
|
118
|
+ [ -f $PIDFILE ] && rm $PIDFILE
|
|
119
|
+ seconds=0
|
|
120
|
+ fi
|
|
121
|
+ sleep 1
|
|
122
|
+ done
|
|
123
|
+ [ $dots -gt 0 ] && echo ""
|
|
124
|
+ #echo "$NAME is stopped."
|
|
125
|
+ fi
|
|
126
|
+ fi
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+restart() {
|
|
130
|
+ stop
|
|
131
|
+ start
|
|
132
|
+}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+status() {
|
|
136
|
+ PID=$(cat $PIDFILE)
|
|
137
|
+
|
|
138
|
+ test -e $PIDFILE
|
|
139
|
+ if [ $? == 0 ]; then
|
|
140
|
+ echo $NAME " running! pid $PID"
|
|
141
|
+ else
|
|
142
|
+ echo $NAME " not running !!!"
|
|
143
|
+ fi
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+reset() {
|
|
147
|
+ $0 stop
|
|
148
|
+ [ -f "$RESETMODEMS" ] && "$RESETMODEMS"
|
|
149
|
+ sleep 30
|
|
150
|
+ $0 start
|
|
151
|
+}
|
|
152
|
+
|