-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #843 from kernelkit/drop-execd
Redesign and simplify container creation/removal
- Loading branch information
Showing
26 changed files
with
381 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
service :%i pid:!/run/k8s-logger-%i.pid <usr/container:%i> \ | ||
[2345] k8s-logger -cni %i -f local1 /run/containers/%i.fifo -- Logger for container %i | ||
sysv :%i pid:!/run/container:%i.pid <!pid/k8s-logger:%i> log kill:10 \ | ||
task name:container-%i :setup \ | ||
[2345] container -n %i setup -- Setup container %i | ||
sysv <!usr/container:%i> :%i pid:!/run/container:%i.pid log:prio:local1,tag:%i kill:10 \ | ||
[2345] container -n %i -- container %i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
d /run/containers/args 0700 - - | ||
d /run/containers/files 0700 - - | ||
d /var/lib/containers 0700 - - | ||
d /var/lib/containers/oci 0700 - - | ||
d /run/cni 0755 - - | ||
L+ /var/lib/cni - - - - /run/cni |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#!/bin/sh | ||
# This script can be used to start, stop, create, and delete containers. | ||
# It is primarily used by confd to create jobs for execd to run from its | ||
# /run/containers/queue, but it can also be used manually. | ||
# It is what confd use, with the Finit [email protected] template, to set | ||
# up, run, and delete containers. | ||
# | ||
# NOTE: when creating/deleting containers, remember 'initctl reload' to | ||
# activate the changes! When called by confd, via execd, this is | ||
# already handled. | ||
# activate the changes! In confd this is already handled. | ||
# | ||
DOWNLOADS=/var/lib/containers/oci | ||
BUILTIN=/lib/oci | ||
TMPDIR=/var/tmp | ||
checksum="" | ||
extracted= | ||
timeout=30 | ||
dir="" | ||
all="" | ||
env="" | ||
|
@@ -126,7 +126,17 @@ unpack_archive() | |
fi | ||
;; | ||
*) # docker://*, docker-archive:*, or URL | ||
echo "$image" | ||
if podman image exists "$image"; then | ||
echo "$image" | ||
return 0 | ||
fi | ||
# XXX: use --retry=0 with Podman 5.0 or later. | ||
if ! id=$(podman pull --quiet "$image"); then | ||
log "Failed pulling $image" | ||
return 1 | ||
fi | ||
# Echo image name to caller | ||
podman images --filter id="$id" --format "{{.Repository}}:{{.Tag}}" | ||
return 0 | ||
;; | ||
esac | ||
|
@@ -216,13 +226,10 @@ create() | |
fi | ||
|
||
if [ -z "$logging" ]; then | ||
logging="--log-driver k8s-file --log-opt path=/run/containers/$name.fifo" | ||
logging="--log-driver none" | ||
fi | ||
|
||
# Pull quietly and don't retry on failure, we use execd for this, | ||
# or user retry manually when run interactively, we may have other | ||
# containers waiting to start that have an image locally already. | ||
# Use --retry=0 with Podman 5.0 or later. | ||
# When we get here we've already fetched, or pulled, the image | ||
args="$args --read-only --replace --quiet --cgroup-parent=containers $caps" | ||
args="$args --restart=$restart --systemd=false --tz=local $privileged" | ||
args="$args $vol $mount $hostname $entrypoint $env $port $logging" | ||
|
@@ -253,6 +260,7 @@ create() | |
if podman create --name "$name" --conmon-pidfile="$pidfn" $args "$image" $*; then | ||
[ -n "$quiet" ] || log "Successfully created container $name from $image" | ||
[ -n "$manual" ] || start "$name" | ||
|
||
# Should already be enabled by confd (this is for manual use) | ||
initctl -bnq enable "container@${name}.conf" | ||
exit 0 | ||
|
@@ -272,16 +280,23 @@ delete() | |
exit 1 | ||
fi | ||
|
||
# Should already be disabled (and stopped) by confd (this is for manual use) | ||
initctl -bnq disable "container@${name}.conf" | ||
# Should already be stopped, but if not ... | ||
container stop "$name" | ||
|
||
while running "$name"; do | ||
_=$((timeout -= 1)) | ||
if [ $timeout -le 0 ]; then | ||
err 1 "timed out waiting for container $1 to stop before deleting it." | ||
fi | ||
sleep 1 | ||
done | ||
|
||
podman rm -vif "$name" >/dev/null 2>&1 | ||
[ -n "$quiet" ] || log "Container $name has been removed." | ||
} | ||
|
||
waitfor() | ||
{ | ||
timeout=$2 | ||
while [ ! -f "$1" ]; do | ||
_=$((timeout -= 1)) | ||
if [ $timeout -le 0 ]; then | ||
|
@@ -353,6 +368,12 @@ netrestart() | |
done | ||
} | ||
|
||
cleanup() | ||
{ | ||
log "Received signal, exiting." | ||
exit 1 | ||
} | ||
|
||
usage() | ||
{ | ||
cat <<EOF | ||
|
@@ -386,6 +407,7 @@ options: | |
-q, --quiet Quiet operation, called from confd | ||
-r, --restart POLICY One of "no", "always", or "on-failure:NUM" | ||
-s, --simple Show output in simplified format | ||
-t, --timeout SEC Set timeout for delete/restart commands, default: 20 | ||
-v, --volume NAME:PATH Create named volume mounted inside container on PATH | ||
commands: | ||
|
@@ -403,6 +425,7 @@ commands: | |
restart [network] NAME Restart a (crashed) container or container(s) using network | ||
run NAME [CMD] Run a container interactively, with an optional command | ||
save IMAGE FILE Save a container image to an OCI tarball FILE[.tar.gz] | ||
setup NAME Create and set up container as a Finit task | ||
shell Start a shell inside a container | ||
show [image | volume] Show containers, images, or volumes | ||
stat Show continuous stats about containers (Ctrl-C aborts) | ||
|
@@ -525,6 +548,10 @@ while [ "$1" != "" ]; do | |
-s | --simple) | ||
simple=true | ||
;; | ||
-t | --timeout) | ||
shift | ||
timeout=$1 | ||
;; | ||
-v | --volume) | ||
shift | ||
vol="$vol -v $1" | ||
|
@@ -541,6 +568,8 @@ if [ -n "$cmd" ]; then | |
shift | ||
fi | ||
|
||
trap cleanup INT TERM | ||
|
||
case $cmd in | ||
# Does not work atm., cannot attach to TTY because | ||
# we monitor 'podman start -ai foo' with Finit. | ||
|
@@ -666,6 +695,20 @@ case $cmd in | |
gzip "$file" | ||
fi | ||
;; | ||
setup) | ||
[ -n "$name" ] || err 1 "setup: missing container name." | ||
script=/run/containers/${name}.sh | ||
[ -x "$script" ] || err 1 "setup: $script does not exist or is not executable." | ||
while ! "$script"; do | ||
# Wait for address/route changes, or retry every 60 secods | ||
# shellcheck disable=2162,3045 | ||
ip monitor address route | while read -t 60 _; do break; done | ||
|
||
# On IP address/route changes, wait a few seconds more to ensure | ||
# the system has ample time to react and set things up for us. | ||
sleep 2 | ||
done | ||
;; | ||
shell) | ||
podman exec -it "$1" sh -l | ||
;; | ||
|
@@ -720,7 +763,6 @@ case $cmd in | |
else | ||
name=$1 | ||
stop "$name" | ||
timeout=20 | ||
while running "$name"; do | ||
_=$((timeout -= 1)) | ||
if [ $timeout -le 0 ]; then | ||
|
@@ -781,7 +823,7 @@ case $cmd in | |
[ -n "$cmd" ] && shift | ||
case $cmd in | ||
prune) | ||
podman volume $force prune | ||
podman volume prune $force | ||
;; | ||
*) | ||
false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,6 @@ INFIX_HOME="https://github.com/kernelkit/infix/" | |
INFIX_DOC="https://github.com/kernelkit/infix/tree/main/doc" | ||
INFIX_SUPPORT="mailto:[email protected]" | ||
BR2_PACKAGE_CONFD=y | ||
BR2_PACKAGE_EXECD=y | ||
BR2_PACKAGE_GENCERT=y | ||
BR2_PACKAGE_STATD=y | ||
BR2_PACKAGE_FACTORY=y | ||
|
@@ -188,7 +187,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc" | |
BR2_PACKAGE_FINIT_PLUGIN_TTY=y | ||
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y | ||
BR2_PACKAGE_IITO=y | ||
BR2_PACKAGE_K8S_LOGGER=y | ||
BR2_PACKAGE_KEYACK=y | ||
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y | ||
BR2_PACKAGE_LANDING=y | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,6 @@ INFIX_DOC="https://github.com/kernelkit/infix/tree/main/doc" | |
INFIX_SUPPORT="mailto:[email protected]" | ||
BR2_PACKAGE_CONFD=y | ||
# BR2_PACKAGE_CONFD_TEST_MODE is not set | ||
BR2_PACKAGE_EXECD=y | ||
BR2_PACKAGE_GENCERT=y | ||
BR2_PACKAGE_STATD=y | ||
BR2_PACKAGE_FACTORY=y | ||
|
@@ -178,7 +177,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc" | |
BR2_PACKAGE_FINIT_PLUGIN_TTY=y | ||
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y | ||
BR2_PACKAGE_IITO=y | ||
BR2_PACKAGE_K8S_LOGGER=y | ||
BR2_PACKAGE_KEYACK=y | ||
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y | ||
BR2_PACKAGE_LANDING=y | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
d /run/containers/args 0700 - - | ||
d /run/containers/files 0700 - - | ||
d /var/lib/containers/oci 0755 - - | ||
d /run/containers/inbox 0700 - - | ||
d /run/containers/queue 0700 - - | ||
d /run/cni 0755 - - | ||
L+ /var/lib/cni - - - - /run/cni |
2 changes: 1 addition & 1 deletion
2
package/finit/0001-Only-mark-rdeps-dirty-if-main-service-is-nohup.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 46ffa81f5c88ce95db011369d8bfb802313e4217 Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Thu, 17 Oct 2024 14:23:24 +0200 | ||
Subject: [PATCH 1/6] Only mark rdeps dirty if main service is nohup | ||
Subject: [PATCH 1/7] Only mark rdeps dirty if main service is nohup | ||
Organization: Addiva Elektronik | ||
|
||
This patch changes a behavior that's been default since Finit 4.0, | ||
|
2 changes: 1 addition & 1 deletion
2
package/finit/0002-Reset-color-attributes-and-clear-screen-when-startin.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 119e66a7e9c95283918639b51dd03a3d666955f8 Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Mon, 28 Oct 2024 10:58:04 +0100 | ||
Subject: [PATCH 2/6] Reset color attributes and clear screen when starting up | ||
Subject: [PATCH 2/7] Reset color attributes and clear screen when starting up | ||
Organization: Addiva Elektronik | ||
|
||
Some boot loaders, like GRUB, leave background color artifacts from | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0c0e880f3fdd38f7bbde618408378dc0a19ff005 Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Sun, 3 Nov 2024 09:39:46 +0100 | ||
Subject: [PATCH 3/6] plugins: refactor rtc.so | ||
Subject: [PATCH 3/7] plugins: refactor rtc.so | ||
Organization: Addiva Elektronik | ||
|
||
Factor out time_set() and time_get() for readability and reuse. | ||
|
2 changes: 1 addition & 1 deletion
2
package/finit/0004-Fix-418-support-systems-with-a-broken-RTC.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From bc8118d515839dc598f437aa01f07a771646968d Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Sun, 3 Nov 2024 09:47:16 +0100 | ||
Subject: [PATCH 4/6] Fix #418: support systems with a broken RTC | ||
Subject: [PATCH 4/7] Fix #418: support systems with a broken RTC | ||
Organization: Addiva Elektronik | ||
|
||
This patch introduces a new configure option --with-rtc-file=FILE. When | ||
|
2 changes: 1 addition & 1 deletion
2
package/finit/0005-Fix-buggy-with-rtc-date-DATE-introduced-in-Finit-v4..patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 6be16f2f6d093ef495d0fe4313f7b05b4ba3e08f Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Sun, 3 Nov 2024 10:38:38 +0100 | ||
Subject: [PATCH 5/6] Fix buggy --with-rtc-date=DATE, introduced in Finit v4.4 | ||
Subject: [PATCH 5/7] Fix buggy --with-rtc-date=DATE, introduced in Finit v4.4 | ||
Organization: Addiva Elektronik | ||
|
||
In 42ef3d3c, for v4.4-rc1, support for setting a custom RTC restore date | ||
|
2 changes: 1 addition & 1 deletion
2
package/finit/0006-plugins-reduce-log-level-LOG_ERR-LOG_WARNING.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 49c0557cedd8d3c1a2f74d27fa7db83dd529914a Mon Sep 17 00:00:00 2001 | ||
From: Joachim Wiberg <[email protected]> | ||
Date: Sun, 3 Nov 2024 20:49:04 +0100 | ||
Subject: [PATCH 6/6] plugins: reduce log level LOG_ERR -> LOG_WARNING | ||
Subject: [PATCH 6/7] plugins: reduce log level LOG_ERR -> LOG_WARNING | ||
Organization: Addiva Elektronik | ||
|
||
These plugins signal success and failure directly to the console, the | ||
|
Oops, something went wrong.