diff --git a/debian/control b/debian/control index ba540c188..778e8dea1 100644 --- a/debian/control +++ b/debian/control @@ -21,7 +21,8 @@ Build-Depends: debhelper (>= 9), libglibmm-2.4-dev, libgstreamer-plugins-base1.5-dev, libsigc++-2.0-dev, - libwebsocketpp-dev + libwebsocketpp-dev, + 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 177244c74..3790edfcc 100644 --- a/debian/kurento-media-server.default +++ b/debian/kurento-media-server.default @@ -1,109 +1,25 @@ -#!/bin/dash -# File checked with ShellCheck: https://www.shellcheck.net/ -# shellcheck disable=SC2034 # Ignore unused variables +# ############ BEGIN Settings for Kurento Media Server ############ -# This file is loaded by "/etc/init.d/kurento-media-server", the system service -# init script that is run by the command `service kurento-media-server start`. -# -# Settings found in this file won't be loaded if Kurento Media Server is started -# manually, for example by directly executing `/usr/bin/kurento-media-server`. +# 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" +GST_DEBUG_NO_COLOR=1 +# 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 -# Service init script settings -# ============================ +# Maximum number of log files to keep. +# Default: 10 +NUMBER_LOG_FILES=10 -# If not "true", the service will refuse to start -START_DAEMON="true" +# Extra options +EXTRA_OPTS="" -# Arguments that will get passed directly to the KMS executable -DAEMON_ARGS="" - -# Linux user that will be owner of KMS process and generated files -DAEMON_USER="kurento" - -# Path where to store log files -DAEMON_LOG_DIR="/var/log/kurento-media-server" - -## System-wide destination of Kernel core dump files. See: -## https://www.kernel.org/doc/Documentation/sysctl/kernel.txt -## -## Note that in Ubuntu with Apport the default pattern is: -## |/usr/share/apport/apport %p %s %c %d %P -## and it only creates a one-time Crash Report in "/var/crash/". See: -## https://doc-kurento.readthedocs.io/en/latest/user/troubleshooting.html#media-server-crashes -## -## Uncomment this to override Apport and/or set a custom core dump destination -## into the file "/proc/sys/kernel/core_pattern": -# DAEMON_CORE_PATTERN="/tmp/core_%e_%p_%u_%t" - -## Per-process max open file descriptors (set 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) / 2 ))" - -## Per-user max threads (set to Kernel 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 POSIX shell (like Dash) -# DAEMON_MAX_THREADS="$(ulimit -Hp)" - - - -# Debug & logging settings -# ======================== - -## Default recommended logging levels -export GST_DEBUG="3,Kurento*:4,kms*:4,sdp*:4,webrtc*:4,*rtpendpoint:4,rtp*handler:4,rtpsynchronizer:4,agnosticbin:4" - -## Extended logging -## -## To investigate issues in some parts of KMS, you'll want to enable additional -## logs. Check out KMS docs to see some of the **suggested levels**: -## https://doc-kurento.readthedocs.io/en/latest/features/logging.html -## -## For convenience, some of the suggested levels are provided here: -## -## Extended logging: MediaFlow{In,Out} event state changes -# export GST_DEBUG="${GST_DEBUG:-3},KurentoMediaElementImpl:5" -## -## Extended logging: WebRTC ICE candidate gathering -# export GST_DEBUG="${GST_DEBUG:-3},kmsiceniceagent:5,kmswebrtcsession:5,webrtcendpoint:4" -## -## Extended logging: Transcoding of media -# export GST_DEBUG="${GST_DEBUG:-3},Kurento*:5,agnosticbin*:5" - -## Disable colored output, so logs don't contain extraneous characters -export GST_DEBUG_NO_COLOR=1 - -## Output path for GStreamer debug graphs (uncomment to enable graphs) -# export GST_DEBUG_DUMP_DOT_DIR="/tmp" - -## Path for rotating log files (comment to disable logs) -export KURENTO_LOGS_PATH="$DAEMON_LOG_DIR" - -## Maximum file size for rotating log files, in MB (default: 100 MB) -# export KURENTO_LOG_FILE_SIZE=100 - -## Maximum number of rotating log files to keep (default: 10 files) -# export KURENTO_NUMBER_LOG_FILES=10 - -## Abort the server when underlying libs print a Warning or Critical message, -## for example "GStreamer-WARNING" or "GStreamer-CRITICAL". This can be used to -## obtain a Kernel core dump or a GDB backtrace, needed to solve the issue. See: -## https://doc-kurento.readthedocs.io/en/latest/user/troubleshooting.html#gstreamer-critical-messages-in-the-log -# export G_DEBUG="fatal-warnings" - - - -# Server settings -# =============== - -unset GST_PLUGIN_PATH - -## Path to the main configuration file for Kurento Media Server -# export KURENTO_CONF_FILE="/etc/kurento/kurento.conf.json" - -## Path to the directory where Kurento modules can be found -# export KURENTO_MODULES_PATH="/usr/lib" - -## Path to the directory where config files can be found for Kurento modules -# export KURENTO_MODULES_CONFIG_PATH="/etc/kurento/modules" +# ############ 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 8c8992f2b..000000000 --- a/debian/kurento-media-server.init +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/dash -# File checked with ShellCheck: https://www.shellcheck.net/ - -### 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" -DAEMON_ERR_FILE="$DAEMON_LOG_DIR/errors.log" -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 -m 755 -d /var/run || { - log_failure_msg "Unable to access /var/run directory" - exit 1 - } - fi - - # Verify logs destination directory ($DAEMON_LOG_DIR) - [ -d "$DAEMON_LOG_DIR" ] || { - log_warning_msg "Directory '$DAEMON_LOG_DIR' does not exist" - install -m 755 -o "$DAEMON_USER" -d "$DAEMON_LOG_DIR" || { - log_failure_msg "Cannot create directory '$DAEMON_LOG_DIR'" - exit 1 - } - log_success_msg "Created directory '$DAEMON_LOG_DIR'" - } - [ "$(stat --printf='%U' "$DAEMON_LOG_DIR")" = "$DAEMON_USER" ] || { - log_warning_msg "'$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'" - } - - # Verify errors log file ($DAEMON_ERR_FILE) - [ -f "$DAEMON_ERR_FILE" ] || { - log_warning_msg "File '$DAEMON_ERR_FILE' does not exist" - install -m 644 -o "$DAEMON_USER" /dev/null "$DAEMON_ERR_FILE" || { - log_failure_msg "Cannot create file '$DAEMON_ERR_FILE'" - exit 1 - } - log_success_msg "Created file '$DAEMON_ERR_FILE'" - } - [ "$(stat --printf='%U' "$DAEMON_ERR_FILE")" = "$DAEMON_USER" ] || { - log_warning_msg "'$DAEMON_ERR_FILE' is not owned by '$DAEMON_USER'" - chown "$DAEMON_USER" "$DAEMON_ERR_FILE" || { - log_failure_msg "Cannot change owner of '$DAEMON_ERR_FILE' to '$DAEMON_USER'" - exit 1 - } - log_success_msg "Changed owner of '$DAEMON_ERR_FILE' 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 "Set 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_ERR_FILE" - - /sbin/start-stop-daemon \ - --start \ - --pidfile "$PID_FILE" \ - --make-pidfile \ - --exec "$DAEMON_BIN" \ - --chuid "$DAEMON_USER" \ - --background \ - --no-close \ - -- ${DAEMON_ARGS:-} \ - 2>>"$DAEMON_ERR_FILE" || { - 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());