As I posted here before, Ubuntu has moved to Upstart as the main
engine to start daemons. As a result, Kamailio will fail to start on boot time 
because
it starts before MySQL that has already been moved to the new Upstart daemon
starting fashion. I am struggling to get some help from the Ubuntu community
explaining how we can match the previous init script behavior when using
Upstart but I got no success till now. Anyway, I have created an Upstart script
for Kamailio that does most everything that the old script use to do. However,
in this script I am making sure MySQL starts before Kamailio. If you have 
another SQL engine
you must change the script to match your SQL engine by changing the “start on
started” statement on the script. To use it you have to: A – Create a 
kamailio.conf file at “/etc/init/” with the
contents of the kamailio.conf script in attach, that is the new Upstart stile
init script. Please notice that I just adapted the existing script, no news… B 
– Create a symbolic link at /etc/init.d/ pointing to this
kamailio.conf at /etc/init/. C – If you want, you can still have a 
/etc/default/kamailio
file like it used to be and the script will behave like it used to behave when 
using
the default file. Hopefully someone more “influent” at the Ubuntu community
may get some help on how to adapt their “start on started” Upstart stanza to
behave like we need for multiple possible SQL engines. Cheers! Moacir           
                          
# Kamailio Service

description   "Upstart script for Kamailio server"
author        "Kamailio Community"
version       "0.1-beta"

env DAEMON=/sbin/kamailio
env NAME=kamailio
env DESC="Kamailio SIP server"
env HOMEDIR=/var/run/kamailio
env DEFAULTS=/etc/default/kamailio
env CFGFILE=/etc/kamailio/kamailio.cfg
env RUN_KAMAILIO=yes

start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]
start on started mysql

console output
expect daemon

pre-start script

# Load startup default options if available.
if [ -f $DEFAULTS ]; then
  . $DEFAULTS || true
fi

# Do not start kamailio if fork=no is set in the config file
if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFGFILE; then
        echo "Not starting $DESC: fork=no specified in config file."
        echo "Review your config or start Kamailio in debug mode."
        exit 1
fi

# Check if kamailio configuration is valid before starting the server.
set +e
out=$($DAEMON -c 2>&1 > /dev/null)
retcode=$?
set -e
if [ "$retcode" != '0' ]; then
        echo "Not starting $DESC: Config file invalid."
        echo -e "\n$out\n"
        exit 1;
fi

# Create HOMEDIR directory in case it doesn't exist.
# Useful in Ubuntu as /var/run/ content is deleted in shutdown.
if [ ! -d $HOMEDIR ]; then
        mkdir $HOMEDIR
fi

[ -z $USER  ] && USER=$(whoami)
[ -z $GROUP ] && GROUP=$(groups | awk '{print $1}')

# Set the appropiate owner and group
chown ${USER}:${GROUP} $HOMEDIR

# Create a radius sequence file to be used by the radius client if
# radius accounting is enabled. This is needed to avoid any issue
# with the file not being writable if kamailio first starts as user
# root because DUMP_CORE is enabled and creates this file as user
# root and then later it switches back to user kamailio and cannot
# write to the file. If the file exists before kamailio starts, it
# won't change it's ownership and will be writable for both root
# and kamailio, no matter what options are chosen at install time

if [ -n "${RADIUS_SEQ_FILE}" ]; then
        RADIUS_SEQ_FILE=$HOMEDIR/$RADIUS_SEQ_FILE
        touch $RADIUS_SEQ_FILE
        chown ${USER}:${GROUP} $RADIUS_SEQ_FILE
        chmod 660 $RADIUS_SEQ_FILE
fi

if [ "$RUN_KAMAILIO" != "yes" ]; then
        echo "Not starting $DESC, it is not yet configured."
        echo "Edit $DEFAULTS or /etc/init/kamailio.conf first."
        exit 1
fi

# Define Kamailio memory usage
[ -z "$SHM_MEMORY" ] && SHM_MEMORY=64
[ -z "$PKG_MEMORY" ] && PKG_MEMORY=4

# Define user to run Kamailio
# If not defined at defaults, use current user
[ -z "$USER" ]  && USER=kamailio
[ -z "$GROUP" ] && GROUP=kamailio

# Set the environment if set to dump core
if test "$DUMP_CORE" = "yes" ; then
  # set proper ulimit.
  ulimit -c unlimited

  # directory for the core dump files.
  # COREDIR=/tmp/corefiles
  # [ -d $COREDIR ] || mkdir $COREDIR
  # chmod 777 $COREDIR
  # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern
fi

OPTIONS="-f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP"

echo "\nStarting Kamailio as $DAEMON $OPTIONS\n"

end script

exec $DAEMON $OPTIONS
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to