Jump to content

LSB compliant init script


Pavlos Parissis

Recommended Posts

Hi all,

 

I created a LSB compliant init script for pbx because the available init scripts aren't.

 

The attached script passes the test mentioned here and implements the correct return status mentioned here.

 

It has been tested on CentOS 5.4.

 

If you are planning to but it under Cluster control pay attention to one of the comments.

 

Have fun with it

 

#!/bin/bash
#
### BEGIN INIT INFO
# Provides: pbx_01
# Required-Start: $local_fs $network 
# Required-Stop: $local_fs $network 
# Default-Start:   3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop pbx_01
# Description: Init script fro pbxnsip.
### END INIT INFO

# source function library
. /etc/init.d/functions

RETVAL=0

# Installation location
INSTALLDIR=/pbx_service_01/pbxnsip
PBX_CONFIG=$INSTALLDIR/pbx.xml
PBX=pbx_01
PID_FILE=/var/run/$PBX.pid
LOCK_FILE=/var/lock/subsys/$PBX
PBX_OPTIONS="--dir $INSTALLDIR --config $PBX_CONFIG --pidfile $PID_FILE"


# Disable the below when pbx is under pacemaker Cluster resource manager
# Pacemaker doesn't like exit 5
[ -x $INSTALLDIR/$PBX ] || exit 5

start()
{
       echo -n "Starting PBX: "
       daemon --pidfile $PID_FILE $INSTALLDIR/$PBX $PBX_OPTIONS
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && touch $LOCK_FILE
       return $RETVAL  

}
stop()
{
       echo -n "Stopping PBX: "
       killproc -p $PID_FILE $PBX 
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
       return $RETVAL
}

case "$1" in
       start)
               start
               ;;
       stop)
               stop
               ;;
       restart)
               stop
               start
               ;;
       force-reload)
               stop
               start
               ;;
       status)
               status -p $PID_FILE $PBX
               RETVAL=$?
               ;;
       *)
               echo $"Usage: $0 {start|stop|restart|force-reload|status}"
               exit 2
esac
exit $RETVA

Link to comment
Share on other sites

  • 4 years later...

The above script is nice indeed and we use it for many years. Here it is again, properly formatted and with a spell correction for anyone that maybe interested.

#!/bin/bash
#
### BEGIN INIT INFO
# Provides: pbx
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start:   3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop pbx
# Description: Init script for pbxnsip.
### END INIT INFO

# source function library
. /etc/init.d/functions

RETVAL=0

# Installation location
INSTALLDIR=/opt/pbxnsip/pbx
PBX=pbxctrl
PID_FILE=/var/run/$PBX.pid
LOCK_FILE=/var/lock/subsys/$PBX
PBX_OPTIONS="--dir $INSTALLDIR --pidfile $PID_FILE"


[ -x $INSTALLDIR/$PBX ] || exit 5

start()
{
        echo -n "Starting PBX: "
        daemon --pidfile $PID_FILE $INSTALLDIR/$PBX $PBX_OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $LOCK_FILE
        return $RETVAL
}
stop()
{
        echo -n "Stopping PBX: "
        killproc -p $PID_FILE $PBX
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        force-reload)
                stop
                start
                ;;
        status)
		#/bin/netstat -anp|grep pbxctrl|grep LISTEN|grep -v ':::'
                status -p $PID_FILE $PBX
                RETVAL=$?
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart|force-reload|status}"
                exit 2
esac
exit $RETVAL

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...