From a65ecb6427daf08d642e5ff51717c038560e4957 Mon Sep 17 00:00:00 2001 From: Hane Date: Fri, 29 May 2026 21:18:37 +0200 Subject: [PATCH] feat: user container mgmt service + run on boot --- .../.config/rc/init.d/podman-containers | 46 +++++++++++++++++++ ...ate-runlevels-here-as-in-etc-for-user.info | 0 orchestrating/.profile | 16 +++++++ orchestrating/README.org | 19 ++++++++ 4 files changed, 81 insertions(+) create mode 100755 orchestrating/.config/rc/init.d/podman-containers create mode 100644 orchestrating/.config/rc/runlevels/create-runlevels-here-as-in-etc-for-user.info create mode 100644 orchestrating/.profile create mode 100644 orchestrating/README.org diff --git a/orchestrating/.config/rc/init.d/podman-containers b/orchestrating/.config/rc/init.d/podman-containers new file mode 100755 index 0000000..bb39475 --- /dev/null +++ b/orchestrating/.config/rc/init.d/podman-containers @@ -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 +} diff --git a/orchestrating/.config/rc/runlevels/create-runlevels-here-as-in-etc-for-user.info b/orchestrating/.config/rc/runlevels/create-runlevels-here-as-in-etc-for-user.info new file mode 100644 index 0000000..e69de29 diff --git a/orchestrating/.profile b/orchestrating/.profile new file mode 100644 index 0000000..a3fbe5b --- /dev/null +++ b/orchestrating/.profile @@ -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 diff --git a/orchestrating/README.org b/orchestrating/README.org new file mode 100644 index 0000000..7ba858c --- /dev/null +++ b/orchestrating/README.org @@ -0,0 +1,19 @@ +#+OPTIONS: toc:nil + +* ROOT SERVICES +=.sh= to be symlinked to =/etc/init.d/podman-containers= +* USER SERVICES AND RUNLEVELS +- =.config= folder to be symlinked to =~= +* XDG_RUNTIME_DIR AND RUNLEVEL SETUP +- =.profile= to be symlinked to srch_shell{/home/$USER/.profile= + +* RUN USERS SERVICES ON BOOT +- Symlink =/etc/init.d/user= to =/etc/init.d/user.$usernames=. After add, add the latter service with =rc-update= as root. + +* IF HAS PASSWORD +Add the following to a new file in =/etc/doas.d/=: + +#+begin_src shell +permit nopass as +permit nopass root as +#+end_src