33 lines
679 B
Bash
Executable file
33 lines
679 B
Bash
Executable file
#!/bin/sh
|
|
set -eu
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
printf 'eseguire come root\n' >&2
|
|
exit 2
|
|
fi
|
|
|
|
NAME=${1:-}
|
|
if [ -z "$NAME" ]; then
|
|
printf 'uso: %s <nome-container>\n' "$0" >&2
|
|
exit 2
|
|
fi
|
|
|
|
unit="/etc/systemd/system/container-$NAME.service"
|
|
tmp=$(mktemp)
|
|
trap 'rm -f "$tmp"' EXIT HUP INT TERM
|
|
|
|
podman generate systemd --new --name "$NAME" > "$tmp"
|
|
chmod 0644 "$tmp"
|
|
|
|
if cmp -s "$tmp" "$unit"; then
|
|
printf '%s: unit invariata\n' "$NAME"
|
|
exit 0
|
|
fi
|
|
|
|
mv "$tmp" "$unit"
|
|
tmp=""
|
|
systemctl daemon-reload
|
|
systemctl enable "container-$NAME.service" >/dev/null
|
|
systemctl restart "container-$NAME.service"
|
|
printf '%s: %s\n' "$NAME" "$(systemctl is-active "container-$NAME.service")"
|