aboutsummaryrefslogtreecommitdiffstats
path: root/migrate-service
blob: de084356d4fbdc60bba0720ae47a6b9dc4e6d9f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandriva Linux
# Module          : rpm-helper
# File            : migrate-service
# Version         : $Id$
# Authors         : Andrey Borzenkov
# Created On      : Sat Mar 12 18:37:00 2011
# Purpose         : helper script for rpm scriptlets to migrate
#		    from SysV script to systemd unit.
#---------------------------------------------------------------

if [ $# -lt 3 ]; then
    echo "usage: $0 {pre|post} <service name> <unit name> ..." 1>&2
    exit 1
fi

phase=$1			# pre/post
srv=$2				# name of the SysV script
shift 2				# systemd units

if [ $phase = pre ]; then
    # create flag that service was active and stop it
    # As we are booted under systemd, we can just as well ask it ...
    /bin/rm -f /tmp/systemd-migrate-active-$srv
    if /bin/mountpoint -q /sys/fs/cgroup/systemd; then
	active=$(/bin/systemctl show --no-pager -p ActiveState $srv.service 2> /dev/null)
	if [ "${active#ActiveState=}" = active ]; then
	    /bin/touch /tmp/systemd-migrate-active-$srv
	    /bin/systemctl stop $srv.service
	fi
    fi

    # enable units if service was active in run-levels 3 or 5.
    # This loosely corresponds to systemctl is-enabled. We assume, that
    # units do include correct [Install] entries.
    if /sbin/chkconfig --no-redirect --level=3 $srv || \
       /sbin/chkconfig --no-redirect --level=5 $srv; then
	/bin/systemctl --no-reload --quiet enable "$@" || :
    fi
else
    # Reload daemon after old package was removed
    # Restart new units if old SysV script was started.
    if /bin/mountpoint -q /sys/fs/cgroup/systemd; then
	/bin/systemctl daemon-reload
	if [ -f /tmp/systemd-migrate-active-$srv ]; then
	    /bin/systemctl start "$@"
	fi
    fi
    /bin/rm -f /tmp/systemd-migrate-active-$srv
fi

# migrate-service ends here