diff options
-rwxr-xr-x | add-service | 38 | ||||
-rwxr-xr-x | del-service | 17 |
2 files changed, 28 insertions, 27 deletions
diff --git a/add-service b/add-service index 4561f12..307f0a4 100755 --- a/add-service +++ b/add-service @@ -22,6 +22,13 @@ if [ $# -lt 3 ]; then exit 1 fi +# What init system are we currently using? +if /bin/mountpoint -q /sys/fs/cgroup/systemd; then + init=systemd +else + init=sysvinit +fi + pkg=$1 # name of the package num=$2 # number of packages installed if [ $do_sysv = yes ]; then @@ -107,28 +114,19 @@ if [ $num = 1 ]; then # First install mode add_service else - # Upgrade mode. systemd units are restarted in postun - [ -n "$srv" ] || exit 0 - - # if the service is activated, add it again to be able to handle - # changes in start/stop levels. This does not change enabled/disabled - # state, so we do not do it for systemd where dependencies are handled - # automatically. - - # Restart only SysV services here only if no additional systemd - # units are defined or systemd is not active. Otherwise user is expected - # to add postun script that handles systemd units. - - set -- /etc/rc3.d/S??$srv - if [ $# -gt 1 ]; then - echo 1>&2 "add-service: Error: $srv appears multiple times: $*" - fi + # Upgrade mode. + if [ x$init = xsystemd ]; then + /bin/systemctl --quiet try-restart $units + else + set -- /etc/rc3.d/S??$srv + if [ $# -gt 1 ]; then + echo 1>&2 "add-service: Error: $srv appears multiple times: $*" + fi - if [ -f "$1" ]; then - /sbin/chkconfig --add $srv - fi + if [ -f "$1" ]; then + /sbin/chkconfig --add $srv + fi - if ! /bin/mountpoint -q /sys/fs/cgroup/systemd; then # restart the service if already running if [ -f /var/lock/subsys/$srv ]; then /sbin/service $srv restart > /dev/null || : diff --git a/del-service b/del-service index 753fcc3..f519065 100755 --- a/del-service +++ b/del-service @@ -22,6 +22,13 @@ if [ $# -lt 3 ]; then exit 1 fi +# What init system are we currently using? +if /bin/mountpoint -q /sys/fs/cgroup/systemd; then + init=systemd +else + init=sysvinit +fi + pkg=$1 # name of the package num=$2 # number of packages installed if [ $do_sysv = yes ]; then @@ -44,10 +51,8 @@ fi if [ $num = 0 ]; then if [ -z "$DURING_INSTALL" ]; then - if [ -n "$units" ]; then - if /bin/mountpoint -q /sys/fs/cgroup/systemd; then - /bin/systemctl stop $units - fi + if [ x$init = xsystemd ]; then + /bin/systemctl stop $units elif [ -n "srv" ]; then /sbin/service $srv stop > /dev/null || : fi @@ -59,9 +64,7 @@ if [ $num = 0 ]; then # Yes - this is very ugly workaround. chkconfig --del does daemon-reload, # but initscript is still there, so it remains loaded. Remove file and # reload again. Systemd units are supposed to provide postun script - - if [ -n "$srv" -a -f /etc/rc.d/init.d/$srv ] && \ - /bin/mountpoint -q /sys/fs/cgroup/systemd; then + if [ -n "$srv" -a -f /etc/rc.d/init.d/$srv -a x$init = xsystemd ]; then /bin/rm -f /etc/rc.d/init.d/$srv /bin/systemctl daemon-reload fi |