# 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