blob: 6b9984bda025dd3f140d7e5521bb82fdd5b1205b (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/bin/sh
#---------------------------------------------------------------
# Project : Mageia Linux
# Module : rpm-helper
# File : del-service
# Version : $Id$
# Authors : Frederic Lepied, Andrey Borzenkov
# Created On : Tue Jul 9 08:11:26 2002
# Purpose : helper script for rpm scriptlets to remove a
# service.
#---------------------------------------------------------------
if [ x"$1" = x--no-sysv ]; then
do_sysv=no
shift
else
do_sysv=yes
fi
if [ $# -lt 3 ]; then
echo "usage: $0 [--no-sysv] <pkg name> <number installed> [<service name>] [<unit name> ...]" 1>&2
exit 1
fi
# What init system are we currently using?
if [ -d /run/systemd/system/ ]; then
init=systemd
else
init=sysvinit
fi
pkg=$1 # name of the package
num=$2 # number of packages installed
if [ $do_sysv = yes ]; then
srv=$3 # name of the SysV script
shift 3
else
srv=
shift 2
fi
units="$*" # systemd units
USERUNITDIR=/etc/systemd/system
RUNTIMEUNITDIR=/run/systemd/system
SYSTEMUNITDIR=/lib/systemd/system
find_unit() {
unit=$(basename "$1")
# We need to normalise the systemd unit name as the native unit may not have
# the same filename (sans it's .service suffix) as sysvinit script.
# In this case, symlinks are used to mask the sysvinit file, but for enabling
# and disabling units we must use the official name.
searchunit=
if [ -L "$USERUNITDIR/$unit" ]; then
searchunit=$(/usr/bin/readlink -m "$USERUNITDIR/$unit")
elif [ -e "$USERUNITDIR/$unit" ]; then
searchunit="$USERUNITDIR/$unit"
elif [ -L "$RUNTIMEUNITDIR/$unit" ]; then
searchunit=$(/usr/bin/readlink -m "$RUNTIMEUNITDIR/$unit")
elif [ -e "$RUNTIMEUNITDIR/$unit" ]; then
searchunit="$RUNTIMEUNITDIR/$unit"
elif [ -L "$SYSTEMUNITDIR/$unit" ]; then
searchunit=$(/usr/bin/readlink -m "$SYSTEMUNITDIR/$unit")
elif [ -e "$SYSTEMUNITDIR/$unit" ]; then
searchunit="$SYSTEMUNITDIR/$unit"
fi
if [ -n "$searchunit" ]; then
echo -n "$searchunit"
fi
}
# If only a sysvinit service is given, then deal with a systemd unit of the same
# name. Specific specs can enable specific unit names as needed but this should
# catch the most common usage.
if [ -z "$units" ]; then
units="$srv.service"
searchunit=$(find_unit "$units")
if [ -n "$searchunit" ]; then
units=$(basename "$searchunit")
fi
fi
if [ "$num" = 0 ]; then
if [ -z "$DURING_INSTALL" ]; then
if [ x$init = xsystemd ]; then
/bin/systemctl stop $units >/dev/null 2>&1
elif [ -n "$srv" ]; then
/sbin/service $srv stop > /dev/null || :
fi
fi
/bin/systemctl --no-reload --quiet disable $units >/dev/null 2>&1
if [ -n "$srv" ]; then
if [ -f /etc/rc.d/init.d/$srv ] || [ -f /etc/xinetd.d/$srv ]; then
/sbin/chkconfig --del $srv
fi
fi
fi
# del-service ends here
|