[PATCH] Add start- stop- box/smsc, store-status functionality to debian init script
Konstantin Vayner <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <CAFvzOVxvAvCfyTPpq93=bLupxV64U15XqRMQDmG4gNc-PMTdiQ@mail.gmail.com> |
This adds some new features to debian init script:
1. Allow start/stop separate boxes via /etc/init.d/kannel {start|stop}-box
boxname
2. Allow start/stop smsc by /etc/init.d/kannel {start|stop}-smsc smsc-id
3. Allow querying store status via /etc/init.d/kannel store-status
4. Actually, it also allows arbitrary http admin commands via
/etc/init.d/kannel http-admin command params , where params should be a
single-argument string, prepared to be passed via url (in form
"param1=value¶m2=value")
NB: startup/shutdown output format changed to multiple lines of output here
(because it uses start-box / stop-box internally, and each call like that
outputs a line)
Attached.
Regards,
Konstantin
debian_kannel_init.patch
(application/octet-stream, 4.8 KB)
Index: debian/kannel.init
===================================================================
--- debian/kannel.init (revision 5030)
+++ debian/kannel.init (working copy)
@@ -24,62 +24,120 @@
case "$1" in
start)
- echo -n "Starting WAP gateway:"
- echo -n " bearerbox"
- start-stop-daemon --start --quiet \
- --pidfile $PIDFILES/kannel_bearerbox.pid \
- --chuid kannel \
- --exec $BOXPATH/bearerbox -- -v 4 --parachute --daemonize \
- --pid-file $PIDFILES/kannel_bearerbox.pid $CONF
+ echo "Starting Kannel gateway..."
+ $0 start-bearerbox
sleep 1 # Wait for bearerbox
- test ! -z $START_WAPBOX && (
- echo -n " wapbox"
- start-stop-daemon --start --quiet \
- --pidfile $PIDFILES/kannel_wapbox.pid \
- --chuid kannel \
- --exec $BOXPATH/wapbox -- -v 4 --parachute --daemonize \
- --pid-file $PIDFILES/kannel_wapbox.pid $CONF
- )
- test ! -z $START_SMSBOX && (
- echo -n " smsbox"
- start-stop-daemon --start --quiet \
- --pidfile $PIDFILES/kannel_smsbox.pid \
- --chuid kannel \
- --exec $BOXPATH/smsbox -- -v 4 --parachute --daemonize \
- --pid-file $PIDFILES/kannel_smsbox.pid $CONF
- )
- echo "."
+ test ! -z $START_SMSBOX && $0 start-smsbox
+ test ! -z $START_WAPBOX && $0 wapbox
+ echo "DONE."
;;
stop)
- echo -n "Stopping WAP gateway:"
- test ! -z $START_SMSBOX && (
- echo -n " smsbox"
- start-stop-daemon --stop --retry 5 --quiet \
- --pidfile $PIDFILES/kannel_smsbox.pid \
- --name smsbox
- )
- test ! -z $START_WAPBOX && (
- echo -n " wapbox"
- start-stop-daemon --stop --retry 5 --quiet \
- --pidfile $PIDFILES/kannel_wapbox.pid \
- --name wapbox
- )
- echo -n " bearerbox"
- start-stop-daemon --stop --retry 5 --quiet \
- --pidfile $PIDFILES/kannel_bearerbox.pid \
- --name bearerbox
- echo "."
+ echo "Starting Kannel gateway..."
+ test ! -z $START_WAPBOX && $0 stop-wapbox
+ test ! -z $START_SMSBOX && $0 stop-smsbox
+ $0 stop-bearerbox
+ echo "DONE."
;;
- status)
+ start-box)
+ BOX=$2
+ test -z $BOX && {
+ echo "You must specify box name"
+ exit 1
+ }
+ test ! -x $BOXPATH/$BOX && {
+ echo "Bad box: $BOX"
+ exit 1
+ }
+ echo -n "Starting $BOX: "
+ start-stop-daemon --start --quiet \
+ --pidfile $PIDFILES/kannel_$BOX.pid \
+ --chuid kannel \
+ --exec $BOXPATH/$BOX -- -v 4 --parachute --daemonize \
+ --pid-file $PIDFILES/kannel_$BOX.pid $CONF
+ echo "done."
+ ;;
+
+ stop-box)
+ BOX=$2
+ test -z $BOX && {
+ echo "You must specify box name"
+ exit 1
+ }
+ test ! -x $BOXPATH/$BOX && {
+ echo "Bad box: $BOX"
+ exit 1
+ }
+ echo -n "Stopping $BOX: "
+ start-stop-daemon --stop --retry 5 --quiet \
+ --pidfile $PIDFILES/kannel_$BOX.pid \
+ --name $BOX
+ echo "done."
+ ;;
+
+ restart-box)
+ $0 stop-box $2
+ sleep 1
+ $0 start-box $2
+ ;;
+
+ start-bearerbox)
+ $0 start-box bearerbox
+ ;;
+
+ start-smsbox)
+ $0 start-box smsbox
+ ;;
+
+ start-wapbox)
+ $0 start-box wapbox
+ ;;
+
+ stop-bearerbox)
+ $0 stop-box bearerbox
+ ;;
+
+ stop-smsbox)
+ $0 stop-box smsbox
+ ;;
+
+ stop-wapbox)
+ $0 stop-box wapbox
+ ;;
+
+ http-admin)
+ CMD=$2
+ PARAMS=$3
+ test -z $CMD && {
+ echo "Command required"
+ exit 1
+ }
CORE_CONF=$(grep -r 'group[[:space:]]*=[[:space:]]*core' $CONFDIR | cut -d: -f1)
ADMIN_PORT=$(grep '^admin-port' $CORE_CONF | sed "s/.*=[[:space:]]*//")
ADMIN_PASS=$(grep '^admin-password' $CORE_CONF | sed "s/.*=[[:space:]]*//")
- STATUS_URL="http://127.0.0.1:${ADMIN_PORT}/status.txt?password=${ADMIN_PASS}"
- lynx -source $STATUS_URL
+ ADMIN_URL="http://127.0.0.1:${ADMIN_PORT}/${CMD}.txt?password=${ADMIN_PASS}"
+ test ! -z $PARAMS && ADMIN_URL="${ADMIN_URL}&${PARAM}"
+ lynx -source $ADMIN_URL
+ echo
;;
+ status)
+ $0 http-admin status
+ ;;
+
+ store-status)
+ $0 http-admin store-status
+ ;;
+
+ start-smsc)
+ $0 http-admin start-smsc "smsc=$2"
+ ;;
+
+ stop-smsc)
+ $0 http-admin stop-smsc "smsc=$2"
+ ;;
+
reload)
# We don't have support for this yet.
exit 1
@@ -92,7 +150,7 @@
;;
*)
- echo "Usage: $0 {start|stop|status|restart|force-reload}"
+ echo "Usage: $0 {start|stop|status|restart|force-reload|start-box boxname|stop-box boxname|store-status|start-smsc smsc-id|stop-smsc smsc-id}"
exit 1
esac