From ab6fb6099303ecb05892c0b5063e90dbd993d9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Gon=C3=A7alves?= Date: Tue, 22 Oct 2019 14:23:35 +0100 Subject: [PATCH] Replace SysV init script by a Systemd service file. --- debian/control | 3 +- debian/kurento-media-server.default | 117 +++------------- debian/kurento-media-server.init | 200 ---------------------------- debian/kurento-media-server.service | 16 +++ debian/rules | 2 +- server/ResourceManager.cpp | 4 +- 6 files changed, 39 insertions(+), 303 deletions(-) delete mode 100755 debian/kurento-media-server.init create mode 100644 debian/kurento-media-server.service diff --git a/debian/control b/debian/control index 8eb96e379..633e772dc 100644 --- a/debian/control +++ b/debian/control @@ -20,7 +20,8 @@ Build-Depends: debhelper (>= 9), libglibmm-2.4-dev, libgstreamer-plugins-base1.5-dev, libsigc++-2.0-dev, - libssl1.0-dev | libssl-dev (<< 1.1.0) + libssl1.0-dev | libssl-dev (<< 1.1.0), + dh-systemd Standards-Version: 4.0.0 Vcs-Git: https://github.com/Kurento/kurento-media-server.git Vcs-Browser: https://github.com/Kurento/kurento-media-server diff --git a/debian/kurento-media-server.default b/debian/kurento-media-server.default index 11a6b1da8..65d0c0199 100644 --- a/debian/kurento-media-server.default +++ b/debian/kurento-media-server.default @@ -1,105 +1,24 @@ -# Defaults for kurento-media-server initscript (/etc/init.d/kurento-media-server) -# This is a POSIX shell fragment +# ############ BEGIN Settings for Kurento Media Server ############ -# Settings loaded by the initscript -START_DAEMON="true" # If not "true", the daemon will refuse to load -DAEMON_ARGS="" # Passed directly to the kurento-media-server executable -DAEMON_USER="kurento" # User as whom Kurento Media Server will run -DAEMON_LOG_DIR="/var/log/kurento-media-server" # Where to store daemon logs +# Logging level. +# See http://doc-kurento.readthedocs.io/en/latest/features/logging.html +GST_DEBUG_LEVEL="3" +GST_DEBUG="Kurento*:4,kms*:4,sdp*:4,webrtc*:4,*rtpendpoint:4,rtp*handler:4,rtpsynchronizer:4,agnosticbin:4" +# Path where rotating log files will be stored. +# If this option is unset, logging will be disabled. +# Default: Unset +LOGS_PATH="/var/log/kurento-media-server" +# Maximum file size for log files, in MB. +# Default: 100 +LOG_FILE_SIZE=100 -############ Kurento Media Server Settings ############ +# Maximum number of log files to keep. +# Default: 10 +NUMBER_LOG_FILES=10 -## Most settings can be passed either as environment variables or as -## command-line arguments. -## E.g.: KURENTO_LOGS_PATH="/tmp" is equivalent to --logs-path="/tmp" +# Extra options +EXTRA_OPTS="" -## Default logging levels for recommended components. -## Command line equivalent: --gst-debug-level=3 --gst-debug="[...]" -## See https://doc-kurento.readthedocs.io/en/latest/features/logging.html -export GST_DEBUG="3,Kurento*:4,kms*:4,sdp*:4,webrtc*:4,*rtpendpoint:4,rtp*handler:4,rtpsynchronizer:4,agnosticbin:4" - -## Extended logging: Event MediaFlow{In,Out} state changes -# export GST_DEBUG="${GST_DEBUG:-3},KurentoMediaElementImpl:5" - -## Extended logging: ICE candidate gathering -# export GST_DEBUG="${GST_DEBUG:-3},kmsiceniceagent:5,kmswebrtcsession:5,webrtcendpoint:4" - -## 3rd-Party logging: libnice -# export G_MESSAGES_DEBUG="libnice,libnice-stun" -# export GST_DEBUG="${GST_DEBUG:-3},glib:5" - -## Extended logging: RPC calls -# export GST_DEBUG="${GST_DEBUG:-3},KurentoWebSocketTransport:5" - -## Extended logging: Transcoding of media -# export GST_DEBUG="${GST_DEBUG:-3},Kurento*:5,agnosticbin*:5" - -## Logging settings: Disable colored output. -## When running KMS with these service init scripts, this setting mainly -## affects the output of errors in '/var/log/kurento-media-server/errors.log'. -## Also useful to set when running directly from a Docker container. -export GST_DEBUG_NO_COLOR=1 - -## Logging settings: Output path for GStreamer debug graphs. -## Uncomment to enable generation of debug graphs. -# export GST_DEBUG_DUMP_DOT_DIR="/tmp" - -## Path where rotating log files will be stored. -## If this option is unset, logging will be disabled. -## Command line equivalent: --logs-path -## Default: Unset -export KURENTO_LOGS_PATH="$DAEMON_LOG_DIR" - -## Maximum file size for log files, in MB. -## Command line equivalent: --log-file-size -## Default: 100 -# export KURENTO_LOG_FILE_SIZE=100 - -## Maximum number of log files to keep. -## Command line equivalent: --number-log-files -## Default: 10 -# export KURENTO_NUMBER_LOG_FILES=10 - -## Path to the main configuration file for Kurento. -## Command line equivalent: --conf-file -## Default: "/etc/kurento/kurento.conf.json" -# export KURENTO_CONF_FILE="/etc/kurento/kurento.conf.json" - -## Path to the directory where Kurento modules can be found. -## Command line equivalent: --modules-path -## Default: "/usr/lib" -# export KURENTO_MODULES_PATH="/usr/lib" - -## Path to the directory where config files can be found for Kurento modules. -## Command line equivalent: --modules-config-path -## Default: "/etc/kurento/modules" -# export KURENTO_MODULES_CONFIG_PATH="/etc/kurento/modules" - - - -############ Linux Kernel & System Settings ############ - -unset GST_PLUGIN_PATH - -## Destination of Kernel core dump files -## See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt -## -## In Ubuntu, if Apport is installed it creates a compact Crash Report -## including the Core Dump and some other system information. -## The default pattern in Ubuntu desktop systems is: -## '|/usr/share/apport/apport %p %s %c %d %P'. -## -## Uncomment to set a custom pattern for core dump files. -# DAEMON_CORE_PATTERN="/tmp/core_%e_%p_%u_%t" - -## Set per-process max open file descriptors to half of system-wide max -## (Only touch this if you are a sysadmin and/or you know what you are doing!) -DAEMON_MAX_FILES="$(( ($(cat /proc/sys/fs/file-max) * 50) / 100 ))" - -## Set per-user max threads to system's "Hard Limit" -## (Only touch this if you are a sysadmin and/or you know what you are doing!) -## -## Note: This is '-u' in Bash and '-p' in Sh -# DAEMON_MAX_THREADS="$(ulimit -Hp)" +# ############ END Settings for Kurento Media Server ############ diff --git a/debian/kurento-media-server.init b/debian/kurento-media-server.init deleted file mode 100755 index 86656b405..000000000 --- a/debian/kurento-media-server.init +++ /dev/null @@ -1,200 +0,0 @@ -#!/bin/dash - -### BEGIN INIT INFO -# Provides: kurento-media-serverd -# Required-Start: $remote_fs $network -# Required-Stop: $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Kurento Media Server daemon -### END INIT INFO - -if [ -r /lib/lsb/init-functions ]; then - # shellcheck source=/lib/lsb/init-functions - . /lib/lsb/init-functions -else - echo "E: /lib/lsb/init-functions not found, package lsb-base needed" - exit 1 -fi - -# Default settings -START_DAEMON="false" -DAEMON_ARGS="" -DAEMON_USER="kurento" -DAEMON_LOG_DIR="/var/log/kurento-media-server" - -# Load user-configurable settings -if [ -r /etc/default/kurento-media-server ]; then - # shellcheck source=/etc/default/kurento-media-server - . /etc/default/kurento-media-server -fi - -# Non-configurable settings -DAEMON_BIN="/usr/bin/kurento-media-server" -PID_FILE="/var/run/kurento-media-server.pid" - -[ "$START_DAEMON" != "true" ] && { - log_failure_msg "Startup is disabled; enable it in /etc/default/kurento-media-server" - exit 1 -} - -[ ! -x "$DAEMON_BIN" ] && { - log_failure_msg "File is not executable: $DAEMON_BIN" - exit 1 -} - -# Only root can start Kurento -verify_user() { - [ "$(id -u)" -eq 0 ] || { - log_failure_msg "Only root can start or stop Kurento Media Server" - exit 1 - } -} - -start_kurento() { - verify_user - - # Verify pid file directory exists - if [ ! -e /var/run ]; then - install -d -m755 /var/run || { - log_failure_msg "Unable to access /var/run directory" - exit 1 - } - fi - - # Verify log directory exists - [ ! -d "$DAEMON_LOG_DIR" ] && { - log_warning_msg "Directory '$DAEMON_LOG_DIR' does not exist" - install -d -o "$DAEMON_USER" -m 755 "$DAEMON_LOG_DIR" || { - log_failure_msg "Cannot create directory: $DAEMON_LOG_DIR" - exit 1 - } - log_success_msg "Created directory: $DAEMON_LOG_DIR" - } - - # Make sure $DAEMON_LOG_DIR belongs to $DAEMON_USER - [ "$(stat -c '%U' "$DAEMON_LOG_DIR")" = "$DAEMON_USER" ] || { - log_warning_msg "Directory '$DAEMON_LOG_DIR' is not owned by '$DAEMON_USER'" - chown "$DAEMON_USER" "$DAEMON_LOG_DIR" || { - log_failure_msg "Cannot change owner of '$DAEMON_LOG_DIR' to '$DAEMON_USER'" - exit 1 - } - log_success_msg "Changed owner of '$DAEMON_LOG_DIR' to '$DAEMON_USER'" - } - - # If set and non-null, configure Kernel core dump output pattern - [ -n "${DAEMON_CORE_PATTERN:-}" ] && { - echo "$DAEMON_CORE_PATTERN" | tee /proc/sys/kernel/core_pattern >/dev/null - } - - # Update process' resource limits - log_action_msg "Configure Kernel resource limits for Kurento Media Server" - - # Enable generation of Kernel core dumps / crash reports - ulimit -c unlimited || { - log_failure_msg "Cannot set limit: unlimited core dump size" - exit 1 - } - - # If set and not null, configure per-process max open file descriptors - [ -n "${DAEMON_MAX_FILES:-}" ] && { - # Maximum limit value allowed by Ubuntu: 2^20 = 1048576 - MAXIMUM_LIMIT=1048576 - [ "$DAEMON_MAX_FILES" -gt "$MAXIMUM_LIMIT" ] && DAEMON_MAX_FILES="$MAXIMUM_LIMIT" - - ulimit -n "$DAEMON_MAX_FILES" || { - log_failure_msg "Cannot set limit: $DAEMON_MAX_FILES max open file descriptors" - exit 1 - } - } - - # If set and not null, configure per-user max threads - [ -n "${DAEMON_MAX_THREADS:-}" ] && { - ulimit -Sp "$DAEMON_MAX_THREADS" || { - log_failure_msg "Cannot set limit: $DAEMON_MAX_THREADS max threads" - exit 1 - } - } - - # Add new section in error log - # Note: This is "echo" Dash builtin, not the "/bin/echo" GNU command, so - # escape sequences can be used directly, no need to enable them - echo "\n\n$(date --iso-8601=seconds) -- New execution" >>"$DAEMON_LOG_DIR/errors.log" - - /sbin/start-stop-daemon \ - --start \ - --pidfile "$PID_FILE" \ - --make-pidfile \ - --exec "$DAEMON_BIN" \ - --chuid "$DAEMON_USER" \ - --background \ - --no-close \ - -- $DAEMON_ARGS \ - 2>>"$DAEMON_LOG_DIR/errors.log" || { - log_warning_msg "Kurento Media Server already started" - return - } -} - -stop_kurento() { - verify_user - - /sbin/start-stop-daemon \ - --stop \ - --exec "$DAEMON_BIN" \ - --pidfile "$PID_FILE" || { - log_failure_msg "Kurento Media Server not running" - } - - [ -f "$PID_FILE" ] && rm -f "$PID_FILE" -} - -status() { - log_action_begin_msg "Checking Kurento Media Server" - - rc="$(pidofproc -p "$PID_FILE" "$DAEMON_BIN" >/dev/null 2>&1)" - if [ "$rc" -eq 0 ]; then - read -r pid < "$PID_FILE" - log_action_cont_msg "$DAEMON_BIN is running with pid $pid" - elif [ "$rc" -eq 1 ]; then - log_action_cont_msg "$DAEMON_BIN is not running but the pid file exists" - elif [ "$rc" -eq 3 ]; then - log_action_cont_msg "$DAEMON_BIN is not running" - else - log_action_cont_msg "Unable to determine $DAEMON_BIN status" - fi - log_action_end_msg "$rc" - return "$rc" -} - -case "$1" in - start) - log_daemon_msg "Start Kurento Media Server" - start_kurento - log_end_msg $?; - ;; - - stop) - log_daemon_msg "Stop Kurento Media Server"; - stop_kurento - log_end_msg $?; - ;; - - restart) - $0 stop - $0 start - ;; - - force-reload) - $0 stop - $0 start - ;; - - status) - status - ;; - - *) - echo "Usage: $0 {start|stop|restart|status}" >&2 - ;; -esac diff --git a/debian/kurento-media-server.service b/debian/kurento-media-server.service new file mode 100644 index 000000000..59bcbe9bc --- /dev/null +++ b/debian/kurento-media-server.service @@ -0,0 +1,16 @@ +[Unit] +Description=Kurento Media Server daemon +After=network.target + +[Service] +Type=simple +EnvironmentFile=/etc/default/kurento-media-server +User=kurento +Group=kurento +LimitCORE=infinity +LimitNOFILE=100000 +ExecStart=/usr/bin/kurento-media-server --gst-debug-level=${GST_DEBUG_LEVEL} --gst-debug=${GST_DEBUG} --logs-path=${LOGS_PATH} --log-file-size=${LOG_FILE_SIZE} --number-log-files=${NUMBER_LOG_FILES} ${EXTRA_OPTS} +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules index f1ea043b6..1acbaa06b 100755 --- a/debian/rules +++ b/debian/rules @@ -4,7 +4,7 @@ #export DH_VERBOSE=1 %: - dh $@ --parallel + dh $@ --parallel --with=systemd override_dh_auto_configure: export FINAL_INSTALL_DIR=/usr diff --git a/server/ResourceManager.cpp b/server/ResourceManager.cpp index 0c9126385..6cf17cad9 100644 --- a/server/ResourceManager.cpp +++ b/server/ResourceManager.cpp @@ -95,7 +95,7 @@ checkThreads (float limit_percent) std::string exMessage = oss.str(); oss << " (system max: " << maxThreads << ");" - << " set a higher limit with `ulimit -Su`, or in the KMS service settings (/etc/default/kurento-media-server)"; + << " set a higher limit with `ulimit -Su`, or override service settings with `systemctl edit kurento-media-server`"; std::string logMessage = oss.str(); GST_WARNING ("%s", logMessage.c_str()); @@ -153,7 +153,7 @@ checkOpenFiles (float limit_percent) std::string exMessage = oss.str(); oss << " (system max: " << maxOpenFiles << ");" - << " set a higher limit with `ulimit -Sn`, or in the KMS service settings (/etc/default/kurento-media-server)"; + << " set a higher limit with `ulimit -Sn`, or override service settings with `systemctl edit kurento-media-server`"; std::string logMessage = oss.str(); GST_WARNING ("%s", logMessage.c_str());