Files

56 lines
1.0 KiB
Bash

# Sourced by managed-container; uses the shared OCF and parameter environment.
service_uid()
{
id -u "${SERVICE_USER}"
}
service_home()
{
getent passwd "${SERVICE_USER}" | cut -d: -f6
}
as_service_user()
{
local uid home
uid="$(id -u "$SERVICE_USER")" || return 1
home="$(getent passwd "$SERVICE_USER" | cut -d: -f6)" || return 1
runuser -u "$SERVICE_USER" -- \
sh -c '
home="$1"
runtime="$2"
shift 2
cd "$home" || exit 1
export HOME="$home"
export XDG_RUNTIME_DIR="$runtime"
exec "$@"
' sh \
"$home" \
"/run/user/$uid" \
"$@"
}
service_running()
{
as_service_user \
systemctl --user is-active --quiet "${SERVICE_NAME}"
}
container_running()
{
local state
state="$(
as_service_user podman inspect \
--format '{{.State.Running}}' \
"${CONTAINER_NAME}" 2>/dev/null
)" || return 1
[ "${state}" = "true" ]
}