feat: user container mgmt service + run on boot

This commit is contained in:
Hane 2026-05-29 21:18:37 +02:00
commit 4454251fc4
4 changed files with 79 additions and 0 deletions

View 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
}

16
orchestrating/.profile Normal file
View file

@ -0,0 +1,16 @@
# Set XDG_CONFIG_HOME dir to default
export XDG_CONFIG_HOME="$HOME/.config"
# Init XDG_RUNTIME_DIR directory for current user
UID=$(id -u)
if test -z "${XDG_RUNTIME_DIR}"; then
export XDG_RUNTIME_DIR=/tmp/xdg/$UID-xdg-runtime-dir
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir -p "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
#Start user default runlevel
openrc -U default

17
orchestrating/README.org Normal file
View file

@ -0,0 +1,17 @@
* ROOT SERVICES
- src_shell{<service>.sh} to be symlinked to src_shell{/etc/init.d/podman-containers}
* USER SERVICES AND RUNLEVELS
- src_shell{.config} folder to be symlinked to src_shell{~}
* XDG_RUNTIME_DIR AND RUNLEVEL SETUP
- src_shell{.profile} to be symlinked to srch_shell{/home/$USER/.profile}
* RUN USERS SERVICES ON BOOT
- Symlink src_shell{/etc/init.d/user} to src_shell{/etc/init.d/user.$usernames}. After add, add the latter service with src_shell{rc-update} as root.
* IF <USER> HAS PASSWORD
Add the following to a new file in src_shell{/etc/doas.d/}:
#+begin_src shell
permit nopass <user> as <user>
permit nopass root as <user>
#+end_src