Browse Source

TT#26264 Use better systemd native units

While still not the ideal implementation, this is certainly better than
the sysvinit script wrapper. We then will "only" need to move the setup
scripts into proper service files later on.

Change-Id: I990d6847117a4b91a8365a5e307fd96cf5b1899f
(cherry picked from commit aee2a27c3e)
(cherry picked from commit 1b489bd45d)
(cherry picked from commit 79807a9c2e)
changes/82/20582/1
Guillem Jover 8 years ago
parent
commit
9f970337fe
8 changed files with 173 additions and 53 deletions
  1. +2
    -44
      debian/ngcp-rtpengine-daemon.init
  2. +1
    -0
      debian/ngcp-rtpengine-daemon.install
  3. +16
    -0
      debian/ngcp-rtpengine-daemon.service
  4. +100
    -0
      debian/ngcp-rtpengine-iptables-setup
  5. +2
    -9
      debian/ngcp-rtpengine-recording-daemon.init
  6. +1
    -0
      debian/ngcp-rtpengine-recording-daemon.install
  7. +14
    -0
      debian/ngcp-rtpengine-recording-daemon.service
  8. +37
    -0
      debian/ngcp-rtpengine-recording-nfs-setup

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

@ -15,7 +15,6 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=ngcp-rtpengine-daemon NAME=ngcp-rtpengine-daemon
DESC="RTP/media proxy" DESC="RTP/media proxy"
TABLE=0 TABLE=0
MANAGE_IPTABLES=yes
DAEMON=$(which rtpengine) DAEMON=$(which rtpengine)
DEFAULTS=/etc/default/${NAME} DEFAULTS=/etc/default/${NAME}
@ -37,7 +36,6 @@ fi
OPTIONS="" OPTIONS=""
START_OPTIONS="" START_OPTIONS=""
MODPROBE_OPTIONS=""
if [ ! -z "$INTERFACES" ]; then if [ ! -z "$INTERFACES" ]; then
for interface in $INTERFACES; do for interface in $INTERFACES; do
@ -125,30 +123,16 @@ fi
if ! test -z "$SET_USER"; then if ! test -z "$SET_USER"; then
START_OPTIONS="$START_OPTIONS --chuid $SET_USER" 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" test "$DO_DIR_CHOWN" = 1 && chown "$SET_USER": "$PIDDIR"
fi fi
if ! test -z "$SET_GROUP"; then if ! test -z "$SET_GROUP"; then
START_OPTIONS="$START_OPTIONS --group $SET_GROUP" 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" test "$DO_DIR_CHOWN" = 1 && chgrp "$SET_GROUP" "$PIDDIR"
fi 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 case "$1" in
start) start)
set +e set +e
@ -165,23 +149,7 @@ case "$1" in
;; ;;
esac esac
fi 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 set -e
log_daemon_msg "Starting $DESC" "$NAME" log_daemon_msg "Starting $DESC" "$NAME"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -197,17 +165,7 @@ case "$1" in
return $? return $?
fi fi
set +e 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 set -e
rm -f $PIDFILE rm -f $PIDFILE
log_end_msg $? log_end_msg $?


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

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

+ 16
- 0
debian/ngcp-rtpengine-daemon.service View File

@ -0,0 +1,16 @@
[Unit]
Description=NGCP RTP/media Proxy Daemon
After=network-online.target
After=remote-fs.target
Requires=network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/default/ngcp-rtpengine-daemon
PIDFile=/var/run/ngcp-rtpengine-daemon.pid
ExecStartPre=/usr/sbin/ngcp-rtpengine-iptables-setup start
ExecStart=/usr/sbin/rtpengine -f -E --pidfile /var/run/ngcp-rtpengine-daemon.pid --config-file /etc/rtpengine/rtpengine.conf --table $TABLE
ExecStopPost=/usr/sbin/ngcp-rtpengine-iptables-setup stop
[Install]
WantedBy=multi-user.target

+ 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

@ -32,7 +32,6 @@ if [ "$RUN_RTPENGINE_RECORDING" != "yes" ]; then
exit 0 exit 0
fi fi
[ -z "$PIDFILE" ] && PIDFILE="/var/run/rtpengine-recording.pid" [ -z "$PIDFILE" ] && PIDFILE="/var/run/rtpengine-recording.pid"
[ -z "$NFS_OPTIONS" ] && NFS_OPTIONS="hard,tcp,intr"
OPTIONS="" OPTIONS=""
START_OPTIONS="" START_OPTIONS=""
@ -83,15 +82,9 @@ case "$1" in
fi fi
set -e 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 # shellcheck disable=SC2086
start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ 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/ recording-daemon/rtpengine-recording /usr/sbin/
debian/ngcp-rtpengine-recording-nfs-setup /usr/sbin/

+ 14
- 0
debian/ngcp-rtpengine-recording-daemon.service View File

@ -0,0 +1,14 @@
[Unit]
Description=NGCP RTP/media Recording Daemon
After=network-online.target
After=remote-fs.target
Requires=network-online.target
[Service]
Type=simple
PIDFile=/run/ngcp-rtpengine-recording-daemon.pid
ExecStartPre=/usr/sbin/ngcp-rtpengine-recording-nfs-setup start
ExecStart=/usr/sbin/rtpengine-recording -f -E --pidfile /run/ngcp-rtpengine-recording-daemon.pid --config-file /etc/rtpengine/rtpengine-recording.conf
[Install]
WantedBy=multi-user.target

+ 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