|
@@ -6,197 +6,242 @@
|
|
# Required-Stop: $syslog $network $local_fs
|
|
# Required-Stop: $syslog $network $local_fs
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Default-Stop: 0 1 6
|
|
|
|
+# Should-Start: postgresql mysql radius
|
|
|
|
+# Should-Stop: postgresql mysql radius
|
|
# Short-Description: Start the Kamailio SIP proxy server
|
|
# Short-Description: Start the Kamailio SIP proxy server
|
|
# Description: Start the Kamailio SIP proxy server
|
|
# Description: Start the Kamailio SIP proxy server
|
|
### END INIT INFO
|
|
### END INIT INFO
|
|
-#
|
|
|
|
-# TODO:
|
|
|
|
-# The following fields should be added (and completed):
|
|
|
|
-# Should-Start: postgresql mysql radius
|
|
|
|
-# Should-Stop: postgresql mysql radius
|
|
|
|
|
|
+
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
DAEMON=/usr/sbin/kamailio
|
|
DAEMON=/usr/sbin/kamailio
|
|
NAME=kamailio
|
|
NAME=kamailio
|
|
-DESC=kamailio
|
|
|
|
|
|
+DESC=Kamailio
|
|
HOMEDIR=/var/run/kamailio
|
|
HOMEDIR=/var/run/kamailio
|
|
PIDFILE=$HOMEDIR/$NAME.pid
|
|
PIDFILE=$HOMEDIR/$NAME.pid
|
|
DEFAULTS=/etc/default/kamailio
|
|
DEFAULTS=/etc/default/kamailio
|
|
CFGFILE=/etc/kamailio/kamailio.cfg
|
|
CFGFILE=/etc/kamailio/kamailio.cfg
|
|
RUN_KAMAILIO=no
|
|
RUN_KAMAILIO=no
|
|
|
|
|
|
|
|
+
|
|
# Do not start kamailio if fork=no is set in the config file
|
|
# Do not start kamailio if fork=no is set in the config file
|
|
-# otherwise the boot process will just stop
|
|
|
|
|
|
+# otherwise the boot process will just stop.
|
|
check_fork ()
|
|
check_fork ()
|
|
{
|
|
{
|
|
- if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFGFILE; then
|
|
|
|
- echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/kamailio debug instead"
|
|
|
|
- exit 1
|
|
|
|
- fi
|
|
|
|
|
|
+ if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFGFILE; then
|
|
|
|
+ echo "Not starting $DESC: fork=no specified in config file. Run /etc/init.d/kamailio debug instead."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
check_kamailio_config ()
|
|
check_kamailio_config ()
|
|
{
|
|
{
|
|
- # 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: invalid configuration file!"
|
|
|
|
- echo -e "\n$out\n"
|
|
|
|
- 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: invalid configuration file!"
|
|
|
|
+ echo -e "\n$out\n"
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
check_homedir ()
|
|
check_homedir ()
|
|
{
|
|
{
|
|
- # Create HOMEDIR directory in case it doesn't exist
|
|
|
|
- if [ ! -d $HOMEDIR ]; then
|
|
|
|
- mkdir $HOMEDIR
|
|
|
|
- fi
|
|
|
|
-
|
|
|
|
- # Set the appropiate owner and group
|
|
|
|
- chown ${USER}:${GROUP} $HOMEDIR
|
|
|
|
|
|
+ # 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
|
|
|
|
+
|
|
|
|
+ # Set the appropiate owner and group
|
|
|
|
+ chown ${USER}:${GROUP} $HOMEDIR
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
create_radius_seqfile ()
|
|
create_radius_seqfile ()
|
|
{
|
|
{
|
|
- # 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
|
|
|
|
- RADIUS_SEQ_FILE=$HOMEDIR/kamailio_radius.seq
|
|
|
|
-
|
|
|
|
- if [ ! -f $RADIUS_SEQ_FILE ]; then
|
|
|
|
- touch $RADIUS_SEQ_FILE
|
|
|
|
- fi
|
|
|
|
-
|
|
|
|
- chown ${USER}:${GROUP} $RADIUS_SEQ_FILE
|
|
|
|
- chmod 660 $RADIUS_SEQ_FILE
|
|
|
|
|
|
+ # 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
|
|
|
|
+ RADIUS_SEQ_FILE=$HOMEDIR/kamailio_radius.seq
|
|
|
|
+
|
|
|
|
+ if [ ! -f $RADIUS_SEQ_FILE ]; then
|
|
|
|
+ touch $RADIUS_SEQ_FILE
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ chown ${USER}:${GROUP} $RADIUS_SEQ_FILE
|
|
|
|
+ chmod 660 $RADIUS_SEQ_FILE
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
if [ ! -f $DAEMON ]; then
|
|
if [ ! -f $DAEMON ]; then
|
|
- echo "No Kamailio daemon at: $DAEMON"
|
|
|
|
- exit 0
|
|
|
|
|
|
+ echo "No $DESC daemon at $DAEMON."
|
|
|
|
+ case "$1" in
|
|
|
|
+ status)
|
|
|
|
+ # LSB - 4: program or service status is unknown.
|
|
|
|
+ exit 4
|
|
|
|
+ ;;
|
|
|
|
+ *)
|
|
|
|
+ # LSB - 5: program is not installed.
|
|
|
|
+ exit 5
|
|
|
|
+ ;;
|
|
|
|
+ esac
|
|
fi
|
|
fi
|
|
|
|
|
|
-# Load startup options if available
|
|
|
|
|
|
+
|
|
|
|
+# Load startup options if available.
|
|
if [ -f $DEFAULTS ]; then
|
|
if [ -f $DEFAULTS ]; then
|
|
- . $DEFAULTS || true
|
|
|
|
|
|
+ . $DEFAULTS || true
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
+
|
|
if [ "$RUN_KAMAILIO" != "yes" ]; then
|
|
if [ "$RUN_KAMAILIO" != "yes" ]; then
|
|
- echo "Kamailio not yet configured. Edit /etc/default/kamailio first."
|
|
|
|
- case "$1" in
|
|
|
|
- status)
|
|
|
|
- # 4 program or service status is unknown
|
|
|
|
- exit 4
|
|
|
|
- ;;
|
|
|
|
- *)
|
|
|
|
- # 6 program is not configured
|
|
|
|
- exit 6
|
|
|
|
- ;;
|
|
|
|
- esac
|
|
|
|
|
|
+ echo "$DESC not yet configured. Edit $DEFAULTS first."
|
|
|
|
+ case "$1" in
|
|
|
|
+ status)
|
|
|
|
+ # LSB - 4: program or service status is unknown.
|
|
|
|
+ exit 4
|
|
|
|
+ ;;
|
|
|
|
+ *)
|
|
|
|
+ # LSB - 6: program is not configured.
|
|
|
|
+ exit 6
|
|
|
|
+ ;;
|
|
|
|
+ esac
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
+
|
|
set -e
|
|
set -e
|
|
|
|
|
|
|
|
+
|
|
MEMORY=$((`echo $MEMORY | sed -e 's/[^0-9]//g'`))
|
|
MEMORY=$((`echo $MEMORY | sed -e 's/[^0-9]//g'`))
|
|
[ -z "$USER" ] && USER=kamailio
|
|
[ -z "$USER" ] && USER=kamailio
|
|
[ -z "$GROUP" ] && GROUP=kamailio
|
|
[ -z "$GROUP" ] && GROUP=kamailio
|
|
[ $MEMORY -le 0 ] && MEMORY=32
|
|
[ $MEMORY -le 0 ] && MEMORY=32
|
|
|
|
|
|
|
|
+
|
|
if test "$DUMP_CORE" = "yes" ; then
|
|
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
|
|
|
|
|
|
+ # 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
|
|
fi
|
|
|
|
|
|
|
|
+
|
|
if [ "$SSD_SUID" != "yes" ]; then
|
|
if [ "$SSD_SUID" != "yes" ]; then
|
|
- OPTIONS="-f $CFGFILE -P $PIDFILE -m $MEMORY -u $USER -g $GROUP"
|
|
|
|
- SSDOPTS=""
|
|
|
|
|
|
+ OPTIONS="-f $CFGFILE -P $PIDFILE -m $MEMORY -u $USER -g $GROUP"
|
|
|
|
+ SSDOPTS=""
|
|
else
|
|
else
|
|
- OPTIONS="-f $CFGFILE -P $PIDFILE -m $MEMORY"
|
|
|
|
- SSDOPTS="--chuid $USER:$GROUP"
|
|
|
|
|
|
+ OPTIONS="-f $CFGFILE -P $PIDFILE -m $MEMORY"
|
|
|
|
+ SSDOPTS="--chuid $USER:$GROUP"
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
+
|
|
start_kamailio_daemon ()
|
|
start_kamailio_daemon ()
|
|
{
|
|
{
|
|
- start-stop-daemon --start --quiet --pidfile $PIDFILE $SSDOPTS \
|
|
|
|
- --exec $DAEMON -- $OPTIONS || if [ ! -r "$PIDFILE" ]; then
|
|
|
|
- echo " error, failed to start."
|
|
|
|
- exit 1
|
|
|
|
- elif read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
|
|
|
|
- echo -n " already running"
|
|
|
|
- echo "."
|
|
|
|
- else
|
|
|
|
- echo " error, failed to start ($PIDFILE exists)."
|
|
|
|
- exit 1
|
|
|
|
- fi
|
|
|
|
|
|
+ start-stop-daemon --start --quiet --pidfile $PIDFILE $SSDOPTS \
|
|
|
|
+ --exec $DAEMON -- $OPTIONS
|
|
|
|
+ res=$?
|
|
|
|
+
|
|
|
|
+ echo -n "$NAME "
|
|
|
|
+ if [ $res -eq 0 ] ; then
|
|
|
|
+ echo "started."
|
|
|
|
+ exit 0
|
|
|
|
+ else
|
|
|
|
+ if [ ! -r "$PIDFILE" ]; then
|
|
|
|
+ echo "error, failed to start."
|
|
|
|
+ exit 1
|
|
|
|
+ elif read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
|
|
|
|
+ echo "already running."
|
|
|
|
+ exit 0
|
|
|
|
+ else
|
|
|
|
+ echo "error, failed to start ($PIDFILE exists)."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+ fi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
case "$1" in
|
|
case "$1" in
|
|
start|debug)
|
|
start|debug)
|
|
- check_kamailio_config
|
|
|
|
- check_homedir
|
|
|
|
- create_radius_seqfile
|
|
|
|
-
|
|
|
|
- if [ "$1" != "debug" ]; then
|
|
|
|
- check_fork
|
|
|
|
- fi
|
|
|
|
-
|
|
|
|
- echo -n "Starting $DESC: $NAME "
|
|
|
|
- start_kamailio_daemon
|
|
|
|
- echo "."
|
|
|
|
- ;;
|
|
|
|
|
|
+ check_kamailio_config
|
|
|
|
+ check_homedir
|
|
|
|
+ create_radius_seqfile
|
|
|
|
+
|
|
|
|
+ if [ "$1" != "debug" ]; then
|
|
|
|
+ check_fork
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ echo "Starting $DESC:"
|
|
|
|
+ set +e
|
|
|
|
+ start_kamailio_daemon
|
|
|
|
+ ;;
|
|
|
|
+
|
|
stop)
|
|
stop)
|
|
- echo -n "Stopping $DESC: $NAME "
|
|
|
|
- start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \
|
|
|
|
- --exec $DAEMON
|
|
|
|
- echo "."
|
|
|
|
- ;;
|
|
|
|
|
|
+ echo -n "Stopping $DESC: $NAME "
|
|
|
|
+ set +e
|
|
|
|
+ start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \
|
|
|
|
+ --exec $DAEMON
|
|
|
|
+
|
|
|
|
+ if [ $? -eq 0 ] ; then
|
|
|
|
+ echo "stopped."
|
|
|
|
+ exit 0
|
|
|
|
+ else
|
|
|
|
+ echo "failed to stop."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+ ;;
|
|
|
|
+
|
|
restart|force-reload)
|
|
restart|force-reload)
|
|
- check_kamailio_config
|
|
|
|
- check_homedir
|
|
|
|
- create_radius_seqfile
|
|
|
|
-
|
|
|
|
- echo -n "Restarting $DESC: $NAME "
|
|
|
|
- start-stop-daemon --oknodo --stop --quiet --pidfile \
|
|
|
|
- $PIDFILE --exec $DAEMON
|
|
|
|
- sleep 1
|
|
|
|
- start_kamailio_daemon
|
|
|
|
- echo "."
|
|
|
|
- ;;
|
|
|
|
|
|
+ check_kamailio_config
|
|
|
|
+ check_homedir
|
|
|
|
+ create_radius_seqfile
|
|
|
|
+
|
|
|
|
+ echo "Restarting $DESC:"
|
|
|
|
+ set +e
|
|
|
|
+ start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE --retry=5 \
|
|
|
|
+ $PIDFILE --exec $DAEMON
|
|
|
|
+ if [ $? -ne 0 ] ; then
|
|
|
|
+ echo "$NAME failed to stop."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+ start_kamailio_daemon
|
|
|
|
+ ;;
|
|
|
|
+
|
|
status)
|
|
status)
|
|
- echo -n "Status of $DESC: "
|
|
|
|
- if [ ! -r "$PIDFILE" ]; then
|
|
|
|
- echo "$NAME is not running."
|
|
|
|
- exit 3
|
|
|
|
- fi
|
|
|
|
- if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
|
|
|
|
- echo "$NAME is running."
|
|
|
|
- exit 0
|
|
|
|
- else
|
|
|
|
- echo "$NAME is not running but $PIDFILE exists."
|
|
|
|
- exit 1
|
|
|
|
- fi
|
|
|
|
- ;;
|
|
|
|
|
|
+ echo -n "Status of $DESC: $NAME "
|
|
|
|
+ if [ ! -r "$PIDFILE" ]; then
|
|
|
|
+ echo "is not running."
|
|
|
|
+ exit 3
|
|
|
|
+ fi
|
|
|
|
+ if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
|
|
|
|
+ echo "is running."
|
|
|
|
+ exit 0
|
|
|
|
+ else
|
|
|
|
+ echo "is not running but $PIDFILE exists."
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
|
|
+ ;;
|
|
|
|
+
|
|
*)
|
|
*)
|
|
- N=/etc/init.d/$NAME
|
|
|
|
- echo "Usage: $N {start|stop|restart|force-reload|debug|status}" >&2
|
|
|
|
- exit 1
|
|
|
|
- ;;
|
|
|
|
|
|
+ N=/etc/init.d/$NAME
|
|
|
|
+ echo "Usage: $N {start|stop|restart|force-reload|debug|status}" >&2
|
|
|
|
+ exit 1
|
|
|
|
+ ;;
|
|
esac
|
|
esac
|
|
|
|
|
|
|
|
+
|
|
exit 0
|
|
exit 0
|