-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpp.back.systemd.svc
More file actions
263 lines (216 loc) · 10.2 KB
/
Copy pathpp.back.systemd.svc
File metadata and controls
263 lines (216 loc) · 10.2 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#@ pp_systemd_make_service_file(): create systemd service file
pp_systemd_make_service_file() {
local svc f
if [ "${pp_systemd_disabled:-false}" = "true" ]; then
return
fi
svc="$1"
f="${pp_systemd_service_dir:-/opt/quest/libexec/vas}/$svc.service"
pp_add_file_if_missing $f run 644 v || return 0
cat <<. >$pp_destdir$f
# Systemd unit file for $svc
[Unit]
Description=${pp_systemd_service_description:-"systemd service file for $svc"}
${pp_systemd_service_man:+"Documentation=$pp_systemd_service_man"}
${pp_systemd_service_documentation:+"Documentation=$pp_systemd_service_documentation"}
${pp_systemd_service_requires:+"Requires=$pp_systemd_service_requires"}
After=${pp_systemd_service_after:-"syslog.target network.target auditd.service"}
${pp_systemd_service_before:+"Before=$pp_systemd_service_before"}
${pp_systemd_service_wants:+"Wants=$pp_systemd_service_wants"}
${pp_systemd_service_conflicts:+"Conflicts=$pp_systemd_service_conflicts"}
[Service]
ExecStart=${pp_systemd_service_exec:-"/opt/quest/sbin/$svc"} ${pp_systemd_service_exec_args}
KillMode=${pp_systemd_service_killmode:-process}
Type=${pp_systemd_service_type:-forking}
${pp_systemd_service_pidfile:+"PIDFile=$pp_systemd_service_pidfile"}
[Install]
WantedBy=${pp_systemd_system_target:-"multi-user.target"}
.
}
#@ pp_systemd_service_init_common(): emit common code for install/uninstall
pp_systemd_service_init_common () {
cat <<.
_pp_systemd_init () {
systemd_service_dir=${pp_systemd_service_dir:-/opt/quest/libexec/vas}
systemd_target=${pp_systemd_system_target:-"multi-user.target"}
systemd_target_wants="\${systemd_target}.wants"
pkg_config_cmd=${pp_systemd_pkg_config_cmd:-"\$(command -v pkg-config)"}
systemctl_cmd=${pp_systemd_systemctl_cmd:-"\$(command -v systemctl)"}
# See if pkg-config is installed to get the default locations for this OS, if not installed then just use what we hard code.
# So far works on Debian 8, OpenSuse12.3, Ubuntu 16.04, RHEL 7.3
# See systemd wiki for more OS interactions https://en.wikipedia.org/wiki/Systemd
if [ -x "\$pkg_config_cmd" ]; then
systemd_system_unit_dir="\$(pkg-config systemd --variable=systemdsystemunitdir)"
systemd_system_conf_dir="\$(pkg-config systemd --variable=systemdsystemconfdir)"
fi
#if pkg-config does not exist or if the \$pkg_config_cmd command returns nothing
if test -z "\$systemd_system_unit_dir"; then
systemdsystemunitdirs="/lib/systemd/system /usr/lib/systemd/system"
for dir in \$systemdsystemunitdirs; do
if [ -d "\$dir/\$systemd_target_wants" ]; then
systemd_system_unit_dir="\$dir"
break
fi
done
fi
# In the case where \$systemd_system_conf_dir is empty hard code the path
if test -z "\$systemd_system_conf_dir"; then
systemd_system_conf_dir="/etc/systemd/system"
fi
# if the \$svc.pp file defines the systemd unit dir then use it.
${pp_systemd_system_unit_dir:+"# systemd_system_unit_dir defined by variable pp_systemd_system_unit_dir from the \$svc.pp file"}
systemd_system_unit_dir="${pp_systemd_system_unit_dir:-"\$systemd_system_unit_dir"}"
# if the \$svc.pp file defines the systemd conf dir then use it.
${pp_systemd_system_conf_dir:+"# systemd_system_conf_dir defined by variable pp_systemd_system_conf_dir from the \$svc.pp file"}
systemd_system_conf_dir="${pp_systemd_system_conf_dir:-"\$systemd_system_conf_dir"}"
}
.
}
#@ pp_systemd_service_install_common(): emit common code for service install
pp_systemd_service_install_common () {
if [ "${pp_systemd_disabled:-false}" = "true" ]; then
cat<<'.'
# systemd support disabled
_pp_systemd_init () {
return
}
_pp_systemd_install () {
return
}
_pp_systemd_enable () {
return
}
.
return
fi
pp_systemd_service_init_common
cat<<'.'
_pp_systemd_install () {
local svc="$1"
# If $systemctl_cmd is not set, then call _pp_systemd_init. If still not
# set, we do not know where the systemctl command is so do nothing;
# systemd must not be on this system.
if test -z "$systemctl_cmd"; then
_pp_systemd_init
fi
if test -x "$systemctl_cmd" && test -d "$systemd_system_conf_dir/$systemd_target_wants"; then
# If our service file still exists (upgrade) remove the link/file and systemctl
# will recreate it if/when we enable the $svc service.
rm -f "$systemd_system_conf_dir/$systemd_target_wants/$svc.service"
# Copy the $svc.service file to the correct systemd_system_unit_dir location
if [ "x$systemd_service_dir" != "x$systemd_system_unit_dir" ]; then
cp -f "$systemd_service_dir/$svc.service" "$systemd_system_unit_dir/$svc.service"
chmod 644 "$systemd_system_unit_dir/$svc.service"
fi
fi
}
_pp_systemd_enable () {
local svc="$1"
local RUNNING=0
# If $systemctl_cmd is not set, then call _pp_systemd_init. If still not
# set, we do not know where the systemctl command is so do nothing;
# systemd must not be on this system.
if test -z "$systemctl_cmd"; then
_pp_systemd_init
fi
if test -x "$systemctl_cmd" && test -f "$systemd_system_unit_dir/$svc.service"; then
# stop the daemon using the old init script before enabling systemd for the service
# we do this so we do not "orphan" the process. Because init started it and if we enable systemd
# it will not know about this process and will not be able to stop it.
if [ -x "/etc/init.d/$svc" ]; then
output="$(/etc/init.d/$svc status 2>&1)"
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
case "$output" in
*"not running"*)
# systemd is reporting the status (compatibility package is installed)
RUNNING=1
;;
*) # it is really running
/etc/init.d/$svc stop > /dev/null 2>&1
;;
esac
fi
fi
# If the service is not running according to its sysv script (eg. systemd service
# is not using a pidfile the sysv script needs), or its sysv script is not present any more,
# check how systemd thinks.
# We also try to restart the service in case something went wrong with it.
if $systemctl_cmd is-active "$svc" >/dev/null 2>&1 || $systemctl_cmd is-failed "$svc" >/dev/null 2>&1; then
$systemctl_cmd stop "$svc" >/dev/null 2>&1
RUNNING=0
fi
# Enable the $svc.service
$systemctl_cmd daemon-reload >/dev/null 2>&1
# We do not need the init.d script any more, and it causes problems on SLES
# where systemd sysv compatibility is enforced and broken on default installs
rm -f "/etc/init.d/$svc"
$systemctl_cmd enable $svc.service >/dev/null 2>&1
# Now that the service has been enabled, start it again if it was running before.
if [ $RUNNING -eq 0 ]; then
$systemctl_cmd start $svc.service >/dev/null 2>&1
fi
fi
}
.
}
#@ pp_systemd_service_remove_common(): emit common code for service removal
pp_systemd_service_remove_common () {
if [ "${pp_systemd_disabled:-false}" = "true" ]; then
cat<<'.'
# systemd support disabled
_pp_systemd_init () {
return
}
_pp_systemd_disable () {
return
}
_pp_systemd_remove () {
return
}
.
return
fi
pp_systemd_service_init_common
cat<<'.'
_pp_systemd_disable () {
local svc="$1"
# If $systemctl_cmd is not set, then call _pp_systemd_init.
# If still not set, we do not know where the systemctl command
# is so do nothing; systemd must not be on this system.
if test -z "$systemctl_cmd"; then
_pp_systemd_init
fi
systemd_service_file="$systemd_system_conf_dir/$systemd_target_wants/$svc.service"
# Remove systemd symlink (enabled) unit service file
if test -e $systemd_service_file; then
# Disable the $svc service
if test -x "$systemctl_cmd"; then
$systemctl_cmd disable $svc.service > /dev/null 2>&1
else
# For some reason systemctl is not install but our service file exists
# Just delete the symlink then
rm -f "$systemd_service_file"
fi
fi
}
_pp_systemd_remove () {
local svc="$1"
# If $systemctl_cmd is not set, then call _pp_systemd_init.
# If still not set, we do not know where the systemctl command
# is so do nothing; systemd must not be on this system.
if test -z "$systemctl_cmd"; then
_pp_systemd_init
fi
$systemctl_cmd stop $svc.service > /dev/null 2>&1
# Remove the systemd unit service file
if [ "x$systemd_service_dir" != "x$systemd_system_unit_dir" ]; then
rm -f "$systemd_system_unit_dir/$svc.service"
fi
if test -x "$systemctl_cmd"; then
$systemctl_cmd daemon-reload
$systemctl_cmd reset-failed $svc.service >/dev/null 2>&1 || true
fi
}
.
}