2
0
Fork 0

sh.zio.pod-systemd: update to use podlet

This commit is contained in:
Astra 2025-07-07 18:02:18 +01:00
parent 31452e5241
commit 22530be0f5

View file

@ -6,17 +6,31 @@ else
. "$(dirname "$(realpath -s "$0")")/../libexec/zio/helpers/bash.sh"
fi
test_prog "podlet"
test_prog "podman"
service_name="$1"
command_args="${@:2}"
if [[ -z $service_name ]]; then
say warning "No service name given, exiting"
exit
fi
if [[ -z $command_args ]]; then
say warning "No command args given, exiting"
exit
fi
say info "Creating systemd service for $service_name"
podlet -u -i -d \"$service_name container\" podman run $command_args
if [[ $(id -u) = 0 ]]; then
podman generate systemd -n --new $service_name > "/etc/systemd/system/container-$service_name.service"
systemctl daemon-reload
systemctl enable --now container-$service_name
say primary "System service file for $service_name created, enabled and started"
systemctl start $service_name
say primary "System service file for $service_name created and started"
else
podman generate systemd -n --new $service_name > "$HOME/.config/systemd/user/container-$service_name.service"
systemctl --user daemon-reload
systemctl enable --user --now container-$service_name
say primary "User service file for $service_name created, enabled and started"
systemctl --user start $service_name
say primary "User service file for $service_name created and started"
fi