Re: [PATCH] Add start- stop- box/smsc, store-status functionality to debian init script

spameden <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <CAHCALez9Sc+UrViqF2y=JZMw9JZfL8DcvKO_E17YOrr5H-kC+A@mail.gmail.com>
2013/3/12 Alexander Malysh <[email protected]>:
> Hi,
>
> patch not tested but the idea is good and I'm +1 to commit it.
>
> Any objections?
>
> Alex
>
> Am 12.03.2013 um 00:09 schrieb Konstantin Vayner <[email protected]>:
>
>> This adds some new features to debian init script:
>>
>> 1. Allow start/stop separate boxes via /etc/init.d/kannel {start|stop}-box boxname

Nice idea, but needs better handling, I've looked into the patch it
seems does not support multiple configuration files (for example for
starting multiple smsbox'es or sqlbox'es, e.g.
/etc/kannel/sqlbox1.conf /etc/kannel/sqlbox2.conf, etc)

>> 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&param2=value")

Would be nice to require/chacking of lynx installation before giving
any of the opportunity to execute those commands.

>>
>> 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)

The main problem with current init.d script it's not always working.

If there was a big queue on the restart bearerbox takes some time to
populate the memory with it, thus

sleep 1 is not enough anymore.

I'm using this solution on the start:

PORTCONF=$(grep '^smsbox-port' ${CONF}|awk {'print $3'})
while [ -z "$(netstat -nl|grep ":${PORTCONF}.*LISTEN")" ]; do sleep 1; done

and on stop:

while [ ! -z "$(netstat -nl|grep ":${PORTCONF}.*LISTEN")" ]; do sleep 1; done


My version also handles multiple sqlbox.conf files depending on the
values in the /etc/default/kannel file for debian.

So if you don't want to start specific service (e.g. OpenSMPPBox, you
just change value from 1 to 0 for START_SMPPBOX in the
/etc/default/kannel).

I've attached my init.d script and default file for understanding.
>>
>> Attached.
>>
>> Regards,
>>    Konstantin
>> <debian_kannel_init.patch>
>
>
kannel.init.d.debian.sh (application/x-sh, 5.7 KB)
#!/bin/sh
# Start/stop the Kannel boxes: One bearer box and one WAP box.

# This is the default init.d script for Kannel.  Its configuration is
# appropriate for a small site running Kannel on one machine.

# Make sure that the Kannel binaries can be found in $BOXPATH or somewhere
# else along $PATH.  run_kannel_box has to be in $BOXPATH.

### BEGIN INIT INFO
# Provides:          kannel
# Required-Start:    $local_fs $remote_fs 
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      $network $named mysql
# Should-Stop:       $network $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SMS and WAP gateway
# Description:       Kannel is a gateway for connecting WAP phones to the
#                    Internet. It also works as an SMS gateway.
### END INIT INFO

. /lib/lsb/init-functions

# Make sure that the Kannel binaries can be found in $BOXPATH or somewhere
# else along $PATH.  run_kannel_box has to be in $BOXPATH.

BOXPATH=/usr/sbin
PIDFILES=/var/run/kannel
CONFDIR=/etc/kannel
CONF=$CONFDIR/kannel.conf
PORTCONF=$(grep '^smsbox-port' ${CONF}|awk {'print $3'})
SQLCONF=$CONFDIR/sqlbox
SMSBOXCONF=$CONFDIR/smsbox.conf
SMPPBOXCONF=$CONFDIR/opensmppbox.conf
#from 0 to 4
DEBUGLVL=0

PATH=$BOXPATH:$PATH:/sbin

# On Debian, the most likely reason for the bearerbox not being available
# is that the package is in the "removed" or "unconfigured" state, and the
# init.d script is still around because it's a conffile.  This is normal,
# so don't generate any output.
test -x $BOXPATH/bearerbox || exit 0
test -r /etc/default/kannel && . /etc/default/kannel
test -x $PIDFILES || mkdir $PIDFILES && chown kannel:root $PIDFILES

case "$1" in
  start)
    echo -n "Starting SMS/WAP gateway:"
    echo -n " bearerbox"
    start-stop-daemon --start --quiet \
        --pidfile $PIDFILES/bearerbox.pid \
        --chuid kannel \
        --exec $BOXPATH/run_kannel_box \
        -- \
        --pidfile $PIDFILES/bearerbox.pid \
        --no-extra-args \
        $BOXPATH/bearerbox -v $DEBUGLVL -- $CONF
		
    #Wait till bearerbox is up
    while [ -z "$(netstat -nl|grep ":${PORTCONF}.*LISTEN")" ]; do sleep 1; done

    test "x$START_WAPBOX" = "x1" && (
       echo -n " wapbox"
       start-stop-daemon --start --quiet \
           --pidfile $PIDFILES/wapbox.pid \
           --chuid kannel \
           --exec $BOXPATH/run_kannel_box \
           -- \
           --pidfile $PIDFILES/wapbox.pid \
           --no-extra-args \
           $BOXPATH/wapbox -v $DEBUGLVL -- $CONF
    )
    test "x$START_SQLBOX" = "x1" && (
        for i in $SQLBOX; 
        do
             echo -n " sqlbox_$i"
             start-stop-daemon --start --quiet \
                  --pidfile $PIDFILES/sqlbox_$i.pid \
                  --chuid kannel \
                  --exec $BOXPATH/run_kannel_box \
                  -- \
                  --pidfile $PIDFILES/sqlbox_$i.pid \
                  --no-extra-args \
                  $BOXPATH/sqlbox -v $DEBUGLVL -- ${SQLCONF}_${i}.conf
        done
    )
              
    test "x$START_SMSBOX" = "x1" && (
        echo -n " smsbox"
	start-stop-daemon --start --quiet \
           --pidfile $PIDFILES/smsbox.pid \
           --chuid kannel \
           --exec $BOXPATH/run_kannel_box \
           -- \
           --pidfile $PIDFILES/smsbox.pid \
           --no-extra-args \
           $BOXPATH/smsbox -v $DEBUGLVL -- $SMSBOXCONF
    )
    test "x$START_SMPPBOX" = "x1" && (
        echo -n " opensmppbox"
        start-stop-daemon --start --quiet \
           --pidfile $PIDFILES/smppbox.pid \
           --chuid kannel \
           --exec $BOXPATH/run_kannel_box \
           -- \
           --pidfile $PIDFILES/smppbox.pid \
           --no-extra-args \
           $BOXPATH/opensmppbox -v $DEBUGLVL -- $SMPPBOXCONF
    )
    echo "."	
    ;;
  stop)
    echo -n "Stopping SMS/WAP gateway:"

    test "x$START_SMPPBOX" = "x1" && (
	echo -n " smppbox"
        start-stop-daemon --stop --retry 5 --quiet \
            --pidfile $PIDFILES/smppbox.pid \
            --exec $BOXPATH/run_kannel_box
    )

    test "x$START_SMSBOX" = "x1" && (
	echo -n " smsbox"
        start-stop-daemon --stop --retry 5 --quiet \
            --pidfile $PIDFILES/smsbox.pid \
            --exec $BOXPATH/run_kannel_box
    )

    test "x$START_SQLBOX" = "x1" && (
        for i in $SQLBOX; 
        do  
             echo -n " sqlbox_$i"
             start-stop-daemon --stop --retry 5 --quiet \
                    --pidfile $PIDFILES/sqlbox_$i.pid \
                    --exec $BOXPATH/run_kannel_box
        done           
        )

    test "x$START_WAPBOX" = "x1" && (
        echo -n " wapbox"
        start-stop-daemon --stop --retry 5 --quiet \
            --pidfile $PIDFILES/wapbox.pid \
            --exec $BOXPATH/run_kannel_box
    )
    echo -n " bearerbox"
    start-stop-daemon --stop --quiet \
        --pidfile $PIDFILES/bearerbox.pid \
        --exec $BOXPATH/run_kannel_box
    #Wait till bearerbox is down
    while [ ! -z "$(netstat -nl|grep ":${PORTCONF}.*LISTEN")" ]; do sleep 1; done
    echo "."
    ;;
  status)
    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
    ;;

  reload)
    # We don't have support for this yet.
    exit 1
    ;;

  restart|force-reload)
    $0 stop
    $0 start
    ;;

  *)
    echo "Usage: $0 {start|stop|status|restart|force-reload}"
    exit 1

esac

exit 0
default.kannel (application/octet-stream, 95 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.