Browse Source

TT#26264 Use better sysvinit scripts

We move the NFS setup into its own init script so that we can manage its
actions independently.

[gjover@sipwise.com: Rework the original systemd commit for sysvinit. ]

Change-Id: I990d6847117a4b91a8365a5e307fd96cf5b1899f
(cherry picked from commit 79807a9c2e)
changes/79/28779/2
Guillem Jover 8 years ago
parent
commit
d453aa24f3
6 changed files with 143 additions and 53 deletions
  1. +2
    -44
      debian/ngcp-rtpengine-daemon.init
  2. +1
    -0
      debian/ngcp-rtpengine-daemon.install
  3. +100
    -0
      debian/ngcp-rtpengine-iptables-setup
  4. +2
    -9
      debian/ngcp-rtpengine-recording-daemon.init
  5. +1
    -0
      debian/ngcp-rtpengine-recording-daemon.install
  6. +37
    -0
      debian/ngcp-rtpengine-recording-nfs-setup

+ 2
- 44
debian/ngcp-rtpengine-daemon.init View File

@ -16,7 +16,6 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=ngcp-rtpengine-daemon
DESC="RTP/media proxy"
TABLE=0
MANAGE_IPTABLES=yes
DAEMON=$(which rtpengine)
DEFAULTS=/etc/default/${NAME}
@ -38,7 +37,6 @@ fi
OPTIONS=""
START_OPTIONS=""
MODPROBE_OPTIONS=""
if [ ! -z "$INTERFACES" ]; then
for interface in $INTERFACES; do
@ -126,30 +124,16 @@ fi
if ! test -z "$SET_USER"; then
START_OPTIONS="$START_OPTIONS --chuid $SET_USER"
PUID=$(id -u "$SET_USER" 2> /dev/null)
test -z "$PUID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_uid=$PUID"
if test -z "$SET_GROUP"; then
PGID=$(id -g "$SET_USER" 2> /dev/null)
test -z "$PGID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$PGID"
fi
test "$DO_DIR_CHOWN" = 1 && chown "$SET_USER": "$PIDDIR"
fi
if ! test -z "$SET_GROUP"; then
START_OPTIONS="$START_OPTIONS --group $SET_GROUP"
PGID=$(grep "^$SET_GROUP:" /etc/group | cut -d: -f3 2> /dev/null)
test -z "$PGID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$PGID"
test "$DO_DIR_CHOWN" = 1 && chgrp "$SET_GROUP" "$PIDDIR"
fi
###
if [ -x /usr/sbin/ngcp-virt-identify ]; then
if /usr/sbin/ngcp-virt-identify --type container; then
VIRT="yes"
fi
fi
case "$1" in
start)
set +e
@ -166,23 +150,7 @@ case "$1" in
;;
esac
fi
if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then
if [ "$MANAGE_IPTABLES" = "yes" ]; then
# shellcheck disable=SC2086
modprobe xt_RTPENGINE $MODPROBE_OPTIONS
iptables -N rtpengine 2> /dev/null
iptables -D INPUT -j rtpengine 2> /dev/null
iptables -I INPUT -j rtpengine
iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
ip6tables -N rtpengine 2> /dev/null
ip6tables -D INPUT -j rtpengine 2> /dev/null
ip6tables -I INPUT -j rtpengine
ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
fi
fi
ngcp-rtpengine-iptables-setup start
set -e
log_daemon_msg "Starting $DESC" "$NAME"
# shellcheck disable=SC2086
@ -198,17 +166,7 @@ case "$1" in
return $?
fi
set +e
if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then
sleep 1
if [ -e /proc/rtpengine/control ]; then
echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null
fi
if [ "$MANAGE_IPTABLES" = "yes" ]; then
iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
rmmod xt_RTPENGINE 2>/dev/null
fi
fi
ngcp-rtpengine-iptables-setup stop
set -e
rm -f $PIDFILE
log_end_msg $?


+ 1
- 0
debian/ngcp-rtpengine-daemon.install View File

@ -1,2 +1,3 @@
daemon/rtpengine /usr/sbin/
debian/ngcp-rtpengine-iptables-setup /usr/sbin
etc/rtpengine.sample.conf /etc/rtpengine/

+ 100
- 0
debian/ngcp-rtpengine-iptables-setup View File

@ -0,0 +1,100 @@
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
TABLE=0
MODNAME=xt_RTPENGINE
MANAGE_IPTABLES=yes
DEFAULTS=/etc/default/ngcp-rtpengine-daemon
# Load startup options if available
if [ -f "$DEFAULTS" ]; then
. "$DEFAULTS" || true
fi
MODPROBE_OPTIONS=""
# Handle requested setuid/setgid.
if ! test -z "$SET_USER"; then
PUID=$(id -u "$SET_USER" 2> /dev/null)
test -z "$PUID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_uid=$PUID"
if test -z "$SET_GROUP"; then
PGID=$(id -g "$SET_USER" 2> /dev/null)
test -z "$PGID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$PGID"
fi
fi
if ! test -z "$SET_GROUP"; then
PGID=$(grep "^$SET_GROUP:" /etc/group | cut -d: -f3 2> /dev/null)
test -z "$PGID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$PGID"
fi
###
if [ -x /usr/sbin/ngcp-virt-identify ]; then
if /usr/sbin/ngcp-virt-identify --type container; then
VIRT="yes"
fi
fi
firewall_setup()
{
if [ "$TABLE" -lt 0 ] || [ "$VIRT" = "yes" ]; then
return
fi
if [ "$MANAGE_IPTABLES" != "yes" ]; then
return
fi
# shellcheck disable=SC2086
modprobe $MODNAME $MODPROBE_OPTIONS
iptables -N rtpengine 2>/dev/null
iptables -D INPUT -j rtpengine 2>/dev/null
iptables -I INPUT -j rtpengine
iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
ip6tables -N rtpengine 2>/dev/null
ip6tables -D INPUT -j rtpengine 2>/dev/null
ip6tables -I INPUT -j rtpengine
ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
}
firewall_teardown()
{
if [ "$TABLE" -lt 0 ] || [ "$VIRT" = "yes" ]; then
return
fi
# XXX: Wait a bit to make sure the daemon has been stopped.
sleep 1
if [ -e /proc/rtpengine/control ]; then
echo "del $TABLE" >/proc/rtpengine/control 2>/dev/null
fi
if [ "$MANAGE_IPTABLES" != "yes" ]; then
return
fi
iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
rmmod $MODNAME 2>/dev/null
}
case "$1" in
start)
firewall_setup
;;
stop)
firewall_teardown
;;
*)
echo "Usage: $0 {start|stop}" >&2
exit 1
;;
esac
exit 0

+ 2
- 9
debian/ngcp-rtpengine-recording-daemon.init View File

@ -34,7 +34,6 @@ if [ "$RUN_RTPENGINE_RECORDING" != "yes" ]; then
exit 0
fi
[ -z "$PIDFILE" ] && PIDFILE="/var/run/rtpengine-recording.pid"
[ -z "$NFS_OPTIONS" ] && NFS_OPTIONS="hard,tcp,intr"
OPTIONS=""
START_OPTIONS=""
@ -91,15 +90,9 @@ case "$1" in
fi
set -e
log_daemon_msg "Starting $DESC" "$NAME"
ngcp-rtpengine-recording-nfs-setup start
if [ "$MUST_NFS" = yes ]; then
if ! grep -E -q "^[^ :]+:[^ :]+ $NFS_LOCAL_MOUNT nfs.? " /proc/mounts; then
log_progress_msg "Mounting NFS share"
test -d "$NFS_LOCAL_MOUNT" || mkdir -p "$NFS_LOCAL_MOUNT"
mount -t nfs -o "$NFS_OPTIONS" "$NFS_HOST:$NFS_REMOTE_PATH" "$NFS_LOCAL_MOUNT"
fi
fi
log_daemon_msg "Starting $DESC" "$NAME"
# shellcheck disable=SC2086
start-stop-daemon --start --quiet --pidfile "$PIDFILE" \


+ 1
- 0
debian/ngcp-rtpengine-recording-daemon.install View File

@ -1 +1,2 @@
recording-daemon/rtpengine-recording /usr/sbin/
debian/ngcp-rtpengine-recording-nfs-setup /usr/sbin/

+ 37
- 0
debian/ngcp-rtpengine-recording-nfs-setup View File

@ -0,0 +1,37 @@
#!/bin/sh
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DEFAULTS=/etc/default/ngcp-rtpengine-recording-daemon
. /lib/lsb/init-functions
# Load startup options if available
if [ -f "$DEFAULTS" ]; then
. "$DEFAULTS" || true
fi
[ -z "$NFS_OPTIONS" ] && NFS_OPTIONS="hard,tcp,intr"
###
case "$1" in
start)
if [ "$MUST_NFS" = yes ]; then
if ! grep -E -q "^[^ :]+:[^ :]+ $NFS_LOCAL_MOUNT nfs.? " /proc/mounts; then
log_action_msg "Mounting NFS share"
test -d "$NFS_LOCAL_MOUNT" || mkdir -p "$NFS_LOCAL_MOUNT"
mount -t nfs -o "$NFS_OPTIONS" "$NFS_HOST:$NFS_REMOTE_PATH" "$NFS_LOCAL_MOUNT"
fi
fi
;;
stop)
;;
*)
echo "Usage: $0 {start|stop}" >&2
exit 1
;;
esac
exit 0

Loading…
Cancel
Save