feat: user container mgmt service + run on boot
This commit is contained in:
parent
1f1568b5fa
commit
c5fff9e6cf
4 changed files with 81 additions and 0 deletions
46
orchestrating/.config/rc/init.d/podman-containers
Executable file
46
orchestrating/.config/rc/init.d/podman-containers
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/sbin/openrc-run
|
||||
|
||||
description="Podman Containers Startup Service"
|
||||
|
||||
# Default values for configurable variables
|
||||
DEFAULT_PODMAN="podman"
|
||||
DEFAULT_CONTAINER_USER="hane"
|
||||
|
||||
# Allow user to override defaults
|
||||
PODMAN="${PODMAN:-$DEFAULT_PODMAN}"
|
||||
CONTAINER_USER="${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}"
|
||||
RESTART_POLICY="unless-stopped"
|
||||
command="$PODMAN"
|
||||
command_args="start --all --filter restart-policy=always"
|
||||
name="podman-containers"
|
||||
command_background=true
|
||||
pidfile="/var/run/${RC_SVCNAME}.pid"
|
||||
output_log="/home/${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}/pihanepi/orchestrating/${RC_SVCNAME}.log"
|
||||
error_log="/home/${CONTAINER_USER:-$DEFAULT_CONTAINER_USER}/pihanepi/orchestrating/${RC_SVCNAME}.err"
|
||||
|
||||
#depend() {
|
||||
# Ensure containers start after the network is up
|
||||
# need net # Ensures that the network is up before starting the containers
|
||||
#}
|
||||
|
||||
start() {
|
||||
ebegin "Starting Podman containers with restart policy"
|
||||
doas -u "$CONTAINER_USER" "$PODMAN" start --all --filter restart-policy=$RESTART_POLICY
|
||||
eend $?
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping Podman containers with restart policy"
|
||||
|
||||
CONTAINERS=$(doas -u "$CONTAINER_USER" "$PODMAN" container ls --filter restart-policy=$RESTART_POLICY -q)
|
||||
|
||||
if [ -n "$CONTAINERS" ]; then
|
||||
for CONTAINER in $CONTAINERS; do
|
||||
doas -u "$CONTAINER_USER" "$PODMAN" stop "$CONTAINER"
|
||||
done
|
||||
eend $?
|
||||
else
|
||||
return 0
|
||||
eend "No containers with restart policy=always are running."
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue