feat(systemd): Add support for including systemd units (#144)
* feat(systemd): Add support for including systemd units This also gets rid of `files` module dependency & exposes this function better to the users. Related issue: https://github.com/ublue-os/bling/issues/143 * fix(systemd): Make included systemd unit check better It doesn't fail now if there is systemd folder present without any files. * chore(systemd): Code spacing fixes * chore(systemd): Disable dotglob, as it's not needed for systemd units * docs(systemd): Remove inclusion term
This commit is contained in:
parent
cf5d0e1750
commit
28ed8ed259
2 changed files with 28 additions and 2 deletions
|
|
@ -2,4 +2,13 @@
|
|||
|
||||
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 --global`. You can specify which units to enable/disable or unmask/mask under each category.
|
||||
|
||||
Supported operations are [enabling](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#enable%20UNIT%E2%80%A6), [disabling](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#disable%20UNIT%E2%80%A6), [masking](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#mask%20UNIT%E2%80%A6%E2%80%A6) and [unmasking](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#unmask%20UNIT%E2%80%A6).
|
||||
You can also include your systemd units to be copied into system directories into these locations,
|
||||
depending if your unit is `system` or `user` based:
|
||||
`config/systemd/system`
|
||||
`config/systemd/user`
|
||||
|
||||
Those units are then copied into these folders (depending on unit base):
|
||||
`/usr/lib/systemd/system`
|
||||
`/usr/lib/systemd/user`
|
||||
|
||||
Supported management operations are [enabling](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#enable%20UNIT%E2%80%A6), [disabling](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#disable%20UNIT%E2%80%A6), [masking](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#mask%20UNIT%E2%80%A6%E2%80%A6) and [unmasking](https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#unmask%20UNIT%E2%80%A6).
|
||||
|
|
|
|||
|
|
@ -3,6 +3,24 @@
|
|||
# Tell build process to exit if there are any errors.
|
||||
set -euo pipefail
|
||||
|
||||
# Copy included systemd unit files to system
|
||||
SYSTEM_UNIT_INCLUDE="$CONFIG_DIRECTORY"/systemd/system
|
||||
USER_UNIT_INCLUDE="$CONFIG_DIRECTORY"/systemd/user
|
||||
SYSTEM_UNIT_DIR="/usr/lib/systemd/system"
|
||||
USER_UNIT_DIR="/usr/lib/systemd/user"
|
||||
|
||||
if [[ -d "$SYSTEM_UNIT_INCLUDE" ]]; then
|
||||
if [[ -n $(find "$SYSTEM_UNIT_INCLUDE" -type f) ]]; then
|
||||
cp -r "$SYSTEM_UNIT_INCLUDE"/* "$SYSTEM_UNIT_DIR"
|
||||
fi
|
||||
fi
|
||||
if [[ -d "$USER_UNIT_INCLUDE" ]]; then
|
||||
if [[ -n $(find "$USER_UNIT_INCLUDE" -type f) ]]; then
|
||||
cp -r "$USER_UNIT_INCLUDE"/* "$USER_UNIT_DIR"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Systemd units configuration (enable, disable, unmask & mask)
|
||||
get_yaml_array ENABLED '.system.enabled[]' "$1"
|
||||
get_yaml_array DISABLED '.system.disabled[]' "$1"
|
||||
get_yaml_array UNMASKED '.system.unmasked[]' "$1"
|
||||
|
|
@ -12,7 +30,6 @@ 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
|
||||
for unit in "${ENABLED[@]}"; do
|
||||
unit=$(printf "$unit")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue