aboutsummaryrefslogtreecommitdiffstats
path: root/add-service
blob: 46a98ac50aca633ebe4f3fb240e38f09ad98af5b (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
105
106
107
108
109
110
111
112
#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandriva Linux
# Module          : rpm-helper
# File            : add-service
# Version         : $Id$
# Author          : Frederic Lepied
# Created On      : Mon Jul  8 08:14:34 2002
# Purpose         : helper script for rpm scriptlets to add a
#		    service.
#---------------------------------------------------------------

if [ $# != 3 ]; then
    echo "usage: $0 <pkg name> <number installed> <service name>" 1>&2
    exit 1
fi

pkg=$1				# name of the package
num=$2				# number of packages installed
srv=$3				# name of the service

systemd=no
sysv=no
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


    # support for systemd. chkconfig will do daemon-reload for us
    if [ $systemd = yes ]; then
	/bin/systemctl $options enable ${unit}
    fi
    if [ $sysv = yes ]; then
	/sbin/chkconfig --add $srv
    fi

    if [ -r /etc/sysconfig/system ]; then
	. /etc/sysconfig/system
    fi

    if [ -z "$ADD_SERVICES_TO_CURRENT_PROFILE_ONLY" ]; then
	# add the service to all the profiles at once
	if [ -d /etc/netprofile/profiles/default/services ]; then
	    for dir in /etc/netprofile/profiles/*/services; do
		touch $dir/$srv
	    done
	fi
    fi
}

add_service() {
    # Add the service
    if [ -r /etc/sysconfig/msec ]; then
	. /etc/sysconfig/msec
    fi
    
    # High security: add only authorized services
    LIST=/etc/security/msec/server

    # during the install the symlink isn't done so find the right file
    # by ourselves
    if [ -n "$DURING_INSTALL" -a ! -f $LIST ]; then
	LIST=/etc/security/msec/server.$SECURE_LEVEL
    fi

    if [ -f $LIST ]; then
	if grep -q "^${srv}$" $LIST ; then
	    add_chkconfig_service $srv
	fi
    else
	# Low security: install all the services
	add_chkconfig_service $srv
    fi
}

if [ $num = 1 ]; then
    # First install mode
    add_service
else
    # Upgrade mode.

    # if the service is activated, add it again to be able to handle
    # 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 [ $sysv = yes ]; then
	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

	# restart the service if already running
	if [ -f /var/lock/subsys/$srv ]; then
	    /sbin/service $srv restart > /dev/null || :
	fi
    fi
fi

# add-service ends here