From 3e792a689c36d3d938a20f634ebbc95c30ec2a9e Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Mon, 2 Jan 2012 11:25:55 +0000 Subject: [PATCH] daemon maintainer scripts: install init script + handle package removal/upgrade This is supposed to fix the missing ngcp-mediaproxy-ng-daemon link in /etc/rc2.d on CE systems. While at it also try to handle restart/stop of service during upgrades and package removals in a sane way. Needs extensive testing though. From: Michael Prokop --- debian/ngcp-mediaproxy-ng-daemon.postinst | 23 +++++++++++----- debian/ngcp-mediaproxy-ng-daemon.postrm | 18 +++++++++++++ debian/ngcp-mediaproxy-ng-daemon.prerm | 33 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) mode change 100644 => 100755 debian/ngcp-mediaproxy-ng-daemon.postinst create mode 100755 debian/ngcp-mediaproxy-ng-daemon.postrm create mode 100755 debian/ngcp-mediaproxy-ng-daemon.prerm diff --git a/debian/ngcp-mediaproxy-ng-daemon.postinst b/debian/ngcp-mediaproxy-ng-daemon.postinst old mode 100644 new mode 100755 index eface1ef1..5f48c7756 --- a/debian/ngcp-mediaproxy-ng-daemon.postinst +++ b/debian/ngcp-mediaproxy-ng-daemon.postinst @@ -3,8 +3,7 @@ set -e -# DEBHELPER like wrapper -init_wrapper() { +restart_handler() { if [ -x "/etc/init.d/ngcp-mediaproxy-ng-daemon" ]; then if [ -x "$(which invoke-rc.d 2>/dev/null)" ]; then invoke-rc.d ngcp-mediaproxy-ng-daemon restart || exit $? @@ -14,16 +13,24 @@ init_wrapper() { fi } -restart_daemon() { - # just invoke init script wrapper on ce systems since +initscript_handler() { + if [ -x "/etc/init.d/ngcp-mediaproxy-ng-daemon" ]; then + update-rc.d ngcp-mediaproxy-ng-daemon defaults >/dev/null + invoke-rc.d ngcp-mediaproxy-ng-daemon start || exit $? + fi +} + +init_handler() { + # just invoke init script wrappers on ce systems since # they do not provide ngcp-check_active and we don't # have to handle inactive nodes if ! [ -x "$(which ngcp-check_active 2>/dev/null)" ]; then - init_wrapper + restart_handler + initscript_handler else # do not restart daemon on inactive node in pro systems if ngcp-check_active ; then echo "Active node detected, restarting ngcp-mediaproxy-ng-daemon" - init_wrapper + restart_handler else echo "Inactive node detected, ignoring request to restart ngcp-mediaproxy-ng-daemon" fi @@ -32,7 +39,7 @@ restart_daemon() { case "$1" in configure) - restart_daemon + init_handler ;; abort-upgrade|abort-remove|abort-deconfigure) @@ -43,3 +50,5 @@ case "$1" in exit 1 ;; esac + +exit 0 diff --git a/debian/ngcp-mediaproxy-ng-daemon.postrm b/debian/ngcp-mediaproxy-ng-daemon.postrm new file mode 100755 index 000000000..d6a4f0acf --- /dev/null +++ b/debian/ngcp-mediaproxy-ng-daemon.postrm @@ -0,0 +1,18 @@ +#!/bin/sh +# postrm script for ngcp-mediaproxy-ng-daemon + +set -e + +removal_wrapper() { + # remove the init script only on ce systems, as the + # the pro system handle it inside the monitoring/HA setup + if ! [ -x "$(which ngcp-check_active 2>/dev/null)" ]; then + update-rc.d ngcp-mediaproxy-ng-daemon remove >/dev/null + fi +} + +if [ "$1" = "purge" ] ; then + removal_wrapper +fi + +exit 0 diff --git a/debian/ngcp-mediaproxy-ng-daemon.prerm b/debian/ngcp-mediaproxy-ng-daemon.prerm new file mode 100755 index 000000000..e8f3824fa --- /dev/null +++ b/debian/ngcp-mediaproxy-ng-daemon.prerm @@ -0,0 +1,33 @@ +#!/bin/sh +# prerm script for ngcp-mediaproxy-ng-daemon + +set -e + +stop_handler() { + if [ -x "/etc/init.d/ngcp-mediaproxy-ng-daemon" ]; then + invoke-rc.d ngcp-mediaproxy-ng-daemon stop || exit $? + fi +} + +stop_daemon() { + # just stop the service on ce systems because + # the pro system handle it as part of their monitoring/HA setup + if ! [ -x "$(which ngcp-check_active 2>/dev/null)" ]; then + stop_handler + else + case "$2" in + upgrade) + echo "Detected upgrade procedure, not stopping ngcp-mediaproxy-ng-daemon service." + ;; + remove|purge) + stop_handler + ;; + esac + fi +} + +if [ "$1" = "prerm" ] ; then + stop_daemon +fi + +exit 0