Skip to content

Commit 71e88b4

Browse files
authored
Merge pull request #3262 from bluca/sysusers
Install sysusers.d config for user/group
2 parents d4b89ab + 57f62f6 commit 71e88b4

File tree

8 files changed

+112
-7
lines changed

8 files changed

+112
-7
lines changed

Makefile.am

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ DISTCHECK_CONFIGURE_FLAGS = ${DISTCHECK_FLAGS} \
496496
--with-systemdsystempresetdir='$${prefix}/usr/lib/systemd/system-preset' \
497497
--with-systemdshutdowndir='$${prefix}/lib/systemd/system-shutdown' \
498498
--with-systemdtmpfilesdir='$${prefix}/usr/lib/tmpfiles.d' \
499+
--with-systemdsysusersdir='$${prefix}/usr/lib/sysusers.d' \
499500
--with-augeas-lenses-dir='$${prefix}/usr/share/augeas/lenses' \
500501
--with-hotplug-dir='$${prefix}/etc/hotplug' \
501502
--with-udev-dir='$${prefix}/etc/udev' \
@@ -1262,6 +1263,12 @@ else !WITH_SYSTEMD_TMPFILES
12621263
WITH_SYSTEMD_TMPFILES = false
12631264
endif !WITH_SYSTEMD_TMPFILES
12641265

1266+
if WITH_SYSTEMD_SYSUSERS
1267+
WITH_SYSTEMD_SYSUSERS = true
1268+
else !WITH_SYSTEMD_SYSUSERS
1269+
WITH_SYSTEMD_SYSUSERS = false
1270+
endif !WITH_SYSTEMD_SYSUSERS
1271+
12651272
if WITH_SYSTEMD_PRESET
12661273
WITH_SYSTEMD_PRESET = true
12671274
else !WITH_SYSTEMD_PRESET
@@ -1413,6 +1420,10 @@ install-as-root:
14131420
echo "$@: Apply systemd-tmpfiles presets" >&2 ; \
14141421
$(SYSTEMD_TMPFILES_PROGRAM) --create || exit ; \
14151422
fi ; \
1423+
if $(WITH_SYSTEMD_SYSUSERS) ; then \
1424+
echo "$@: Apply systemd-sysusers presets" >&2 ; \
1425+
$(SYSTEMD_SYSUSERS_PROGRAM) || exit ; \
1426+
fi ; \
14161427
echo "$@: Learn systemd definition changes" >&2 ; \
14171428
$(SYSTEMD_SYSTEMCTL_PROGRAM) daemon-reload || exit ; \
14181429
APPLIED_SYSTEMD_PRESET=false ; \

NEWS.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ several `FSD` notifications into one executed action. [PR #3097]
338338
prefer a `python3` if available, else `python2`, else `python`. [#1792]
339339
* The `configure` script should now try harder to report specifically
340340
the "purelib" location as `PYTHON*_SITE_PACKAGES`. [#1209]
341+
* Added a `--with-systemdsysusersdir=PATH` option to have systemd pre-create
342+
the user and group accounts for NUT, before packaging or manually executed
343+
commands do (this is particularly important for immutable-image operating
344+
environments). [PR #3262]
341345
* Streamlined handling of `--with-*` and `--enable-*` options using NUT 'm4'
342346
macros; fixed reporting help for options whose defaults are evaluated.
343347
[issue #3049, PR #3140]

autogen.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ if [ ! -f scripts/systemd/nut-common-tmpfiles.conf.in ]; then
150150
) > scripts/systemd/nut-common-tmpfiles.conf.in
151151
fi
152152

153+
if [ ! -f scripts/systemd/nut-common-sysusers.conf.in ]; then
154+
( echo '# autoconf requires this file exists before generating configure script;'
155+
echo '# it will be overwritten by running configure during an actual build'
156+
) > scripts/systemd/nut-common-sysusers.conf.in
157+
fi
158+
153159
# now we can safely call autoreconf
154160
if ( command -v dos2unix ) 2>/dev/null >/dev/null ; then
155161
if ( dos2unix < configure.ac | cmp - configure.ac ) 2>/dev/null >/dev/null ; then

configure.ac

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5114,6 +5114,46 @@ dnl What pathname would we embed into unit files ExecStartPre?
51145114
dnl TODO? Any need to make it a --with-... argument?
51155115
AC_PATH_PROG([SYSTEMD_TMPFILES_PROGRAM], [systemd-tmpfiles], [/usr/bin/systemd-tmpfiles])
51165116

5117+
dnl Note: same as (systemd-)tmpfiles
5118+
AC_MSG_CHECKING([whether to install sysusers.d files])
5119+
NUT_ARG_WITH([systemdsysusersdir], [(DIRPATH|yes|no|auto)], [Directory for systemd sysusers.d scripts], [auto])
5120+
systemdsysusersdir="${nut_with_systemdsysusersdir}"
5121+
5122+
case "${systemdsysusersdir}" in
5123+
yes|auto|"")
5124+
AS_IF([test x"$have_PKG_CONFIG" = xyes],
5125+
[def_systemdsysusersdir="`$PKG_CONFIG --variable=sysusersdir systemd 2>/dev/null`" && test -n "$def_systemdsysusersdir" || \
5126+
def_systemdsysusersdir="`$PKG_CONFIG --variable=sysusersdir libsystemd 2>/dev/null`" || def_systemdsysusersdir=""],
5127+
[def_systemdsysusersdir=""])
5128+
5129+
AS_IF([test x"${def_systemdsysusersdir}" = x], [
5130+
AS_IF([test "${systemdsysusersdir}" = yes],
5131+
[AC_MSG_ERROR([--with-systemdsysusersdir=${systemdsysusersdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
5132+
systemdsysusersdir=""
5133+
], [systemdsysusersdir="${def_systemdsysusersdir}"])
5134+
5135+
unset def_systemdsysusersdir
5136+
;;
5137+
no)
5138+
systemdsysusersdir=""
5139+
;;
5140+
*)
5141+
AS_IF([test -d "${systemdsysusersdir}"], [],
5142+
[AC_MSG_WARN([--with-systemdsysusersdir='${systemdsysusersdir}' was requested, but that location does not currently exist in build environment - just so you know...])])
5143+
;;
5144+
esac
5145+
if test "${systemdsysusersdir}" = "auto" ; then systemdsysusersdir=""; fi
5146+
if test -n "${systemdsysusersdir}"; then
5147+
AC_MSG_RESULT(using ${systemdsysusersdir})
5148+
NUT_REPORT_PATH_INTEGRATIONS([Systemd-sysusers configs], [${systemdsysusersdir}])
5149+
else
5150+
AC_MSG_RESULT(no)
5151+
fi
5152+
AM_CONDITIONAL([WITH_SYSTEMD_SYSUSERS], [test x"${systemdsysusersdir}" != "x"])
5153+
dnl What pathname would we embed into unit files ExecStartPre?
5154+
dnl TODO? Any need to make it a --with-... argument?
5155+
AC_PATH_PROG([SYSTEMD_SYSUSERS_PROGRAM], [systemd-sysusers], [/usr/bin/systemd-sysusers])
5156+
51175157

51185158
dnl Note: we may want binaries with sd_notify and similar features regardless
51195159
dnl of building and delivering unit files (which may be crafted separately).
@@ -6207,6 +6247,7 @@ AC_SUBST(systemdsystemunitdir)
62076247
AC_SUBST(systemdsystempresetdir)
62086248
AC_SUBST(systemdshutdowndir)
62096249
AC_SUBST(systemdtmpfilesdir)
6250+
AC_SUBST(systemdsysusersdir)
62106251
AC_SUBST(auglensdir)
62116252
AC_SUBST(auglenstestsdir)
62126253
AC_SUBST(hotplugdir)
@@ -6685,6 +6726,39 @@ EOF])
66856726
])
66866727
AC_MSG_RESULT([done])
66876728

6729+
dnl ---------------------------------------------------------------------
6730+
AC_MSG_CHECKING([whether to customize ${TOP_BUILDDIR}/scripts/systemd/nut-common-sysusers.conf.in for this system])
6731+
AS_IF([test -n "$systemdsysusersdir"],
6732+
[mkdir -p "${TOP_BUILDDIR}"/scripts/systemd
6733+
cat > "${TOP_BUILDDIR}"/scripts/systemd/nut-common-sysusers.conf.in << EOF
6734+
# Network UPS Tools (NUT) systemd integration
6735+
# Distributed under the terms of GPLv2+
6736+
# See https://networkupstools.org/
6737+
# and https://github.com/networkupstools/nut/
6738+
EOF
6739+
AS_IF([test -n "${RUN_AS_USER}" && test x"${RUN_AS_USER}" != xnobody && test x"${RUN_AS_USER}" != xroot],
6740+
dnl Locked users ('!') are supported since v257
6741+
AS_IF([test x"$have_PKG_CONFIG" = xyes && $PKG_CONFIG --atleast-version=257 systemd 2>/dev/null], [
6742+
cat >> "${TOP_BUILDDIR}"/scripts/systemd/nut-common-sysusers.conf.in << EOF
6743+
u! @RUN_AS_USER@ - - @STATEPATH@
6744+
EOF
6745+
], [
6746+
cat >> "${TOP_BUILDDIR}"/scripts/systemd/nut-common-sysusers.conf.in << EOF
6747+
u @RUN_AS_USER@ - - @STATEPATH@
6748+
EOF
6749+
])
6750+
)
6751+
AS_IF([test -n "${RUN_AS_GROUP}" && test x"${RUN_AS_GROUP}" != xnobody && test x"${RUN_AS_GROUP}" != xnogroup && test x"${RUN_AS_GROUP}" != xroot],
6752+
[cat >> "${TOP_BUILDDIR}"/scripts/systemd/nut-common-sysusers.conf.in << EOF
6753+
g @RUN_AS_GROUP@
6754+
EOF])
6755+
AS_IF([test -n "${RUN_AS_USER}" && test x"${RUN_AS_USER}" != xnobody && test x"${RUN_AS_USER}" != xroot && test -n "${RUN_AS_GROUP}" && test x"${RUN_AS_GROUP}" != xnobody && test x"${RUN_AS_GROUP}" != xnogroup && test x"${RUN_AS_GROUP}" != xroot],
6756+
[cat >> "${TOP_BUILDDIR}"/scripts/systemd/nut-common-sysusers.conf.in << EOF
6757+
m @RUN_AS_USER@ @RUN_AS_GROUP@
6758+
EOF])
6759+
])
6760+
AC_MSG_RESULT([done])
6761+
66886762
dnl # ccache versions 4.5 and newer support namespacing of the objects
66896763
dnl # to facilitate more targeted eviction with --evict-namespace and
66906764
dnl # perhaps --evict-older-than options. Here we bolt a namespace with
@@ -6888,6 +6962,7 @@ AC_CONFIG_FILES([
68886962
scripts/systemd/Makefile
68896963
scripts/systemd/nut.target
68906964
scripts/systemd/nut-common-tmpfiles.conf
6965+
scripts/systemd/nut-common-sysusers.conf
68916966
scripts/systemd/nut-driver.target
68926967
scripts/systemd/nut-driver@.service
68936968
scripts/systemd/nut-logger.service

docs/configure.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,13 @@ Use `--with-systemdshutdowndir` to detect the settings using pkg-config.
11231123
Use `--with-systemdshutdowndir=no` to disable this feature altogether.
11241124

11251125
--with-systemdtmpfilesdir=PATH
1126+
--with-systemdsysusersdir=PATH
11261127

1127-
Where to install Linux systemd configuration for tmpfiles handling (the
1128-
automatically created locations for PID, state and similar run-time files).
1129-
Useless and harmless on other OSes, including Linux distributions
1130-
without systemd, just adding a little noise to configure script output.
1128+
Where to install Linux systemd configuration for tmpfiles and sysusers
1129+
handling (the automatically created locations for user/group, PID,
1130+
state and similar run-time files). Useless and harmless on other OSes,
1131+
including Linux distributions without systemd, just adding a little
1132+
noise to configure script output.
11311133

11321134
Use `--with-systemdtmpfilesdir` to detect the settings using pkg-config.
11331135

docs/nut.dict

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,8 +3284,10 @@ systemd
32843284
systemdshutdowndir
32853285
systemdsystempresetdir
32863286
systemdsystemunitdir
3287+
systemdsysusersdir
32873288
systemdtmpfilesdir
32883289
systemtest
3290+
sysusers
32893291
sysutils
32903292
sysvinit
32913293
tagname

scripts/systemd/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Note: nut-common-tmpfiles.conf.in is also generated, by configure script
1+
# Note: nut-common-tmpfiles.conf.in/nut-common-sysusers.conf.in are also generated, by configure script
22
/nut-common-tmpfiles.conf.in
33
/nut-common-tmpfiles.conf
4+
/nut-common-sysusers.conf.in
5+
/nut-common-sysusers.conf
46
/nut.target
57
# Singular nut-driver.service is obsolete, help with old build workspaces:
68
/nut-driver.service

scripts/systemd/Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ endif !WITH_LIBSYSTEMD_INHIBITOR
2626
systemdtmpfiles_DATA = \
2727
nut-common-tmpfiles.conf
2828

29+
systemdsysusers_DATA = \
30+
nut-common-sysusers.conf
31+
2932
systemdsystempreset_DATA = \
3033
nut-systemd.preset
3134

@@ -50,7 +53,7 @@ EXTRA_DIST += \
5053
nut-driver-enumerator-daemon-activator.service.in \
5154
nut-driver-enumerator-daemon.service.in
5255

53-
# NOTE: Do not EXTRA_DIST nut-common-tmpfiles.conf.in - it is generated per build
56+
# NOTE: Do not EXTRA_DIST nut-common-tmpfiles.conf.in/nut-common-sysusers.conf.in - they are generated per build
5457
endif !HAVE_SYSTEMD
5558

5659
SPELLCHECK_SRC = README.adoc
@@ -80,4 +83,4 @@ CLEANFILES = *-spellchecked
8083
MAINTAINERCLEANFILES = Makefile.in .dirstamp
8184

8285
# Generated by autogen.sh and needed to run the configure script:
83-
MAINTAINERCLEANFILES += nut-common-tmpfiles.conf.in
86+
MAINTAINERCLEANFILES += nut-common-tmpfiles.conf.in nut-common-sysusers.conf.in

0 commit comments

Comments
 (0)