-
Notifications
You must be signed in to change notification settings - Fork 17
/
systemd.plugin
134 lines (109 loc) · 4.26 KB
/
systemd.plugin
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
#############################################################
# #
# systemd.plugin - handling of systemd service files #
# #
#############################################################
# #
# Copyright 2011 by Auke Kok under GPLv2 #
# Parts Copyrighted 2012 by Stefan Wold under GPLv2 #
# #
#############################################################
plugin_systemd_configure()
{
local SERVICES SERVICE SYSTEMD_SERVICES
debug_msg "plugin_systemd_configure ($@)"
if [ -d $SCRIPT_DIRECTORY/systemd.d ]; then
cd $SCRIPT_DIRECTORY/systemd.d
SERVICES=$(ls -1)
SYSTEMD_SERVICES=$(get_module_config SYSTEMD_SERVICES)
for SERVICE in $SERVICES; do
# don't ask for '@' services - these should always be installed but
# never linked directly. Also ask for new or renamed services.
if echo $SERVICE | grep -q @ || echo $SYSTEMD_SERVICES | egrep -q "(^| )$SERVICE( |$)"; then
continue
fi
message "${MESSAGE_COLOR}$SERVICE: $(grep Description= $SERVICE | cut -d= -f2-)${DEFAULT_COLOR}"
if query "Invoke $SERVICE via systemd automatically at boot ?" y
then
SYSTEMD_SERVICES+=" $SERVICE"
else
# ignore output here - this is likely to hit "not found" errors
systemctl disable $SERVICE > /dev/null 2>&1
systemctl stop $SERVICE > /dev/null 2>&1
fi
done
cd $SCRIPT_DIRECTORY
# Look for renamed or removed services and stop and disable them.
# If we don't do it here it will be too late and there will be rogue
# processes left behind after a successful install
for SERVICE in $SYSTEMD_SERVICES; do
if ! echo $SERVICES | egrep -q "(^| )$SERVICE( |$)"; then
verbose_msg "Stopping removed service ($SERVICE)"
systemctl stop $SERVICE &> /dev/null
systemctl disable $SERVICE &> /dev/null
SYSTEMD_SERVICES=$(echo $SYSTEMD_SERVICES | sed -r "s;(^| )$SERVICE( |$);\1;")
fi
done
set_module_config "SYSTEMD_SERVICES" "$SYSTEMD_SERVICES"
fi
return 2
}
plugin_systemd_post_build()
{
local SERVICES SERVICE SYSTEMDUNITDIR
debug_msg "plugin_systemd_post_build ($@)"
local SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
if [ -d $SCRIPT_DIRECTORY/systemd.d ]; then
invoke_installwatch
verbose_msg "handling systemd.d services" | tee -a $C_LOG
cd $SCRIPT_DIRECTORY/systemd.d
SERVICES=$(ls -1)
for SERVICE in $SERVICES; do
/usr/bin/install -g 0 -o 0 -m 0644 $SERVICE $SYSTEMDUNITDIR/$SERVICE
done
cd $SCRIPT_DIRECTORY
devoke_installwatch
fi
systemctl daemon-reload > /dev/null 2>&1
for SERVICE in $SYSTEMD_SERVICES; do
systemctl disable $SERVICE
invoke_installwatch
systemctl enable $SERVICE
devoke_installwatch
# start-or-restart it
if [ "${LUNAR_RESTART_SERVICES:=on}" == "on" ]; then
systemctl restart $SERVICE
fi
done
return 2
}
plugin_systemd_tmpfilesd_post_build() {
local FILE SYSTEMDTEMPFILES
debug_msg "plugin_systemd_tmpfilesd_post_build ($@)"
SYSTEMDTEMPFILES=$(pkg-config systemd --variable=prefix)/lib/tmpfiles.d
if [ -d $SCRIPT_DIRECTORY/tmpfiles.d ]; then
invoke_installwatch
verbose_msg "handling systemd tmpfiles.d files"
for FILE in $SCRIPT_DIRECTORY/tmpfiles.d/*; do
/usr/bin/install -g 0 -o 0 -m 0644 $FILE $SYSTEMDTEMPFILES/
done
devoke_installwatch
fi
return 2
}
plugin_systemd_disable_services_pre_remove() {
local SYSTEMD_SERVICES
debug_msg "plugin_systemd_disable_services_pre_remove ($@)"
SYSTEMD_SERVICES=$(get_module_config SYSTEMD_SERVICES)
for SERVICE in $SYSTEMD_SERVICES; do
verbose_msg "Stopping and disabling systemd service ($SERVICE)"
systemctl stop $SERVICE &> /dev/null
systemctl disable $SERVICE &> /dev/null
done
return 2
}
plugin_register BUILD_CONFIGURE plugin_systemd_configure
plugin_register BUILD_POST_BUILD plugin_systemd_post_build
plugin_register BUILD_POST_BUILD plugin_systemd_tmpfilesd_post_build
plugin_register BUILD_PRE_REMOVE plugin_systemd_disable_services_pre_remove