feat(systemd): Add support for unmasking & masking units (#88)

* feat(systemd): Add support for masking services

* Use unit term in README

* Fix README grammar

* Note about unmasking

* Fix typo in README

* Add unmask & more info about systemctl commands

Address:

https://github.com/ublue-os/bling/pull/88#discussion_r1436877565

https://github.com/ublue-os/bling/pull/88#discussion_r1436917124

* docs: clarify purpose of unmasking

* docs: Fix systemd module README typo

---------

Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com>
This commit is contained in:
fiftydinar 2023-12-31 11:31:49 +01:00 committed by GitHub
parent 9357cf17f1
commit 33226b9b73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# `systemd` Module for Startingpoint
The `systemd` module streamlines the management of systemd units during image building. Units are divided into `system` and `user` categories, with `system` units managed directly using `systemctl` and `user` units using `systemctl --user`. You can specify which units to enable or disable under each category.
The `systemd` module streamlines the management of systemd units during image building. Units are divided into `system` and `user` categories, with `system` units managed directly using `systemctl` and `user` units using `systemctl --user`. You can specify which units to enable/disable or unmask/mask under each category.
## Example Configuration
@ -11,22 +11,34 @@ system:
- example.service
disabled:
- example.target
unmasked:
- example.service
masked:
- example.service
user:
enabled:
- example.timer
disabled:
- example.service
unmasked:
- example.service
masked:
- example.service
```
In this example:
### System Units
- `example.service`: Enabled (runs on system boot)
- `example.target`: Disabled (does not run on system boot)
- `example.target`: Disabled (does not run on system boot, unless other unit strictly requires it)
- `example.service`: Unmasked (runs on system boot, even if previously masked)
- `example.service`: Masked (does not run on system boot, under any circumstances)
### User Units
- `example.timer`: Enabled (runs for the user)
- `example.service`: Disabled (does not run for the user)
- `example.service`: Disabled (does not run for the user, unless other unit strictly requires it)
- `example.service`: Unmasked (runs for the user, even if previously masked)
- `example.service`: Masked (does not run for the user, under any circumstances)
This configuration achieves the same results as the following commands:
@ -34,8 +46,18 @@ This configuration achieves the same results as the following commands:
# System Units
systemctl enable example.service
systemctl disable example.target
systemctl unmask example.service
systemctl mask example.service
# User Units
systemctl --user enable example.timer
systemctl --user disable example.service
systemctl --global enable example.timer
systemctl --global disable example.service
systemctl --global unmask example.service
systemctl --global mask example.service
```
For more information about these systemctl commands, please visit:
https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#enable%20UNIT%E2%80%A6
https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#disable%20UNIT%E2%80%A6
https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#unmask%20UNIT%E2%80%A6
https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#mask%20UNIT%E2%80%A6

View file

@ -5,8 +5,12 @@ set -oue pipefail
get_yaml_array ENABLED '.system.enabled[]' "$1"
get_yaml_array DISABLED '.system.disabled[]' "$1"
get_yaml_array UNMASKED '.system.unmasked[]' "$1"
get_yaml_array MASKED '.system.masked[]' "$1"
get_yaml_array USER_ENABLED '.user.enabled[]' "$1"
get_yaml_array USER_DISABLED '.user.disabled[]' "$1"
get_yaml_array USER_UNMASKED '.user.unmasked[]' "$1"
get_yaml_array USER_MASKED '.user.masked[]' "$1"
if [[ ${#ENABLED[@]} -gt 0 ]]; then
@ -21,6 +25,18 @@ if [[ ${#DISABLED[@]} -gt 0 ]]; then
systemctl disable $unit
done
fi
if [[ ${#UNMASKED[@]} -gt 0 ]]; then
for unit in "${UNMASKED[@]}"; do
unit=$(printf "$unit")
systemctl unmask $unit
done
fi
if [[ ${#MASKED[@]} -gt 0 ]]; then
for unit in "${MASKED[@]}"; do
unit=$(printf "$unit")
systemctl mask $unit
done
fi
if [[ ${#USER_ENABLED[@]} -gt 0 ]]; then
for unit in "${USER_ENABLED[@]}"; do
unit=$(printf "$unit")
@ -33,3 +49,15 @@ if [[ ${#USER_DISABLED[@]} -gt 0 ]]; then
systemctl --global disable $unit
done
fi
if [[ ${#USER_UNMASKED[@]} -gt 0 ]]; then
for unit in "${USER_UNMASKED[@]}"; do
unit=$(printf "$unit")
systemctl --global unmask $unit
done
fi
if [[ ${#USER_MASKED[@]} -gt 0 ]]; then
for unit in "${USER_MASKED[@]}"; do
unit=$(printf "$unit")
systemctl --global mask $unit
done
fi