Browse code

init.d script for starting/stopping IM Gateway

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