This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit ff07123350b20d864f2e1bbdb54e7a102fc95332 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Apr 14 12:46:31 2021 +0200 debian/x2goserver.init: rewrite init script to make it idempotent and actually check if the cleanup service was started correctly. --- debian/changelog | 3 ++ debian/x2goserver.init | 101 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1d3f9c67..84ca3588 100644 --- a/debian/changelog +++ b/debian/changelog @@ -423,6 +423,9 @@ x2goserver (4.1.0.4-0x2go1.2) UNRELEASED; urgency=medium "double-quote" the resulting string. * debian/libx2go-server-perl.install: + Remove duplicated entry for X2Go/Utils.pm. + * debian/x2goserver.init: + + Rewrite init script to make it idempotent and actually check if the + cleanup service was started correctly. [ Oleksandr Shneyder ] * New upstream version (4.1.0.4): diff --git a/debian/x2goserver.init b/debian/x2goserver.init index 9d609571..fdf5d2b8 100644 --- a/debian/x2goserver.init +++ b/debian/x2goserver.init @@ -10,29 +10,92 @@ # Description: The X2Go daemon is responsible for post-session clean-ups ### END INIT INFO -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -XSOCKDIR=/tmp/.X11-unix +PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin' +XSOCKDIR='/tmp/.X11-unix' +DAEMON='/usr/sbin/x2gocleansessions' +PIDFILE='/var/run/x2goserver.pid' +NAME='X2Go Server clean-up daemon' -. /lib/lsb/init-functions +. '/lib/lsb/init-functions' start() { - if [ ! -d $XSOCKDIR ] + # Create socket dir if necessary. + if [ ! -d "${XSOCKDIR}" ] then - mkdir $XSOCKDIR - chmod 1777 $XSOCKDIR + mkdir "${XSOCKDIR}" + chmod '1777' "${XSOCKDIR}" fi - log_action_msg "Cleaning up stale X2Go sessions" - x2gocleansessions + + log_daemon_msg "Starting ${NAME}" "${DAEMON##*/}" + + # Check if daemon is already running. + local status='0' + pidofproc -p "${PIDFILE}" "${DAEMON}" >'/dev/null'|| status="${?}" + if [ '0' = "${status}" ]; then + # It is, nothing else to do. + log_end_msg '0' + return '0' + fi + + # Otherwise, start it. + status='0' + "${DAEMON}" || status="${?}" + + # Check if that was successful. + if [ '0' != "${status}" ]; then + log_end_msg "${status}" + return "${status}" + fi + + # It was, sleep a bit and ... + sleep '1' + + # ... recheck its status, in case it died in-between. + status='0' + pidofproc -p "${PIDFILE}" "${DAEMON}" >'/dev/null' || status="${?}" + log_end_msg "${status}" + + return "${status}" } stop() { - # kill x2gocleansessions, ignore on failure - killall x2gocleansessions || true + log_daemon_msg "Stopping ${NAME}" "${DAEMON##*/}" + + # Check if daemon is already dead. + local status='0' + pidofproc -p "${PIDFILE}" "${DAEMON}" >'/dev/null' || status="${?}" + if [ '0' != "${status}" ]; then + # It is, nothing else to do. + log_end_msg '0' + return '0' + fi + + # Otherwise, let's kill it. + status='0' + # Make sure to truncate the command name to 15 characters because of Linux kernel limitations. + # Also, hope that other kernels also limit the command name to 15 characters... + local proc_name="$(echo "${DAEMON##*/}" | cut -c '1-15')" + start-stop-daemon --stop --quiet --oknodo --name "${proc_name}" --pidfile "${PIDFILE}" || status="${?}" + + # Check its status. + if [ '0' != "${status}" ]; then + # Process wasn't killed, which is weird, since we made sure that it did via pidofproc. + # Maybe the process name truncation had side-effects. + # In any case, report the failure. + log_end_msg "${status}" + return "${status}" + else + # Otherwise, clean up PID file. + pidofproc -p "${PIDFILE}" "${DAEMON}" >'/dev/null' || rm -f "${PIDFILE}" + fi + + log_end_msg "${status}" + return "${status}" } -case "$1" in +case "${1}" in start) start ;; @@ -41,21 +104,17 @@ case "$1" in ;; reload|force-reload|restart) stop - sleep 1 + sleep '1' start ;; status) - if ps -C x2gocleansessions 1>/dev/null 2>/dev/null; then - log_action_msg "X2Go Server clean-up daemon is up and running" - else - log_warning_msg "X2Go Server clean-up daemon is down" - fi + status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" ;; *) - N=/etc/init.d/x2goserver - echo "Usage: $N {start|stop|restart|force-reload}" >&2 - exit 1 + N='/etc/init.d/x2goserver' + echo "Usage: ${N} {start|stop|restart|force-reload}" >&2 + exit '1' ;; esac -exit 0 +exit '0' -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git