package/podman: helper script to create supervised Finit service

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-05-21 20:39:12 +02:00
committed by Tobias Waldekranz
parent b3761d84dc
commit 56677fb1d6
3 changed files with 144 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
#!/bin/sh
# Create a monitored container service
pmargs=""
enable=
dryrun=
name=
usage()
{
cat <<EOF
summary:
Create a supervised Finit service for a podman container.
Use '-e' flag to also enable the service. When called at bootstrap,
this ensures Finit starts the new service when changing runlevel.
Please note, either the entry point or the CMD must run in foreground.
usage:
podman-service [opts] IMAGE [CMD [ARG]]
options:
-d "DESCRIPTION" Optional service description, default: "NAME container"
-e Enable service (does not reload Finit)
-h Show this help text
-n NAME Short name, lower-case, no spaces, e.g., 'nginx'
-p "ARGS" Arguments for podman, example: '-p "-p 80:80"'
-s Simulate (dry run), only echo to stdout
args:
IMAGE Image or URL, e.g., docker://nginx:alpine
CMD Optional command/daemon to run
ARG Optional arguments to command, e.g., --foreground
EOF
}
service_generate()
{
image=$1
cmd=$2
arg=$3
svc="pod-$name"
gen="initctl -fb create $svc"
if [ -z "$description" ]; then
description="$name container"
fi
# shellcheck disable=SC2209
if [ -n "$dryrun" ]; then
gen=cat
enable=
fi
cat <<EOF | $gen
service name:pod :$name podman run --name $name --rm $pmargs $image $cmd $arg -- $description
EOF
if [ -n "$enable" ]; then
initctl -fb enable "pod-$name"
fi
}
while [ "$1" != "" ]; do
case $1 in
-d)
shift
description="$1"
;;
-e)
enable=true
;;
-h|--help|help)
usage
exit 0
;;
-n)
shift
name="$1"
;;
-p)
shift
pmargs="$pmargs $1"
;;
-s)
dryrun=true
;;
*)
break
esac
shift
done
image=$1
if [ -z "$image" ]; then
usage
exit 1
fi
shift
if [ -z "$name" ]; then
name=$(echo "$image" | sed 's/\(.*\):.*/\1/g')
fi
# shellcheck disable=SC2068
service_generate "$image" $@
+2
View File
@@ -81,6 +81,8 @@ define PODMAN_INSTALL_TARGET_CMDS
$(INSTALL) -d -m 755 $(TARGET_DIR)/etc/containers
$(INSTALL) -D -m 644 $(PODMAN_PKGDIR)/containers-policy.json \
$(TARGET_DIR)/etc/containers/policy.json
$(INSTALL) -D -m 755 $(PODMAN_PKGDIR)/podman-service \
$(TARGET_DIR)/usr/bin/podman-service
$(PODMAN_SECCOMP_PROFILE)
endef
@@ -0,0 +1,36 @@
commit 5db2fb2c325807c67b38d18b454bbfc55b51b77f
Author: Joachim Wiberg <troglobit@gmail.com>
Date: Sat May 20 10:08:31 2023 +0200
initctl: let -f force-skip check for built-in service
When calling `initctl -b create` from a start script at bootstrap you
risk blocking the boot since Finit currently cannot reply to IPC during
that period.
This patch allows -f to override this builtin check for the following
initctl commands:
- touch
- show
- edit
- create
- delete
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
diff --git a/src/serv.c b/src/serv.c
index 570f5ac..2029ddd 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -41,6 +41,10 @@ static int is_builtin(char *arg)
{
svc_t *svc;
+ /* skip check, we may be in non-responsive bootstrap */
+ if (iforce)
+ return 0;
+
svc = client_svc_find(arg);
if (!svc)
return 0;