sh.zio.pod-systemd: update file
This commit is contained in:
parent
d2cb59e23f
commit
d3cb97551c
1 changed files with 34 additions and 13 deletions
|
|
@ -1,36 +1,57 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [[ "$(realpath "$(dirname "$(realpath -s "$0")")/../../../")" == "/" ]]; then
|
if [[ "$(realpath "$(dirname "$(realpath "$0")")/../../../")" == "/" ]]; then
|
||||||
. /usr/local/libexec/zio/helpers/bash.sh
|
. /usr/local/libexec/zio/helpers/bash.sh
|
||||||
else
|
else
|
||||||
. "$(dirname "$(realpath -s "$0")")/../libexec/zio/helpers/bash.sh"
|
. "$(dirname "$(realpath "$0")")/../libexec/zio/helpers/bash.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test_prog "podlet"
|
test_prog "podlet"
|
||||||
test_prog "podman"
|
test_prog "podman"
|
||||||
|
|
||||||
service_name="$1"
|
service_name="$1"
|
||||||
command_args="${@:2}"
|
command_args=("${@:2}")
|
||||||
|
|
||||||
if [[ -z $service_name ]]; then
|
if [[ -z "$service_name" ]]; then
|
||||||
say warning "No service name given, exiting"
|
say warning "No service name given, exiting"
|
||||||
exit
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ${#command_args[@]} -eq 0 ]]; then
|
||||||
|
say warning "No command args given, exiting"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $command_args ]]; then
|
# Force the container name to service_name: overwrite any --name passed in the
|
||||||
say warning "No command args given, exiting"
|
# podman arguments, or inject one if absent. This keeps the systemd unit name
|
||||||
exit
|
# (which podlet derives from the container name) always equal to service_name.
|
||||||
|
has_name=false
|
||||||
|
for ((i = 0; i < ${#command_args[@]}; i++)); do
|
||||||
|
case "${command_args[i]}" in
|
||||||
|
--name)
|
||||||
|
command_args[i+1]="$service_name"
|
||||||
|
has_name=true
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
--name=*)
|
||||||
|
command_args[i]="--name=$service_name"
|
||||||
|
has_name=true
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [[ "$has_name" == false ]]; then
|
||||||
|
command_args=(--name "$service_name" "${command_args[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say info "Creating systemd service for $service_name"
|
say info "Creating systemd service for $service_name"
|
||||||
|
podlet -u -i --overwrite -d "$service_name container" podman run "${command_args[@]}"
|
||||||
|
|
||||||
podlet -u -i -d \"$service_name container\" podman run $command_args
|
if [[ $(id -u) -eq 0 ]]; then
|
||||||
if [[ $(id -u) = 0 ]]; then
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl start $service_name
|
systemctl start "$service_name"
|
||||||
say primary "System service file for $service_name created and started"
|
say primary "System service file for $service_name created and started"
|
||||||
else
|
else
|
||||||
systemctl --user daemon-reload
|
systemctl --user daemon-reload
|
||||||
systemctl --user start $service_name
|
systemctl --user start "$service_name"
|
||||||
say primary "User service file for $service_name created and started"
|
say primary "User service file for $service_name created and started"
|
||||||
fi
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue