From fdf507d58bae02abf51940294eb9d4676f86fab4 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 23 Jun 2014 17:14:42 +0200 Subject: [PATCH] MT#6485 sync init.d scripts from templates. --- debian/kamailio-lb.init | 185 ++++++++++++++++++++---------------- debian/kamailio-proxy.init | 187 +++++++++++++++++++++---------------- 2 files changed, 216 insertions(+), 156 deletions(-) diff --git a/debian/kamailio-lb.init b/debian/kamailio-lb.init index e33b289b6..85bbd2539 100644 --- a/debian/kamailio-lb.init +++ b/debian/kamailio-lb.init @@ -2,9 +2,8 @@ ### BEGIN INIT INFO # Provides: kamailio-lb # Required-Start: $syslog $network $local_fs $remote_fs $time -# Should-Start: $named slapd mysql postgresql snmpd radiusd -# Should-Stop: $named slapd mysql postgresql snmpd radiusd # Required-Stop: $syslog $network $local_fs $remote_fs +# Should-Start: sshd # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start the Kamailio SIP proxy server @@ -35,10 +34,8 @@ check_fork () check_kamailio_config () { # Check if kamailio configuration is valid before starting the server - set +e out=$($DAEMON $OPTIONS -c 2>&1 > /dev/null) retcode=$? - set -e if [ "$retcode" != '0' ]; then echo "Not executing command for $DESC: invalid configuration file!" echo -e "\n$out\n" @@ -69,16 +66,13 @@ create_radius_seqfile () # 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 [ -d $HOMEDIR ]; then - chown ${USER}:${GROUP} $HOMEDIR - if [ ! -f $RADIUS_SEQ_FILE ]; then - touch $RADIUS_SEQ_FILE - fi - - chown ${USER}:${GROUP} $RADIUS_SEQ_FILE - chmod 660 $RADIUS_SEQ_FILE + if [ ! -f $RADIUS_SEQ_FILE ]; then + touch $RADIUS_SEQ_FILE fi + + chown ${USER}:${GROUP} $RADIUS_SEQ_FILE + chmod 660 $RADIUS_SEQ_FILE } @@ -109,9 +103,6 @@ if [ "$RUN_KAMAILIO" != "yes" ]; then fi -set -e - - test -z "$SHM_MEMORY" && SHM_MEMORY=64 test -z "$PKG_MEMORY" && PKG_MEMORY=4 SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) @@ -121,18 +112,16 @@ PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) [ -z "$USER" ] && USER=kamailio [ -z "$GROUP" ] && GROUP=kamailio - if test "$DUMP_CORE" = "yes" ; then # set proper ulimit ulimit -c unlimited - - # directory for the core dump files - # COREDIR=/home/corefiles - # [ -d $COREDIR ] || mkdir $COREDIR - # chmod 777 $COREDIR - # echo "$COREDIR/core.$TYPE.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi +# raise memlock limit, otherwise mysql client fails to initialize +ulimit -l unlimited +# raise file descriptors limit, otherwise we get "Can't send +# command to RTP proxy" on massive number of calls with RTP +ulimit -n 16384 if [ "$SSD_SUID" != "yes" ]; then OPTIONS="-f $CFGFILE -P $PIDFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP" @@ -145,6 +134,7 @@ fi start_kamailio_daemon () { + set -e start-stop-daemon --start --quiet --pidfile $PIDFILE $SSDOPTS \ --exec $DAEMON -- $OPTIONS res=$? @@ -170,71 +160,110 @@ start_kamailio_daemon () case "$1" in start|debug) - check_kamailio_config - check_homedir - create_radius_seqfile + if [ -x "/usr/sbin/ngcp-check_active" ]; then + /usr/sbin/ngcp-check_active -q + status=$? + case "${status}" in + 0|3) + echo "Active node or transition." + ;; + *) + echo "Ignored start action in inactive node ($status)" + exit 0 + ;; + esac + fi + check_kamailio_config + check_homedir + create_radius_seqfile - if [ "$1" != "debug" ]; then - check_fork - fi + if [ "$1" != "debug" ]; then + check_fork + fi + + echo "Starting $DESC using $CFGFILE: " + start_kamailio_daemon + ;; - echo "Starting $DESC using $CFGFILE: " - set +e - start_kamailio_daemon - ;; + safe-stop) + check_kamailio_config + echo "Stopping $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ + --exec $DAEMON + echo -n "$NAME " + if [ $? -eq 0 ] ; then + echo "stopped." + exit 0 + else + echo "failed to stop." + exit 1 + fi + ;; stop) - check_kamailio_config - echo "Stopping $DESC:" - start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ - --exec $DAEMON - echo -n "$NAME " - if [ $? -eq 0 ] ; then - echo "stopped." - exit 0 - else - echo "failed to stop." - exit 1 - fi - ;; - - restart|force-reload) - check_kamailio_config - check_homedir - create_radius_seqfile - - echo "Restarting $DESC:" - set +e - start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE --retry=5 \ - --exec $DAEMON - if [ $? -ne 0 ] ; then - echo "$NAME failed to stop." - exit 1 - fi + echo "Stopping $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ + --exec $DAEMON + echo -n "$NAME " + if [ $? -eq 0 ] ; then + echo "stopped." + exit 0 + else + echo "failed to stop." + exit 1 + fi + ;; + + restart|force-reload) + check_kamailio_config + check_homedir + create_radius_seqfile + + echo "Restarting $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE --retry=5 \ + --exec $DAEMON + if [ $? -ne 0 ] ; then + echo "$NAME failed to stop." + exit 1 + fi - start_kamailio_daemon - ;; + if [ -x "/usr/sbin/ngcp-check_active" ]; then + /usr/sbin/ngcp-check_active -q + status=$? + case "${status}" in + 0|3) + echo "Active node or transition." + ;; + *) + echo "Ignored start action in inactive node ($status)" + exit 0 + ;; + esac + fi + + start_kamailio_daemon + ;; status) - 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 - ;; + 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|safe-stop|restart|force-reload|debug|status}" >&2 + exit 1 + ;; esac exit 0 diff --git a/debian/kamailio-proxy.init b/debian/kamailio-proxy.init index e1a7ee5a2..7682f681b 100644 --- a/debian/kamailio-proxy.init +++ b/debian/kamailio-proxy.init @@ -1,10 +1,10 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: kamailio-proxy -# Required-Start: $syslog $network $local_fs $remote_fs $time -# Should-Start: $named slapd mysql postgresql snmpd radiusd -# Should-Stop: $named slapd mysql postgresql snmpd radiusd +# Required-Start: $syslog $network $local_fs $time $remote_fs # Required-Stop: $syslog $network $local_fs $remote_fs +# Should-Start: sshd mysql +# Should-Stop: mysql # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start the Kamailio SIP proxy server @@ -35,10 +35,8 @@ check_fork () check_kamailio_config () { # Check if kamailio configuration is valid before starting the server - set +e out=$($DAEMON $OPTIONS -c 2>&1 > /dev/null) retcode=$? - set -e if [ "$retcode" != '0' ]; then echo "Not executing command for $DESC: invalid configuration file!" echo -e "\n$out\n" @@ -69,16 +67,13 @@ create_radius_seqfile () # 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 [ -d $HOMEDIR ]; then - chown ${USER}:${GROUP} $HOMEDIR - if [ ! -f $RADIUS_SEQ_FILE ]; then - touch $RADIUS_SEQ_FILE - fi - - chown ${USER}:${GROUP} $RADIUS_SEQ_FILE - chmod 660 $RADIUS_SEQ_FILE + if [ ! -f $RADIUS_SEQ_FILE ]; then + touch $RADIUS_SEQ_FILE fi + + chown ${USER}:${GROUP} $RADIUS_SEQ_FILE + chmod 660 $RADIUS_SEQ_FILE } @@ -109,9 +104,6 @@ if [ "$RUN_KAMAILIO" != "yes" ]; then fi -set -e - - test -z "$SHM_MEMORY" && SHM_MEMORY=64 test -z "$PKG_MEMORY" && PKG_MEMORY=4 SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) @@ -125,14 +117,13 @@ PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) if test "$DUMP_CORE" = "yes" ; then # set proper ulimit ulimit -c unlimited - - # directory for the core dump files - # COREDIR=/home/corefiles - # [ -d $COREDIR ] || mkdir $COREDIR - # chmod 777 $COREDIR - # echo "$COREDIR/core.$TYPE.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi +# raise memlock limit, otherwise mysql client fails to initialize +ulimit -l unlimited +# raise file descriptors limit, otherwise we get "Can't send +# command to RTP proxy" on massive number of calls with RTP +ulimit -n 16384 if [ "$SSD_SUID" != "yes" ]; then OPTIONS="-f $CFGFILE -P $PIDFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP" @@ -145,6 +136,7 @@ fi start_kamailio_daemon () { + set -e start-stop-daemon --start --quiet --pidfile $PIDFILE $SSDOPTS \ --exec $DAEMON -- $OPTIONS res=$? @@ -170,71 +162,110 @@ start_kamailio_daemon () case "$1" in start|debug) - check_kamailio_config - check_homedir - create_radius_seqfile + if [ -x "/usr/sbin/ngcp-check_active" ]; then + /usr/sbin/ngcp-check_active -q + status=$? + case "${status}" in + 0|3) + echo "Active node or transition." + ;; + *) + echo "Ignored start action in inactive node ($status)" + exit 0 + ;; + esac + fi + check_kamailio_config + check_homedir + create_radius_seqfile - if [ "$1" != "debug" ]; then - check_fork - fi + if [ "$1" != "debug" ]; then + check_fork + fi - echo "Starting $DESC using $CFGFILE: " - set +e - start_kamailio_daemon - ;; + echo "Starting $DESC using $CFGFILE: " + start_kamailio_daemon + ;; + + safe-stop) + check_kamailio_config + echo "Stopping $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ + --exec $DAEMON + echo -n "$NAME " + if [ $? -eq 0 ] ; then + echo "stopped." + exit 0 + else + echo "failed to stop." + exit 1 + fi + ;; stop) - check_kamailio_config - echo "Stopping $DESC:" - start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ - --exec $DAEMON - echo -n "$NAME " - if [ $? -eq 0 ] ; then - echo "stopped." - exit 0 - else - echo "failed to stop." - exit 1 - fi - ;; - - restart|force-reload) - check_kamailio_config - check_homedir - create_radius_seqfile - - echo "Restarting $DESC:" - set +e - start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE --retry=5 \ - --exec $DAEMON - if [ $? -ne 0 ] ; then - echo "$NAME failed to stop." - exit 1 - fi + echo "Stopping $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ + --exec $DAEMON + echo -n "$NAME " + if [ $? -eq 0 ] ; then + echo "stopped." + exit 0 + else + echo "failed to stop." + exit 1 + fi + ;; + + restart|force-reload) + check_kamailio_config + check_homedir + create_radius_seqfile + + echo "Restarting $DESC:" + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE --retry=5 \ + --exec $DAEMON + if [ $? -ne 0 ] ; then + echo "$NAME failed to stop." + exit 1 + fi - start_kamailio_daemon - ;; + if [ -x "/usr/sbin/ngcp-check_active" ]; then + /usr/sbin/ngcp-check_active -q + status=$? + case "${status}" in + 0|3) + echo "Active node or transition." + ;; + *) + echo "Ignored start action in inactive node ($status)" + exit 0 + ;; + esac + fi + + start_kamailio_daemon + ;; status) - 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 - ;; + 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|safe-stop|restart|force-reload|debug|status}" >&2 + exit 1 + ;; esac exit 0