services: Add (un)mask systemd units

Suggested-by: Anton Midyukov <antohami@altlinux.org>
See: https://bugzilla.altlinux.org/47595
This commit is contained in:
Dmitriy Terekhin 2023-10-06 18:48:36 +04:00 committed by Anton Midyukov
parent 9afa566865
commit f97dd7edc4
4 changed files with 37 additions and 2 deletions

View File

@ -19,3 +19,6 @@ DEFAULT_SYSTEMD_SERVICES_* и SYSTEMD_SERVICES_*.
Для включения служб systemd-logind нужно использовать Для включения служб systemd-logind нужно использовать
DEFAULT_SYSTEMD_USER_SERVICES_* и SYSTEMD_USER_SERVICES_*. DEFAULT_SYSTEMD_USER_SERVICES_* и SYSTEMD_USER_SERVICES_*.
Для того, чтобы замаскировать или размаскировать юнит systemd используйте
SYSTEMD_SERVICES_MASK и SYSTEMD_SERVICES_UNMASK.

View File

@ -8,6 +8,8 @@ use/services: sub/rootfs
@$(call xport,DEFAULT_SYSTEMD_SERVICES_DISABLE) @$(call xport,DEFAULT_SYSTEMD_SERVICES_DISABLE)
@$(call xport,SYSTEMD_SERVICES_ENABLE) @$(call xport,SYSTEMD_SERVICES_ENABLE)
@$(call xport,SYSTEMD_SERVICES_DISABLE) @$(call xport,SYSTEMD_SERVICES_DISABLE)
@$(call xport,SYSTEMD_SERVICES_MASK)
@$(call xport,SYSTEMD_SERVICES_UNMASK)
@$(call xport,DEFAULT_SYSTEMD_USER_SERVICES_ENABLE) @$(call xport,DEFAULT_SYSTEMD_USER_SERVICES_ENABLE)
@$(call xport,DEFAULT_SYSTEMD_USER_SERVICES_DISABLE) @$(call xport,DEFAULT_SYSTEMD_USER_SERVICES_DISABLE)
@$(call xport,SYSTEMD_USER_SERVICES_ENABLE) @$(call xport,SYSTEMD_USER_SERVICES_ENABLE)

View File

@ -17,16 +17,17 @@ switch() {
sname="${sname%.service}" sname="${sname%.service}"
sname="${sname%.socket}" sname="${sname%.socket}"
sname="${sname%.target}"
[ -n "$CHECK_FILES" ] && \ [ -n "$CHECK_FILES" ] && \
grep -E -qs "^[[:blank:]]*$sname(.service|.socket)?[[:blank:]]*$" \ grep -E -qs "^[[:blank:]]*$sname(.service|.socket|.target)?[[:blank:]]*$" \
$CHECK_FILES && return ||: $CHECK_FILES && return ||:
# avoid service duplication: drop sevice without unit type # avoid service duplication: drop sevice without unit type
[ "$sname" = "$1" ] || shell_config_del "$STATUS" "$sname" [ "$sname" = "$1" ] || shell_config_del "$STATUS" "$sname"
case "$2" in case "$2" in
on|off|enabled|disabled) on|off|enabled|disabled|mask|unmask)
shell_config_set "$STATUS" "$1" "$2";; shell_config_set "$STATUS" "$1" "$2";;
esac esac
} }
@ -84,6 +85,29 @@ fi
rm "$STATUS" rm "$STATUS"
# Mask|Unmask systemd units
STATUS=`mktemp`
CHECK_FILES=
for f in systemd-mask systemd-unmask; do
[ -s "$CONFDIR/$f" ] || continue
CHECK_FILES="$CHECK_FILES $CONFDIR/$f"
done
for i in $GLOBAL_SYSTEMD_SERVICES_MASK; do switch $i mask; done
for i in $GLOBAL_SYSTEMD_SERVICES_UNMASK; do switch $i unmask; done
SERVICES="$GLOBAL_SYSTEMD_SERVICES_MASK $GLOBAL_SYSTEMD_SERVICES_UNMASK"
SERVICES="$(echo $SERVICES | tr " " "\n" | sort -u)"
for i in $SERVICES; do
maskunmask="$(shell_config_get "$STATUS" "$i")"
[ -n "$maskunmask" ] || continue
echo "$i" >> "$CONFDIR"/systemd-"$maskunmask"ed
done
rm "$STATUS"
# Enable|Disable logind services # Enable|Disable logind services
STATUS=`mktemp` STATUS=`mktemp`
CHECK_FILES= CHECK_FILES=

View File

@ -17,6 +17,10 @@ switch() {
cc=on; sc=enable;; cc=on; sc=enable;;
off) off)
cc=off; sc=disable;; cc=off; sc=disable;;
unmask)
sc=unmask;;
mask)
sc=mask;;
esac esac
{ {
@ -43,6 +47,8 @@ for i in $GLOBAL_DEFAULT_SYSTEMD_SERVICES_DISABLE; do switch $i off; done
# explicitly specified behaviour # explicitly specified behaviour
for i in $GLOBAL_SYSTEMD_SERVICES_ENABLE; do switch $i on; done for i in $GLOBAL_SYSTEMD_SERVICES_ENABLE; do switch $i on; done
for i in $GLOBAL_SYSTEMD_SERVICES_DISABLE; do switch $i off; done for i in $GLOBAL_SYSTEMD_SERVICES_DISABLE; do switch $i off; done
for i in $GLOBAL_SYSTEMD_SERVICES_MASK; do switch $i mask; done
for i in $GLOBAL_SYSTEMD_SERVICES_UNMASK; do switch $i unmask; done
## systemd-logind services ## systemd-logind services
SYSTEMD_USER='--user --global' SYSTEMD_USER='--user --global'