package/systemd: use host-systemctl preset all to enable units

since v234 upstream recommands using systemctl preset-all to enable units.
* add a buildroot specific preset file
* use that file to disable getty@tty1
* make systemd depend on host-systemd
* remove all link-creating code that systemd does for us.

Most packages will not be affected by this change, but a few packages
were installing units without manually enabling them. Those packages
will now be automatically enabled.

The fact that those packages were not enabled is almost certainly a bug,
but it is a change of behaviour that needs to be reported

host-systemd also builds udevadm for the host. That means we no longer
need to depend on host-eudev to provide udevadm (that would conflict).

Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr>
[yann.morin.1998@free.fr:
  - also remove the hwdb sources on fs generation
  - fix check-package errors
  - few typoes and reformatting in commit log
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Jérémy Rosen 2019-12-16 11:30:41 +01:00 committed by Yann E. MORIN
parent 873e6573d3
commit 231ad359bc
4 changed files with 29 additions and 93 deletions

View File

@ -550,6 +550,10 @@ different steps of the build process.
is when openrc is chosen as init system and +LIBFOO_INSTALL_INIT_OPENRC+ is when openrc is chosen as init system and +LIBFOO_INSTALL_INIT_OPENRC+
has not been set, in such situation +LIBFOO_INSTALL_INIT_SYSV+ will has not been set, in such situation +LIBFOO_INSTALL_INIT_SYSV+ will
be called, since openrc supports sysv init scripts. be called, since openrc supports sysv init scripts.
When systemd is used as the init system, buildroot will automatically enable
all services using the +systemctl preset-all+ command in the final phase of
image building. You can add preset files to prevent a particular unit from
being automatically enabled by buildroot.
* +LIBFOO_HELP_CMDS+ lists the actions to print the package help, which * +LIBFOO_HELP_CMDS+ lists the actions to print the package help, which
is included to the main +make help+ output. These commands can print is included to the main +make help+ output. These commands can print

View File

@ -0,0 +1,5 @@
# Higher priority than systemd presets
# by default systemd enables a getty on tty1
# we don't want that because tty1 may not exist
disable getty@.service

View File

@ -35,6 +35,7 @@ menuconfig BR2_PACKAGE_SYSTEMD
select BR2_PACKAGE_KMOD_TOOLS select BR2_PACKAGE_KMOD_TOOLS
select BR2_TARGET_TZ_INFO select BR2_TARGET_TZ_INFO
select BR2_NEEDS_HOST_UTF8_LOCALE select BR2_NEEDS_HOST_UTF8_LOCALE
select BR2_PACKAGE_HOST_SYSTEMD # for systemctl preset-all, during target-finalize
help help
systemd is a system and service manager for Linux, systemd is a system and service manager for Linux,
compatible with SysV and LSB init scripts. systemd provides compatible with SysV and LSB init scripts. systemd provides
@ -199,7 +200,6 @@ config BR2_PACKAGE_SYSTEMD_HOSTNAMED
config BR2_PACKAGE_SYSTEMD_HWDB config BR2_PACKAGE_SYSTEMD_HWDB
bool "enable hwdb installation" bool "enable hwdb installation"
default y default y
select BR2_PACKAGE_HOST_EUDEV # for udevadm, during target-finalize
help help
Enables hardware database installation to /usr/lib/udev/hwdb.d Enables hardware database installation to /usr/lib/udev/hwdb.d

View File

@ -52,12 +52,6 @@ endif
ifeq ($(BR2_PACKAGE_AUDIT),y) ifeq ($(BR2_PACKAGE_AUDIT),y)
SYSTEMD_DEPENDENCIES += audit SYSTEMD_DEPENDENCIES += audit
SYSTEMD_CONF_OPTS += -Daudit=true SYSTEMD_CONF_OPTS += -Daudit=true
define SYSTEMD_INSTALL_SERVICE_AUDIT
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../../usr/lib/systemd/system/auditd.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/auditd.service
endef
else else
SYSTEMD_CONF_OPTS += -Daudit=false SYSTEMD_CONF_OPTS += -Daudit=false
endif endif
@ -65,11 +59,6 @@ endif
ifeq ($(BR2_PACKAGE_CRYPTSETUP),y) ifeq ($(BR2_PACKAGE_CRYPTSETUP),y)
SYSTEMD_DEPENDENCIES += cryptsetup SYSTEMD_DEPENDENCIES += cryptsetup
SYSTEMD_CONF_OPTS += -Dlibcryptsetup=true SYSTEMD_CONF_OPTS += -Dlibcryptsetup=true
define SYSTEMD_INSTALL_TARGET_CRYPTSETUP
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../../usr/lib/systemd/system/remote-cryptsetup.target \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/remote-cryptsetup.target
endef
else else
SYSTEMD_CONF_OPTS += -Dlibcryptsetup=false SYSTEMD_CONF_OPTS += -Dlibcryptsetup=false
endif endif
@ -204,6 +193,14 @@ endif
ifeq ($(BR2_PACKAGE_SYSTEMD_HWDB),y) ifeq ($(BR2_PACKAGE_SYSTEMD_HWDB),y)
SYSTEMD_CONF_OPTS += -Dhwdb=true SYSTEMD_CONF_OPTS += -Dhwdb=true
define SYSTEMD_BUILD_HWDB
$(HOST_DIR)/bin/udevadm hwdb --update --root $(TARGET_DIR)
endef
SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_BUILD_HWDB
define SYSTEMD_RM_HWDB_SRV
rm -rf $(TARGET_DIR)/$(HOST_EUDEV_SYSCONFDIR)/udev/hwdb.d/
endef
SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SYSTEMD_RM_HWDB_SRV
else else
SYSTEMD_CONF_OPTS += -Dhwdb=false SYSTEMD_CONF_OPTS += -Dhwdb=false
endif endif
@ -270,11 +267,6 @@ endif
ifeq ($(BR2_PACKAGE_SYSTEMD_MACHINED),y) ifeq ($(BR2_PACKAGE_SYSTEMD_MACHINED),y)
SYSTEMD_CONF_OPTS += -Dmachined=true SYSTEMD_CONF_OPTS += -Dmachined=true
define SYSTEMD_INSTALL_TARGET_MACHINED
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../../lib/systemd/system/machines.target \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/machines.target
endef
else else
SYSTEMD_CONF_OPTS += -Dmachined=false SYSTEMD_CONF_OPTS += -Dmachined=false
endif endif
@ -318,11 +310,6 @@ endif
ifeq ($(BR2_PACKAGE_SYSTEMD_PSTORE),y) ifeq ($(BR2_PACKAGE_SYSTEMD_PSTORE),y)
SYSTEMD_CONF_OPTS += -Dpstore=true SYSTEMD_CONF_OPTS += -Dpstore=true
define SYSTEMD_INSTALL_SERVICE_PSTORE
mkdir -p $(TARGET_DIR)/etc/systemd/system/systemd-remount-fs.service.wants
ln -sf ../../../../lib/systemd/system/systemd-pstore.service \
$(TARGET_DIR)/etc/systemd/system/systemd-remount-fs.service.wants/systemd-pstore.service
endef
else else
SYSTEMD_CONF_OPTS += -Dpstore=false SYSTEMD_CONF_OPTS += -Dpstore=false
endif endif
@ -337,29 +324,11 @@ endif
ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),y) ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),y)
SYSTEMD_CONF_OPTS += -Dnetworkd=true SYSTEMD_CONF_OPTS += -Dnetworkd=true
SYSTEMD_NETWORKD_USER = systemd-network -1 systemd-network -1 * - - - Network Manager SYSTEMD_NETWORKD_USER = systemd-network -1 systemd-network -1 * - - - Network Manager
define SYSTEMD_INSTALL_SOCKET_NETWORKD
mkdir -p $(TARGET_DIR)/etc/systemd/system/sockets.target.wants
ln -sf ../../../../lib/systemd/system/systemd-networkd.socket \
$(TARGET_DIR)/etc/systemd/system/sockets.target.wants/systemd-networkd.socket
endef
define SYSTEMD_INSTALL_SERVICE_NETWORKD
ln -sf ../../../lib/systemd/system/systemd-networkd.service \
$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.network1.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../../lib/systemd/system/systemd-networkd.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/systemd-networkd.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/network-online.target.wants
ln -sf ../../../../lib/systemd/system/systemd-networkd-wait-online.service \
$(TARGET_DIR)/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/network-pre.target.wants
ln -sf ../../../../lib/systemd/system/systemd-network-generator.service \
$(TARGET_DIR)/etc/systemd/system/network-pre.target.wants/systemd-network-generator.service
endef
SYSTEMD_NETWORKD_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP)) SYSTEMD_NETWORKD_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
ifneq ($(SYSTEMD_NETWORKD_DHCP_IFACE),) ifneq ($(SYSTEMD_NETWORKD_DHCP_IFACE),)
define SYSTEMD_INSTALL_NETWORK_CONFS define SYSTEMD_INSTALL_NETWORK_CONFS
sed s/SYSTEMD_NETWORKD_DHCP_IFACE/$(SYSTEMD_NETWORKD_DHCP_IFACE)/ \ sed s/SYSTEMD_NETWORKD_DHCP_IFACE/$(SYSTEMD_NETWORKD_DHCP_IFACE)/ \
package/systemd/dhcp.network > \ $(SYSTEMD_PKGDIR)/dhcp.network > \
$(TARGET_DIR)/etc/systemd/network/dhcp.network $(TARGET_DIR)/etc/systemd/network/dhcp.network
endef endef
endif endif
@ -374,13 +343,6 @@ define SYSTEMD_INSTALL_RESOLVCONF_HOOK
endef endef
SYSTEMD_CONF_OPTS += -Dresolve=true SYSTEMD_CONF_OPTS += -Dresolve=true
SYSTEMD_RESOLVED_USER = systemd-resolve -1 systemd-resolve -1 * - - - Network Name Resolution Manager SYSTEMD_RESOLVED_USER = systemd-resolve -1 systemd-resolve -1 * - - - Network Name Resolution Manager
define SYSTEMD_INSTALL_SERVICE_RESOLVED
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../lib/systemd/system/systemd-resolved.service \
$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.resolve1.service
ln -sf ../../../../lib/systemd/system/systemd-resolved.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/systemd-resolved.service
endef
else else
SYSTEMD_CONF_OPTS += -Dresolve=false SYSTEMD_CONF_OPTS += -Dresolve=false
endif endif
@ -388,15 +350,6 @@ endif
ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y) ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y)
SYSTEMD_CONF_OPTS += -Dtimesyncd=true SYSTEMD_CONF_OPTS += -Dtimesyncd=true
SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - - - Network Time Synchronization SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - - - Network Time Synchronization
define SYSTEMD_INSTALL_SERVICE_TIMESYNCD
mkdir -p $(TARGET_DIR)/etc/systemd/system/sysinit.target.wants
ln -sf ../../../../lib/systemd/system/systemd-timesyncd.service \
$(TARGET_DIR)/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
ln -sf ../../../../lib/systemd/system/systemd-time-wait-sync.service \
$(TARGET_DIR)/etc/systemd/system/sysinit.target.wants/systemd-time-wait-sync.service
ln -sf ../../../lib/systemd/system/systemd-timesyncd.service \
$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.timesync1.service
endef
else else
SYSTEMD_CONF_OPTS += -Dtimesyncd=false SYSTEMD_CONF_OPTS += -Dtimesyncd=false
endif endif
@ -447,18 +400,8 @@ SYSTEMD_CONF_OPTS += -Dfallback-hostname=$(SYSTEMD_FALLBACK_HOSTNAME)
endif endif
define SYSTEMD_INSTALL_INIT_HOOK define SYSTEMD_INSTALL_INIT_HOOK
ln -fs ../lib/systemd/systemd $(TARGET_DIR)/sbin/init ln -fs multi-user.target \
ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/halt $(TARGET_DIR)/usr/lib/systemd/system/default.target
ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/poweroff
ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/reboot
ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/shutdown
ln -fs ../../../lib/systemd/system/multi-user.target \
$(TARGET_DIR)/etc/systemd/system/default.target
ln -fs ../../../lib/systemd/system/reboot.target \
$(TARGET_DIR)/etc/systemd/system/ctrl-alt-del.target
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -sf ../../../../lib/systemd/system/remote-fs.target \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/remote-fs.target
endef endef
define SYSTEMD_INSTALL_MACHINEID_HOOK define SYSTEMD_INSTALL_MACHINEID_HOOK
@ -466,9 +409,6 @@ define SYSTEMD_INSTALL_MACHINEID_HOOK
endef endef
SYSTEMD_POST_INSTALL_TARGET_HOOKS += \ SYSTEMD_POST_INSTALL_TARGET_HOOKS += \
SYSTEMD_INSTALL_TARGET_CRYPTSETUP \
SYSTEMD_INSTALL_TARGET_MACHINED \
SYSTEMD_INSTALL_SOCKET_NETWORKD \
SYSTEMD_INSTALL_INIT_HOOK \ SYSTEMD_INSTALL_INIT_HOOK \
SYSTEMD_INSTALL_MACHINEID_HOOK \ SYSTEMD_INSTALL_MACHINEID_HOOK \
SYSTEMD_INSTALL_RESOLVCONF_HOOK SYSTEMD_INSTALL_RESOLVCONF_HOOK
@ -492,10 +432,6 @@ define SYSTEMD_USERS
$(SYSTEMD_TIMESYNCD_USER) $(SYSTEMD_TIMESYNCD_USER)
endef endef
define SYSTEMD_DISABLE_SERVICE_TTY1
rm -f $(TARGET_DIR)/etc/systemd/system/getty.target.wants/getty@tty1.service
endef
ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),) ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),)
# systemd needs getty.service for VTs and serial-getty.service for serial ttys # systemd needs getty.service for VTs and serial-getty.service for serial ttys
# note that console-getty.service should be used on /dev/console as it should not have dependencies # note that console-getty.service should be used on /dev/console as it should not have dependencies
@ -523,30 +459,21 @@ define SYSTEMD_INSTALL_SERVICE_TTY
endef endef
endif endif
define SYSTEMD_INSTALL_SERVICE_AUTOVT define SYSTEMD_INSTALL_PRESET
ln -sf ../../../lib/systemd/system/getty@.service \ $(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
$(TARGET_DIR)/lib/systemd/system/autovt@.service
endef
define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
mkdir -p $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
ln -sf ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
$(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
endef endef
define SYSTEMD_INSTALL_INIT_SYSTEMD define SYSTEMD_INSTALL_INIT_SYSTEMD
$(SYSTEMD_DISABLE_SERVICE_TTY1) $(SYSTEMD_INSTALL_PRESET)
$(SYSTEMD_INSTALL_SERVICE_TTY) $(SYSTEMD_INSTALL_SERVICE_TTY)
$(SYSTEMD_INSTALL_SERVICE_AUTOVT)
$(SYSTEMD_INSTALL_SERVICE_RESOLVED)
$(SYSTEMD_INSTALL_SERVICE_TIMESYNCD)
$(SYSTEMD_INSTALL_NETWORK_CONFS) $(SYSTEMD_INSTALL_NETWORK_CONFS)
$(SYSTEMD_INSTALL_SERVICE_PSTORE)
$(SYSTEMD_INSTALL_SERVICE_NETWORKD)
$(SYSTEMD_INSTALL_SERVICE_AUDIT)
$(SYSTEMD_INSTALL_SERVICE_BOOT_CHECK)
endef endef
define SYSTEMD_PRESET_ALL
$(HOST_DIR)/bin/systemctl --root=$(TARGET_DIR) preset-all
endef
SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_PRESET_ALL
SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV) SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV)
SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV) SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV)