From 183d85fa9f1416d3715e286528f6591875256593 Mon Sep 17 00:00:00 2001 From: Mikhail Efremov Date: Thu, 12 Dec 2019 17:44:18 +0300 Subject: [PATCH] features/services: Add SYSTEMD_SERVICES_{ENABLE,DISABLE} Support systemd-spicific services, e.g. *.socket amd .service units. --- features.in/services/config.mk | 2 ++ .../install2/image-scripts.d/10-services | 19 ++++++++++++++++--- .../rootfs/image-scripts.d/10-services | 7 ++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/features.in/services/config.mk b/features.in/services/config.mk index b72ae06e..36074b70 100644 --- a/features.in/services/config.mk +++ b/features.in/services/config.mk @@ -4,6 +4,8 @@ use/services: sub/rootfs @$(call xport,DEFAULT_SERVICES_DISABLE) @$(call xport,SERVICES_ENABLE) @$(call xport,SERVICES_DISABLE) + @$(call xport,SYSTEMD_SERVICES_ENABLE) + @$(call xport,SYSTEMD_SERVICES_DISABLE) use/services/lvm2-disable: use/services @$(call add,DEFAULT_SERVICES_DISABLE,lvm2-lvmetad) diff --git a/features.in/services/install2/image-scripts.d/10-services b/features.in/services/install2/image-scripts.d/10-services index 47eec11e..e6ac1f0c 100755 --- a/features.in/services/install2/image-scripts.d/10-services +++ b/features.in/services/install2/image-scripts.d/10-services @@ -13,10 +13,18 @@ CHECK_FILES= . shell-config switch() { + local sname="$1" + + sname="${sname%.service}" + sname="${sname%.socket}" + [ -n "$CHECK_FILES" ] && \ - egrep -qs "^[[:blank:]]*$1(.service|.socket)?[[:blank:]]*$" \ + egrep -qs "^[[:blank:]]*$sname(.service|.socket)?[[:blank:]]*$" \ $CHECK_FILES && return ||: + # avoid service duplication: drop sevice without unit type + [ "$sname" = "$1" ] || shell_config_del "$STATUS" "$sname" + case "$2" in on|off) shell_config_set "$STATUS" "$1" "$2";; @@ -36,8 +44,13 @@ for i in $GLOBAL_DEFAULT_SERVICES_DISABLE; do switch $i off; done for i in $GLOBAL_SERVICES_ENABLE; do switch $i on; done for i in $GLOBAL_SERVICES_DISABLE; do switch $i off; done +# systemd services +for i in $GLOBAL_SYSTEMD_SERVICES_ENABLE; do switch $i on; done +for i in $GLOBAL_SYSTEMD_SERVICES_DISABLE; do switch $i off; done + SERVICES="$GLOBAL_DEFAULT_SERVICES_ENABLE $GLOBAL_DEFAULT_SERVICES_DISABLE" SERVICES="$SERVICES $GLOBAL_SERVICES_ENABLE $GLOBAL_SERVICES_DISABLE" +SERVICES="$SERVICES $GLOBAL_SYSTEMD_SERVICES_ENABLE $GLOBAL_SYSTEMD_SERVICES_DISABLE" SERVICES="$(echo $SERVICES | sort -u)" for i in $SERVICES; do @@ -47,7 +60,7 @@ for i in $SERVICES; do done if [ -s "$CONFDIR"/services-on ]; then - if [ -s "$CONFDIR"/systemd-enabled ]; then + if [ -s "$CONFDIR"/systemd-enabled ] || [ -n "$GLOBAL_SYSTEMD_SERVICES_ENABLE" ]; then cat "$CONFDIR"/services-on >>"$CONFDIR"/systemd-enabled rm "$CONFDIR"/services-on else @@ -56,7 +69,7 @@ if [ -s "$CONFDIR"/services-on ]; then fi if [ -s "$CONFDIR"/services-off ]; then - if [ -s "$CONFDIR"/systemd-disabled ]; then + if [ -s "$CONFDIR"/systemd-disabled ] || [ -n "$GLOBAL_SYSTEMD_SERVICES_DISABLE" ]; then cat "$CONFDIR"/services-off >>"$CONFDIR"/systemd-disabled rm "$CONFDIR"/services-off else diff --git a/features.in/services/rootfs/image-scripts.d/10-services b/features.in/services/rootfs/image-scripts.d/10-services index 45a2cd93..d84fabd6 100755 --- a/features.in/services/rootfs/image-scripts.d/10-services +++ b/features.in/services/rootfs/image-scripts.d/10-services @@ -19,7 +19,7 @@ switch() { esac { - [ -z "$SYSTEMCTL" ] || /bin/systemctl --no-reload $sc $1.service + [ -z "$SYSTEMCTL" ] || /bin/systemctl --no-reload $sc $1 [ -z "$CHKCONFIG" ] || /sbin/chkconfig $1 $cc } # 2>/dev/null } @@ -32,4 +32,9 @@ for i in $GLOBAL_DEFAULT_SERVICES_DISABLE; do switch $i off; done for i in $GLOBAL_SERVICES_ENABLE; do switch $i on; done for i in $GLOBAL_SERVICES_DISABLE; do switch $i off; done +# systemd services +CHKCONFIG= +for i in $GLOBAL_SYSTEMD_SERVICES_ENABLE; do switch $i on; done +for i in $GLOBAL_SYSTEMD_SERVICES_DISABLE; do switch $i off; done + :