parser: some more const-correctness for the other functions in msg_parser.[c,h]
[sip-router] / etc / imgwd
1 #!/bin/sh
2 #
3 # 3w-xxxx:      Starts the sip2jab process
4 #
5 # Version:      @(#) /etc/rc.d/init.d/3w-xxxx
6 #
7 # chkconfig: 2345 85 15
8 # description: controls execution of SIP2Jabber gateway
9
10 # JABBER
11 JDIR="/home/sms/jabber-1.4.2"
12 JABBERD="${JDIR}/jabberd/jabberd"
13 JICQEXT="${JDIR}/icqv7ext.sh"
14 CONF="${JDIR}/conf/single.xml"
15 JUSR="sms"
16 JPID="${JDIR}/spool/jabbers.pid"
17 JOUT="${JDIR}/spool/jabberd.log"
18
19 # SER
20 BIN=imgw
21 HM=/home/sms/srouter
22 BINDIR=$HM/bin
23 ETC=$HM/sip_router/etc/imgw.cfg
24 USR="sms"
25 GRP="sms"
26 MYDIR=$HM/core
27 CORE=$MYDIR/core
28
29 RETVAL=0
30
31 ############ ==== #############
32
33 # Test if Jabber exists
34 test -f ${JABBERD} -a -f ${CONF} || exit 0
35
36 # Source function library.
37 . /etc/rc.d/init.d/functions
38
39 # Get config.
40 . /etc/sysconfig/network
41
42 # Check that networking is up.
43 [ "${NETWORKING}" = "no" ] && exit 0
44
45 # Current user
46 CRT_USER=`whoami`
47
48 ### Stop Jabber server
49 stop_jab() {
50         echo "Stopping ICQ transport - external component ..."
51         killproc ${JICQEXT}
52         # echo
53         echo "Stopping Jabber server ..."
54         killproc ${JABBERD}
55         RETVAL=$? 
56         # echo
57         # kill `cat ${JPID}`
58         # echo " OK."
59 }
60
61 ### Start Jabber server
62 start_jab() {
63         if [ -f ${JPID} ]
64         then
65                 echo "Cleaning Jabber from a previous dirty crash ..."
66                 stop_jab
67                 sleep 1
68                 rm -f ${JPID}
69         fi
70
71         if [ `id -u` = 0 ]
72         then
73                 #### Run by root
74                 echo "Starting Jabber server ..."
75                 su - ${JUSR} -c "cd ${JDIR}; ${JABBERD} -B -c ${CONF} > /dev/null 2>&1"  > /dev/null 2>&1
76                 # echo
77                 sleep 2
78                 echo "Starting ICQ transport - external component ..."
79                 su - ${JUSR} -c "cd ${JDIR}; ${JICQEXT} > /dev/null 2>&1 &" > /dev/null 2>&1
80                 RETVAL=$? 
81                 # echo
82         else
83                 ### Run by other users
84                 echo "Starting Jabber server ..."
85                 cd ${JDIR}
86                 ${JABBERD} -B -c ${CONF} > /dev/null 2>&1
87                 # echo
88                 sleep 2
89                 echo "Starting ICQ transport - external component ..."
90                 ${JICQEXT} > /dev/null 2>&1 &
91                 RETVAL=$?
92                 # echo
93         fi
94         
95         sleep 1
96         ### Checking if processes are started
97         if [ `ps auxw | grep ${JABBERD} | head --lines=1 | awk '{print $11}'` = ${JABBERD} ]
98         then
99                 echo "Jabber server:           [[   STARTED   ]]"
100         else
101                 echo "Jabber server:           [[ NOT STARTED ]]"
102         fi
103         if [ `ps auxw | grep ${JICQEXT} | head --lines=1 | awk '{print $11}'` != "grep" ]
104         then
105                 echo "ICQ transport:           [[   STARTED   ]]"
106         else
107                 echo "ICQ transport:           [[ NOT STARTED ]]"
108         fi
109 }
110
111 ### Stop SER
112 stop_ser() {
113         echo -n "Stopping SIP router ..."
114         killproc ${BIN}
115         RETVAL=$?
116         echo
117         # killall ser
118         # echo " [ OK ]"
119 }
120
121 ### Start SER
122 start_ser() {
123         echo "Starting SIP router ..."
124         if [ `id -u` = 0 ]
125         then
126                 #### Run by root
127                 echo "- ${USR} -c cd ${MYDIR}; ${BINDIR}/${BIN} -f ${ETC} -w ${MYDIR}  > /dev/null 2>&1"
128                 su - ${USR} -c "cd ${MYDIR}; ${BINDIR}/${BIN} -f ${ETC} -w ${MYDIR}"  > /dev/null 2>&1
129                 RETVAL=$?
130         else
131                 #### Run by other users
132                 #cd $MYDIR
133
134                 # core timestamping moved to sercheck; -jiri
135                 #       if [ -f $CORE ] ; then
136                 #               chmod a+r $CORE
137                 #               DATE=`date "+%Y-%m-%d--%H-%M"`
138                 #               mv $CORE $CORE.$DATE
139                 #               ( cd ../sip_router; tar cf - . ) | gzip > ser.$DATE.tgz
140                 #       fi
141
142                 cd ${MYDIR}
143                 ${BINDIR}/${BIN} -f ${ETC} -w ${MYDIR}
144                 RETVAL=$?
145
146                 # man setuid: If uid is different from the old effective uid,
147                 # the process will be forbidden from eaving core dumps.
148                 # -> don't set uid, we want to collect core dumps
149                 # -u $USR -g $GRP
150         fi
151
152         sleep 1
153         ### Checking if processes are started
154         if [ `ps auxw | grep ${BINDIR}/${BIN} | head --lines=1 | awk '{print $11}'` = ${BINDIR}/${BIN} ]
155         then
156                 echo "SIP router:              [[   STARTED   ]]"
157         else
158                 echo "SIP router:              [[ NOT STARTED ]]"
159         fi
160 }
161
162 ### Check
163 check_run() {
164         ### Checking if Jabber server is running
165         if [ `ps auxw | grep ${JABBERD} | head --lines=1 | awk '{print $11}'` = ${JABBERD} ]
166         then
167                 echo "Jabber server:           [[   RUNNING   ]]"
168         else
169                 echo "Jabber server:           [[ NOT RUNNING ]]"
170         fi
171         ### Checking if ICQ transport is running
172         if [ `ps auxw | grep ${JICQEXT} | head --lines=1 | awk '{print $11}'` != "grep" ]
173         then
174                 echo "ICQ transport:           [[   RUNNING   ]]"
175         else
176                 echo "ICQ transport:           [[ NOT RUNNING ]]"
177         fi
178         ### Checking if SIP router is running
179         if [ `ps auxw | grep ${BINDIR}/${BIN} | head --lines=1 | awk '{print $11}'` = ${BINDIR}/${BIN} ]
180         then
181                 echo "SIP router:              [[   RUNNING   ]]"
182         else
183                 echo "SIP router:              [[ NOT RUNNING ]]"
184         fi
185 }
186
187 ### Cleaning
188 make_clean() {
189     sleep 2
190     echo "Cleaning Jabber core if generated on killing ..."
191     rm -f ${JDIR}/core.*
192 }
193             
194 case "$1" in
195         start)
196                 start_jab
197                 start_ser
198         ;;
199         stop)
200                 stop_ser
201                 stop_jab
202                 sleep 2
203                 make_clean
204         ;;
205         restart)
206                 echo "Restarting SIP2Jabber ..."
207                 stop_ser
208                 stop_jab
209                 sleep 2
210                 echo
211                 start_jab
212                 start_ser
213                 make_clean
214         ;;
215         check)
216                 check_run
217         ;;
218         *)
219                 N=$0
220                 echo "Usage: $N {start|stop|restart|check}" >&2
221                 exit 1
222         ;;
223 esac
224 echo
225 exit $RETVAL