diff --git a/debian/metaproxy.default b/debian/metaproxy.default index 51f3a26e..550fe055 100644 --- a/debian/metaproxy.default +++ b/debian/metaproxy.default @@ -1,10 +1,8 @@ -# Defaults for metaproxy initscript -# sourced by /etc/init.d/metaproxy -# installed at /etc/default/metaproxy by the maintainer scripts - -# -# This is a POSIX shell fragment -# - -# Additional options that are passed to the Daemon. -DAEMON_OPTS="-D -u $SERVER_USER -p /var/run/metaproxy.pid -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml" +# Metaproxy user information +SERVER_HOME=/var/lib/metaproxy +SERVER_USER=metaproxy +SERVER_NAME="Metaproxy user" +SERVER_GROUP=metaproxy +# Options passed in metaproxy.service +# Do *not* use -D unless changing Type=fork +OPTIONS="-u ${SERVER_USER} -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml" diff --git a/debian/metaproxy.init b/debian/metaproxy.init deleted file mode 100644 index adfdd812..00000000 --- a/debian/metaproxy.init +++ /dev/null @@ -1,180 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: metaproxy -# Required-Start: $local_fs $remote_fs $network $named $time -# Required-Stop: $local_fs $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Controls the metaproxy daemon -# Description: Controls the Metaproxy daemon /usr/bin/metaproxy . -### END INIT INFO - -# Do NOT "set -e" - -# PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/sbin:/usr/sbin:/bin:/usr/bin -NAME=metaproxy -DAEMON=/usr/bin/$NAME -DAEMON_OPTS="-h" -PIDFILE=/var/run/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME - -# Exit if the package is not installed -[ -x "$DAEMON" ] || exit 0 - -# Read user information -. /etc/metaproxy/metaproxy.user - -# Read configuration variable file if it is present -[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -. /lib/init/vars.sh - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -# -# Function that starts the daemon/service -# -do_start() -{ - # Return - # 0 if daemon has been started - # 1 if daemon was already running - # 2 if daemon could not be started - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ - || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_OPTS \ - || return 2 - # Add code here, if necessary, that waits for the process to be ready - # to handle requests from services started subsequently which depend - # on this one. As a last resort, sleep for some time. -} - -# -# Function that stops the daemon/service -# -do_stop() -{ - # Return - # 0 if daemon has been stopped - # 1 if daemon was already stopped - # 2 if daemon could not be stopped - # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE - RETVAL="$?" - [ "$RETVAL" = 2 ] && return 2 - # Wait for children to finish too if this is a daemon that forks - # and if the daemon is only ever run from this initscript. - # If the above conditions are not satisfied then add some other code - # that waits for the process to drop all resources that could be - # needed by services started subsequently. A last resort is to - # sleep for some time. - #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON - #[ "$?" = 2 ] && return 2 - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE - return "$RETVAL" -} - -# -# Function that sends a SIGUSR1 to the daemon/service -# -do_reload() { - # - # If the daemon can reload its configuration without - # restarting (for example, when it is sent a SIGHUP), - # then implement that here. - - $DAEMON -t $DAEMON_OPTS > /dev/null || return 2 - start-stop-daemon --stop --signal USR1 --quiet --retry=5 --pidfile $PIDFILE --name $NAME - RETVAL="$?" - # Return if daemon could not be stopped - [ "$RETVAL" = 2 ] && return 2 - # daemon not running or stopped - rm -f $PIDFILE - # Return if it was not running, in which case we don't start it - [ "$RETVAL" = 1 ] && return 0 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_OPTS \ - || return 2 - return 0 -} - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" = no ] && \ - log_daemon_msg "Starting $DESC" "$NAME" - log_end_msg 1 - ;; - esac - ;; - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - do_stop - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" = no ] && \ - log_daemon_msg "Stopping $DESC" "$NAME" - log_end_msg 1 - ;; - esac - ;; - reload|force-reload) - # - # If do_reload() is not implemented then leave this commented out - # and leave 'force-reload' as an alias for 'restart'. - # - # our reload makes a new PID. systemd doesn't allow it. MP-620 - if test -n "$_use_systemctl"; then - log_daemon_msg "Using systemd. Not reloading $DESC" "$NAME" - log_end_msg 0 - else - log_daemon_msg "Reloading $DESC" "$NAME" - do_reload - log_end_msg $? - fi - ;; - restart) - # - # If the "reload" option is implemented then remove the - # 'force-reload' alias - # - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - do_start - case "$?" in - 0) log_end_msg 0 ;; - 1) log_end_msg 1 ;; # Old process is still running - *) log_end_msg 1 ;; # Failed to start - esac - ;; - *) - # Failed to stop - log_end_msg 1 - ;; - esac - ;; - checkconfig) - $DAEMON -t $DAEMON_OPTS > /dev/null || exit 2 - exit 0 - ;; - status) - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2 - exit 3 - ;; -esac - -: diff --git a/debian/metaproxy.install b/debian/metaproxy.install index bad0fd9f..1c2f17e6 100644 --- a/debian/metaproxy.install +++ b/debian/metaproxy.install @@ -1,5 +1,4 @@ etc/metaproxy/metaproxy.xml -etc/metaproxy/metaproxy.user usr/bin/metaproxy usr/share/man/man1/metaproxy.1 usr/share/man/man3/* diff --git a/debian/metaproxy.logrotate b/debian/metaproxy.logrotate index 239c58ab..d022c4a1 100644 --- a/debian/metaproxy.logrotate +++ b/debian/metaproxy.logrotate @@ -6,8 +6,8 @@ delaycompress notifempty postrotate - if [ -f /var/run/metaproxy.pid ]; then - kill -HUP `cat /var/run/metaproxy.pid` + if [ -d /run/systemd/system ]; then + /usr/bin/systemctl try-reload-or-restart metaproxy.service fi endscript create 644 metaproxy root diff --git a/debian/metaproxy.postinst b/debian/metaproxy.postinst index d1897b1d..deefd1c9 100644 --- a/debian/metaproxy.postinst +++ b/debian/metaproxy.postinst @@ -4,18 +4,22 @@ set -e case "$1" in configure) - . /etc/metaproxy/metaproxy.user - - # 1. create group if not existing + . /etc/default/metaproxy + + # remove old init.d script if existing + if [ -f /etc/init.d/metaproxy ]; then + rm -f /etc/init.d/metaproxy + fi + # create group if not existing if ! getent group | grep -q "^$SERVER_GROUP:" ; then echo -n "Adding group $SERVER_GROUP.." addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true echo "..done" fi - # 2. create homedir if not existing + # create homedir if not existing test -d $SERVER_HOME || mkdir $SERVER_HOME - # 3. create user if not existing + # create user if not existing if ! getent passwd | grep -q "^$SERVER_USER:"; then echo -n "Adding system user $SERVER_USER.." adduser --quiet \ @@ -26,23 +30,39 @@ case "$1" in $SERVER_USER 2>/dev/null || true echo "..done" fi - # 4. adjust passwd entry + # adjust passwd entry usermod -c "$SERVER_NAME" \ -d $SERVER_HOME \ -g $SERVER_GROUP \ $SERVER_USER - - # 5. adjust file and directory permissions + + # adjust file and directory permissions if ! dpkg-statoverride --list $SERVER_HOME >/dev/null then chown -R $SERVER_USER:adm $SERVER_HOME chmod u=rwx,g=rxs,o= $SERVER_HOME fi - - # 6. start service - if [ -x "/etc/init.d/metaproxy" ]; then - update-rc.d metaproxy defaults >/dev/null - invoke-rc.d metaproxy start || exit $? + # reload systemd daemon if systemd is used + if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true fi ;; esac + +# Automatically added by dh_installsystemd/13.24.2 +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # The following line should be removed in trixie or trixie+1 + deb-systemd-helper unmask 'metaproxy.service' >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled 'metaproxy.service'; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable 'metaproxy.service' >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state 'metaproxy.service' >/dev/null || true + fi +fi +# End automatically added section diff --git a/debian/metaproxy.postrm b/debian/metaproxy.postrm index ce720c14..9fd87101 100644 --- a/debian/metaproxy.postrm +++ b/debian/metaproxy.postrm @@ -4,12 +4,8 @@ set -e case "$1" in purge) - update-rc.d metaproxy remove >/dev/null - - # copy of metaproxy.user, which is gone at this point - SERVER_HOME=/var/metaproxy + # delete the orignal user SERVER_USER=metaproxy - SERVER_NAME="Metaproxy user" SERVER_GROUP=metaproxy # find first and last SYSTEM_UID numbers diff --git a/debian/metaproxy.prerm b/debian/metaproxy.prerm index 26165383..b5957fa5 100644 --- a/debian/metaproxy.prerm +++ b/debian/metaproxy.prerm @@ -1,5 +1,5 @@ -#!/bin/sh -set -e -if [ -x "/etc/init.d/metaproxy" ]; then - invoke-rc.d metaproxy stop || exit $? +# Automatically added by dh_installsystemd/13.24.2 +if [ -z "$DPKG_ROOT" ] && [ "$1" = remove ] && [ -d /run/systemd/system ] ; then + deb-systemd-invoke stop 'metaproxy.service' >/dev/null || true fi +# End automatically added section diff --git a/debian/metaproxy.service b/debian/metaproxy.service new file mode 100644 index 00000000..d41ae7ef --- /dev/null +++ b/debian/metaproxy.service @@ -0,0 +1,17 @@ +# Metaproxy systemd-style configuration + +[Unit] +Description=Metaproxy Z39.50/SRU router +Documentation=man:metaproxy(1) +After=network.target + +[Service] +Type=exec +EnvironmentFile=/etc/default/metaproxy +Restart=on-abort +KillMode=process +ExecStart=/bin/sh -c "exec /usr/bin/metaproxy ${OPTIONS}" +ExecReload=kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules index d1eca4b8..b75b7889 100755 --- a/debian/rules +++ b/debian/rules @@ -18,7 +18,6 @@ override_dh_auto_install: mv debian/tmp/usr/share/doc/metaproxy debian/tmp/usr/share/doc/metaproxy-doc mkdir -p debian/tmp/etc/metaproxy cp debian/metaproxy.xml debian/tmp/etc/metaproxy/metaproxy.xml - cp rpm/metaproxy.user debian/tmp/etc/metaproxy/metaproxy.user override_dh_makeshlibs: dh_makeshlibs -V 'libmetaproxy6 (>= 1.12.0)' @@ -28,3 +27,6 @@ override_dh_installchangelogs: override_dh_installdocs: dh_installdocs -A README.md + +override_dh_installsystemd: + dh_installsystemd