From 74eee552b4d032320f824289650b93cd3157d5ec Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov Date: Tue, 8 Mar 2011 15:15:26 +0000 Subject: also re-enable systemd unit in update if it was enabled --- add-service | 34 +++++++++++++++++++--------------- del-service | 3 ++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/add-service b/add-service index 9e25c37..46a98ac 100755 --- a/add-service +++ b/add-service @@ -26,6 +26,7 @@ options=--quiet [ -x /bin/systemctl -a -r /lib/systemd/system/${srv}.service ] && systemd=yes [ -r /etc/rc.d/init.d/${srv} ] && sysv=yes [ $sysv = yes ] && options="$options --no-reload" +unit=${srv}.service add_chkconfig_service() { srv=$1 @@ -33,7 +34,7 @@ add_chkconfig_service() { # support for systemd. chkconfig will do daemon-reload for us if [ $systemd = yes ]; then - /bin/systemctl $options enable ${srv}.service + /bin/systemctl $options enable ${unit} fi if [ $sysv = yes ]; then /sbin/chkconfig --add $srv @@ -82,26 +83,29 @@ if [ $num = 1 ]; then # First install mode add_service else - # Upgrade mode. Only really makes sense for SysV scripts - [ $sysv = yes ] || exit 0 + # Upgrade mode. # if the service is activated, add it again to be able to handle - # changes in start/stop levels and enable systemd unit as well - set -- /etc/rc3.d/S??$srv - if [ $# -gt 1 ]; then - echo 1>&2 "add-service: Error: $srv appears multiple times: $*" + # changes in start/stop levels or systemd WantedBy lines + + if [ $systemd = yes ] && /bin/systemctl is-enabled ${unit}; then + /bin/systemctl --quiet enable ${unit} fi - if [ -f "$1" ]; then - if [ $systemd = yes ]; then - /bin/systemctl $options enable ${srv}.service + if [ $sysv = yes ]; then + set -- /etc/rc3.d/S??$srv + if [ $# -gt 1 ]; then + echo 1>&2 "add-service: Error: $srv appears multiple times: $*" fi - /sbin/chkconfig --add $srv - fi - # restart the service if already running - if [ -f /var/lock/subsys/$srv ]; then - /sbin/service $srv restart > /dev/null || : + if [ -f "$1" ]; then + /sbin/chkconfig --add $srv + fi + + # restart the service if already running + if [ -f /var/lock/subsys/$srv ]; then + /sbin/service $srv restart > /dev/null || : + fi fi fi diff --git a/del-service b/del-service index 881bb99..c95f992 100755 --- a/del-service +++ b/del-service @@ -26,6 +26,7 @@ options=--quiet [ -x /bin/systemctl -a -r /lib/systemd/system/${srv}.service ] && systemd=yes [ -r /etc/rc.d/init.d/${srv} ] && sysv=yes [ $sysv = yes ] && options="$options --no-reload" +unit=${srv}.service if [ $num = 0 ]; then # Will be redirected to systemd if needed @@ -35,7 +36,7 @@ if [ $num = 0 ]; then # support for systemd. chkconfig will do daemon-reload for us if [ $systemd = yes ]; then - /bin/systemctl $options disable ${srv}.service + /bin/systemctl $options disable ${unit} fi if [ $sysv = yes ]; then /sbin/chkconfig --del $srv -- cgit v1.2.1