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
|
||||||
|
}
|
||||||
16
orchestrating/.profile
Normal file
16
orchestrating/.profile
Normal 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
|
||||||
19
orchestrating/README.org
Normal file
19
orchestrating/README.org
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#+OPTIONS: toc:nil
|
||||||
|
|
||||||
|
* ROOT SERVICES
|
||||||
|
=<service>.sh= to be symlinked to =/etc/init.d/podman-containers=
|
||||||
|
* USER SERVICES AND RUNLEVELS
|
||||||
|
=.config= folder to be symlinked to =~=
|
||||||
|
* XDG VARIABLES AND RUNNING USER SERVICES ON LOGIN
|
||||||
|
=.profile= to be symlinked to =/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 <USER> HAS PASSWORD
|
||||||
|
Add the following to a new file in =/etc/doas.d/=:
|
||||||
|
|
||||||
|
#+begin_src shell
|
||||||
|
permit nopass <user> as <user>
|
||||||
|
permit nopass root as <user>
|
||||||
|
#+end_src
|
||||||
Loading…
Add table
Add a link
Reference in a new issue