diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index 1f18caae0..8a8115188 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -3,3 +3,5 @@ CONFIG_FILE=/etc/rtpengine/rtpengine.conf # CONFIG_SECTION=rtpengine PIDFILE=/var/run/ngcp-rtpengine-daemon.pid TABLE=0 +#SET_USER=root +#SET_GROUP=root # GROUP only needs to be set if USER is not set or if the user isn't in the group diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 66b81c371..0daf65ae7 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -37,6 +37,8 @@ set -e . /lib/lsb/init-functions OPTIONS="" +START_OPTIONS="" +MODPROBE_OPTIONS="" if [ ! -z "$INTERFACES" ]; then for interface in $INTERFACES; do @@ -111,6 +113,37 @@ if test "$LOG_STDERR" = "yes" ; then OPTIONS="$OPTIONS --log-stderr" fi +# check if directory for pid file needs to be created + +PIDDIR=$(dirname "$PIDFILE") +DO_DIR_CHOWN=0 +if ! test -z "$PIDDIR" && ! test -d "$PIDDIR"; then + mkdir -p "$PIDDIR" + DO_DIR_CHOWN=1 +fi + +# handle requested setuid/setgid + +if ! test -z "$SET_USER"; then + START_OPTIONS="$START_OPTIONS --chuid $SET_USER" + UID=$(id -u "$SET_USER" 2> /dev/null) + test -z "$UID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_uid=$UID" + if test -z "$SET_GROUP"; then + GID=$(id -g "$SET_USER" 2> /dev/null) + test -z "$GID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$GID" + fi + test "$DO_DIR_CHOWN" = 1 && chown "$SET_USER": "$PIDDIR" +fi + +if ! test -z "$SET_GROUP"; then + START_OPTIONS="$START_OPTIONS --group $SET_GROUP" + GID=$(grep "^$SET_GROUP:" /etc/group | cut -d: -f3 2> /dev/null) + test -z "$GID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$GID" + 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" @@ -137,7 +170,7 @@ case "$1" in log_daemon_msg "Starting $DESC: $NAME" if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then set +e - modprobe xt_RTPENGINE + modprobe xt_RTPENGINE $MODPROBE_OPTIONS if [ -e /proc/mediaproxy/control ]; then echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null fi @@ -173,7 +206,7 @@ case "$1" in set -e fi start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ - --exec "$DAEMON" -- $OPTIONS || log_progress_msg " already running" + --exec "$DAEMON" $START_OPTIONS -- $OPTIONS || log_progress_msg " already running" log_end_msg $? ;; stop) @@ -184,6 +217,7 @@ case "$1" in return $? fi if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then + sleep 1 set +e if [ -e /proc/mediaproxy/control ]; then echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null diff --git a/debian/ngcp-rtpengine-recording-daemon.default b/debian/ngcp-rtpengine-recording-daemon.default index 6346c6003..2e527f114 100644 --- a/debian/ngcp-rtpengine-recording-daemon.default +++ b/debian/ngcp-rtpengine-recording-daemon.default @@ -2,7 +2,9 @@ RUN_RTPENGINE_RECORDING=no CONFIG_FILE=/etc/rtpengine/rtpengine-recording.conf # CONFIG_SECTION=rtpengine-recording PIDFILE=/var/run/ngcp-rtpengine-recording-daemon.pid - +#SET_USER=root +#SET_GROUP=root # GROUP only needs to be set if USER is not set or if the user isn't in the group +# MUST_NFS=no NFS_HOST=192.168.1.1 NFS_REMOTE_PATH=/var/recordings diff --git a/debian/ngcp-rtpengine-recording-daemon.init b/debian/ngcp-rtpengine-recording-daemon.init index d63d0ca56..1256e556d 100755 --- a/debian/ngcp-rtpengine-recording-daemon.init +++ b/debian/ngcp-rtpengine-recording-daemon.init @@ -37,11 +37,44 @@ set -e . /lib/lsb/init-functions OPTIONS="" +START_OPTIONS="" [ -z "$CONFIG_FILE" ] || OPTIONS="$OPTIONS --config-file=$CONFIG_FILE" [ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE" + +# check if directory for pid file needs to be created + +PIDDIR=$(dirname "$PIDFILE") +DO_DIR_CHOWN=0 +if ! test -z "$PIDDIR" && ! test -d "$PIDDIR"; then + mkdir -p "$PIDDIR" + DO_DIR_CHOWN=1 +fi + +# handle requested setuid/setgid + +if ! test -z "$SET_USER"; then + START_OPTIONS="$START_OPTIONS --chuid $SET_USER" + UID=$(id -u "$SET_USER" 2> /dev/null) + test -z "$UID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_uid=$UID" + if test -z "$SET_GROUP"; then + GID=$(id -g "$SET_USER" 2> /dev/null) + test -z "$GID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$GID" + fi + test "$DO_DIR_CHOWN" = 1 && chown "$SET_USER": "$PIDDIR" +fi + +if ! test -z "$SET_GROUP"; then + START_OPTIONS="$START_OPTIONS --group $SET_GROUP" + GID=$(grep "^$SET_GROUP:" /etc/group | cut -d: -f3 2> /dev/null) + test -z "$GID" || MODPROBE_OPTIONS="$MODPROBE_OPTIONS proc_gid=$GID" + 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" @@ -77,7 +110,7 @@ case "$1" in fi start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ - --exec "$DAEMON" -- $OPTIONS || log_progress_msg " already running" + --exec "$DAEMON" $START_OPTIONS -- $OPTIONS || log_progress_msg " already running" log_end_msg $? ;; stop) diff --git a/lib/auxlib.c b/lib/auxlib.c index b69853960..bd5fb9d8b 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "log.h" @@ -34,10 +35,13 @@ void wpidfile() { return; fp = fopen(pid_file, "w"); - if (fp) { - fprintf(fp, "%u\n", getpid()); - fclose(fp); + if (!fp) { + ilog(LOG_CRIT, "Failed to create PID file (%s), aborting startup", strerror(errno)); + exit(-1); } + + fprintf(fp, "%u\n", getpid()); + fclose(fp); }