File macros.systemd of Package systemd-rpm-macros
355
1
# -*- Mode: rpm-spec; indent-tabs-mode: t -*- */
2
# RPM macros for packages installing systemd unit files
3
#
4
###
5
#
6
# When a package install systemd unit files, it should use the
7
# following macros:
8
#
9
# add %systemd_requires in the specfile
10
#
11
# %pre
12
# %service_add_pre demo.service demo1.service
13
#
14
# %post
15
# %service_add_post demo.service demo1.service
16
#
17
# %preun
18
# %service_del_preun demo.service
19
#
20
# %postun
21
# %service_del_postun demo.service
22
# %service_del_postun_with_restart demo.service
23
# %service_del_postun_without_restart demo.service
24
#
25
# Note: the upstream variants are also available and are aliases to
26
# their SUSE counterparts. However for consistency the SUSE macros
27
# should be preferred unless the package is intended to be portable
28
# across multiple distributions based on RPM.
29
30
%_systemd_util_dir /usr/lib/systemd
31
%_unitdir /usr/lib/systemd/system
32
%_userunitdir /usr/lib/systemd/user
33
%_presetdir /usr/lib/systemd/system-preset
34
%_userpresetdir /usr/lib/systemd/user-preset
35
%_udevhwdbdir /usr/lib/udev/hwdb.d
36
%_udevrulesdir /usr/lib/udev/rules.d
37
%_journalcatalogdir /usr/lib/systemd/catalog
38
%_tmpfilesdir /usr/lib/tmpfiles.d
39
%_sysusersdir /usr/lib/sysusers.d
40
%_sysctldir /usr/lib/sysctl.d
41
%_ntpunitsdir /usr/lib/systemd/ntp-units.d
42
%_binfmtdir /usr/lib/binfmt.d
43
%_environmentdir /usr/lib/environment.d
44
%_modulesloaddir /usr/lib/modules-load.d
45
%_modprobedir /lib/modprobe.d
46
%_systemdgeneratordir /usr/lib/systemd/system-generators
47
%_systemdusergeneratordir /usr/lib/systemd/user-generators
48
%_systemd_system_env_generator_dir /usr/lib/systemd/system-environment-generators
49
%_systemd_user_env_generator_dir /usr/lib/systemd/user-environment-generators
50
51
%systemd_requires \
52
Requires(pre): systemd \
53
Requires(post): systemd \
54
Requires(preun): systemd \
55
Requires(postun): systemd \
56
Suggests: systemd-sysvcompat \
57
%{nil}
58
59
# In case you're wondering why "Suggests:" is also used: libzypp
60
# doesn't understand "OrderWithRequires:" yet, see bsc#1187332 for
61
# details.
62
%systemd_ordering \
63
OrderWithRequires(pre): systemd \
64
OrderWithRequires(post): systemd \
65
OrderWithRequires(preun): systemd \
66
OrderWithRequires(postun): systemd \
67
Suggests: systemd systemd-sysvcompat \
68
%{nil}
69
70
%_restart_on_update_force() \
71
%{warn: '-f' with %%service_del_postun is deprecated, use %%service_del_postun_with_restart instead} \
72
(\
73
test "$YAST_IS_RUNNING" = instsys && exit 0 \
74
%{?*:/usr/bin/systemctl try-restart %{*}} \
75
) || : \
76
%{nil}
77
78
%_restart_on_update_never() \
79
%{warn: '-n' with %%service_del_postun is deprecated, use %%service_del_postun_without_restart instead} \
80
%{?*: : # Restart of %{*} skipped} \
81
%{nil}
82
83
%_restart_on_update() (\
84
test "$YAST_IS_RUNNING" = instsys && exit 0\
85
test -f /etc/sysconfig/services -a \\\
86
-z "$DISABLE_RESTART_ON_UPDATE" && . /etc/sysconfig/services\
87
test "$DISABLE_RESTART_ON_UPDATE" = yes -o \\\
88
"$DISABLE_RESTART_ON_UPDATE" = 1 && exit 0\
89
%{?*:/usr/bin/systemctl try-restart %{*}}\
90
) || : %{nil}
91
92
%_stop_on_removal_force() \
93
%{warn: '-f' with %%service_del_preun is deprecated, please dont use it anymore} \
94
( \
95
test "$YAST_IS_RUNNING" = instsys && exit 0\
96
%{?*:/usr/bin/systemctl stop %{*}}\
97
) || : \
98
%{nil}
99
100
%_stop_on_removal_never() \
101
%{warn: '-n' with %%service_del_preun is unsafe, please dont use it anymore} \
102
%{?*: : # Stop of %{*} skipped} \
103
%{nil}
104
105
%_stop_on_removal() (\
106
test "$YAST_IS_RUNNING" = instsys && exit 0\
107
test -f /etc/sysconfig/services -a \\\
108
-z "$DISABLE_STOP_ON_REMOVAL" && . /etc/sysconfig/services\
109
test "$DISABLE_STOP_ON_REMOVAL" = yes -o \\\
110
"$DISABLE_STOP_ON_REMOVAL" = 1 && exit 0\
111
%{?*:/usr/bin/systemctl stop %{*}}\
112
) || : %{nil}
113
114
# Figure out when presets need to be applied. This information is only
115
# recorded during %pre and is actually applied during %post.
116
#
117
# Presets might need to be applied during package install but also
118
# during package update. On update, packages might introduce new
119
# services but we need to make sure that's not happening during the
120
# migration of SysV initscripts. On package install, presets might
121
# have been already applied because of package renaming or split.
122
#
123
%service_add_pre() \
124
if [ -x /usr/bin/systemctl ]; then \
125
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
126
[ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || : \
127
\
128
for service in %{?*} ; do \
129
sysv_service=${service%.*} \
130
\
131
if [ ! -e /usr/lib/systemd/system/$service ] && \
132
[ ! -e /etc/init.d/$sysv_service ]; then \
133
mkdir -p /run/systemd/rpm/needs-preset \
134
touch /run/systemd/rpm/needs-preset/$service \
135
\
136
elif [ -e /etc/init.d/$sysv_service ] && \
137
[ ! -e /var/lib/systemd/migrated/$sysv_service ]; then \
138
/usr/sbin/systemd-sysv-convert --save $sysv_service || : \
139
mkdir -p /run/systemd/rpm/needs-sysv-convert \
140
touch /run/systemd/rpm/needs-sysv-convert/$service \
141
fi \
142
done \
143
fi \
144
%{nil}
145
146
# Apply the presets if %pre told us to do so.
147
#
148
%service_add_post() \
149
if [ -x /usr/bin/systemctl ]; then \
150
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
151
[ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || : \
152
\
153
if [ "$YAST_IS_RUNNING" != "instsys" ]; then \
154
/usr/bin/systemctl daemon-reload || : \
155
fi \
156
for service in %{?*} ; do \
157
sysv_service=${service%.*} \
158
\
159
if [ -e /run/systemd/rpm/needs-preset/$service ]; then \
160
/usr/bin/systemctl preset $service || : \
161
rm "/run/systemd/rpm/needs-preset/$service" || : \
162
\
163
elif [ -e /run/systemd/rpm/needs-sysv-convert/$service ]; then \
164
/usr/sbin/systemd-sysv-convert --apply $sysv_service || : \
165
rm "/run/systemd/rpm/needs-sysv-convert/$service" || : \
166
touch /var/lib/systemd/migrated/$sysv_service || : \
167
fi \
168
done \
169
fi \
170
%{nil}
171
172
# On removal, tell systemd to stop service
173
#
174
# Deprecated options, please do not use in new code:
175
# -f : force service stop on removal (deprecated, will be the default)
176
# -n : do not stop service on removal (unsafe, do not use)
177
#
178
# The default is to check for DISABLE_STOP_ON_REMOVAL environment
179
# variable if not found use the value read from /etc/sysconfig/services.
180
#
181
# NOTE: the default behavior is deprecated and DISABLE_STOP_ON_REMOVAL
182
# support will be removed soon, please do NOT rely on it anymore.
183
#
184
%service_del_preun(fn) \
185
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
186
if [ "$FIRST_ARG" -eq 0 -a -x /usr/bin/systemctl ]; then \
187
# Package removal, not upgrade \
188
/usr/bin/systemctl --no-reload disable %{?*} || : \
189
%{expand:%%_stop_on_removal%{-f:_force}%{!-f:%{-n:_never}} %{?*}} \
190
fi \
191
%{nil}
192
193
# On uninstall, tell systemd to reload its unit files.
194
# On update, tell systemd to reload its unit files but don't restart service.
195
#
196
%service_del_postun_without_restart() \
197
if [ $1 -eq 0 ]; then \
198
# Package removal \
199
for service in %{?*} ; do \
200
sysv_service="${service%.*}" \
201
rm -f "/var/lib/systemd/migrated/$sysv_service" || : \
202
done \
203
fi \
204
if [ -x /usr/bin/systemctl ]; then \
205
/usr/bin/systemctl daemon-reload || : \
206
fi \
207
%{nil}
208
209
# On uninstall, tell systemd to reload its unit files.
210
# On update, tell systemd to reload its unit files and restart service.
211
#
212
# It ignores the content of /etc/sysconfig/services
213
#
214
%service_del_postun_with_restart() \
215
if [ -x /usr/bin/systemctl ]; then \
216
/usr/bin/systemctl daemon-reload || : \
217
if [ $1 -ge 1 ]; then \
218
# Package upgrade, not uninstall \
219
/usr/bin/systemctl try-restart %{?*} || : \
220
fi \
221
fi \
222
%{nil}
223
224
# On uninstall, tell systemd to reload its unit files
225
#
226
# Deprecated options, please do not use in new code:
227
# -f : force restart on update (replaced by %service_del_postun_with_restart)
228
# -n : don't restart on update (replaced by %service_del_postun_without_restart)
229
#
230
# The default is to read DISABLE_RESTART_ON_UPDATE from /etc/sysconfig/services
231
#
232
%service_del_postun(fn) \
233
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
234
%service_del_postun_without_restart %{?*} \
235
if [ "$FIRST_ARG" -ge 1 ]; then \
236
# Package upgrade, not uninstall \
237
if [ -x /usr/bin/systemctl ]; then \
238
%{expand:%%_restart_on_update%{-f:_force}%{!-f:%{-n:_never}} %{?*}} \
239
fi \
240
fi \
241
%{nil}
242
243
#
244
# Upstream variants
245
#
246
247
%systemd_pre() %{expand::%%service_add_pre %{?**}}
248
%systemd_post() %{expand::%%service_add_post %{?**}}
249
%systemd_preun() %{expand::%%service_del_preun %{?**}}
250
%systemd_postun() %{expand::%%service_del_postun_without_restart %{?**}}
251
%systemd_postun_with_restart() %{expand::%%service_del_postun %{?**}}
252
253
%systemd_user_pre() \
254
if [ -x /usr/bin/systemctl ]; then \
255
for service in %{?*} ; do \
256
if [ ! -e "/usr/lib/systemd/user/$service" ]; then \
257
mkdir -p /run/systemd/rpm/needs-user-preset \
258
touch "/run/systemd/rpm/needs-user-preset/$service" \
259
fi \
260
done \
261
fi \
262
%{nil}
263
264
%systemd_user_post() \
265
if [ -x /usr/bin/systemctl ]; then \
266
for service in %{?*} ; do \
267
if [ -e "/run/systemd/rpm/needs-user-preset/$service" ]; then \
268
/usr/bin/systemctl --global preset "$service" || : \
269
rm "/run/systemd/rpm/needs-user-preset/$service" || : \
270
fi \
271
done \
272
fi \
273
%{nil}
274
275
%systemd_user_preun() \
276
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
277
# Package removal, not upgrade \
278
/usr/bin/systemctl --global disable %{?*} || : \
279
fi \
280
%{nil}
281
282
%systemd_user_postun() %{nil}
283
%systemd_user_postun_with_restart() %{nil}
284
285
%udev_hwdb_update() \
286
[ -x /usr/bin/systemd-hwdb ] && /usr/bin/systemd-hwdb update || : \
287
%{nil}
288
289
%udev_rules_update() \
290
[ -x /usr/bin/udevadm ] && /usr/bin/udevadm control --reload || : \
291
%{nil}
292
293
%journal_catalog_update() \
294
[ -x /usr/bin/journalctl ] && /usr/bin/journalctl --update-catalog || : \
295
%{nil}
296
297
%tmpfiles_create() \
298
[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && \
299
/usr/bin/systemd-tmpfiles --create %{?*} || : \
300
%{nil}
301
302
# This should be used by package installation scripts which doesn't require
303
# users or groups to be present before the files installed by the package are
304
# present on disk and when the sysusers conf files are generated during the
305
# build of the package hence not easily available before the build of the
306
# package.
307
#
308
# This macro will go away when this will be moved to file triggers.
309
#
310
# Example:
311
# %post
312
# %sysusers_create %{name}.conf
313
# %files
314
# %{_sysusersdir}/%{name}.conf
315
#
316
%sysusers_create() \
317
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers %{?*} || : \
318
%{nil}
319
320
%sysusers_create_inline() \
321
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers - <<SYSTEMD_INLINE_EOF || : \
322
%{?*} \
323
SYSTEMD_INLINE_EOF\
324
%{nil}
325
326
# This should be used by package installation scripts which require users or
327
# groups to be present before the files installed by the package are present on
328
# disk (for example because some files are owned by those users or groups).
329
#
330
# Example:
331
# Source1: %{name}-sysusers.conf
332
# ...
333
# %install
334
# install -D %SOURCE1 %{buildroot}%{_sysusersdir}/%{name}.conf
335
# %pre
336
# %sysusers_create_package %{name} %SOURCE1
337
# %files
338
# %{_sysusersdir}/%{name}.conf
339
#
340
%sysusers_create_package() \
341
/usr/bin/systemd-sysusers --replace=%_sysusersdir/%1.conf - <<SYSTEMD_INLINE_EOF || : \
342
%(cat %2) \
343
SYSTEMD_INLINE_EOF\
344
%{nil}
345
346
%sysctl_apply() \
347
[ -d /run/systemd/system ] && [ -x /usr/lib/systemd/systemd-sysctl ] && \
348
/usr/lib/systemd/systemd-sysctl %{?*} || : \
349
%{nil}
350
351
%binfmt_apply() \
352
[ -d /run/systemd/system ] && [ -x /usr/lib/systemd/systemd-binfmt ] && \
353
/usr/lib/systemd/systemd-binfmt %{?*} || : \
354
%{nil}
355