Skip to content

Commit

Permalink
Merge pull request #843 from kernelkit/drop-execd
Browse files Browse the repository at this point in the history
Redesign and simplify container creation/removal
  • Loading branch information
troglobit authored Nov 28, 2024
2 parents e39ef89 + fbabf0e commit 3fd4f2c
Show file tree
Hide file tree
Showing 26 changed files with 381 additions and 123 deletions.
6 changes: 3 additions & 3 deletions board/common/rootfs/etc/finit.d/available/[email protected]
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
3 changes: 1 addition & 2 deletions board/common/rootfs/usr/bin/pager
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
# -K :: exit immediately when an interrupt character (usually ^C) is typed
# -R :: Almost raw control charachters, only ANSI color escape sequences and
# OSC 8 hyperlink sequences are output. Allows veritcal scrolling
# -S :: lines longer than the screen width are chopped (truncated), not wrapped
# -X :: No termcap initialization and deinitialization set to the terminal.
# This is what leaves the contents of the output on screen.

export LESS="-P %f (press h for help or q to quit)"
export LANG=en_US.UTF-8

less -RISKd -FX "$@"
less -RIKd -FX "$@"
6 changes: 6 additions & 0 deletions board/common/rootfs/usr/lib/tmpfiles.d/containers.conf
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
72 changes: 57 additions & 15 deletions board/common/rootfs/usr/sbin/container
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=""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -353,6 +368,12 @@ netrestart()
done
}

cleanup()
{
log "Received signal, exiting."
exit 1
}

usage()
{
cat <<EOF
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -525,6 +548,10 @@ while [ "$1" != "" ]; do
-s | --simple)
simple=true
;;
-t | --timeout)
shift
timeout=$1
;;
-v | --volume)
shift
vol="$vol -v $1"
Expand All @@ -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.
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -781,7 +823,7 @@ case $cmd in
[ -n "$cmd" ] && shift
case $cmd in
prune)
podman volume $force prune
podman volume prune $force
;;
*)
false
Expand Down
2 changes: 0 additions & 2 deletions configs/aarch64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ BR2_PACKAGE_CONFD=y
BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_CURIOS_HTTPD=y
BR2_PACKAGE_CURIOS_NFTABLES=y
BR2_PACKAGE_EXECD=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_FACTORY=y
Expand All @@ -147,7 +146,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
Expand Down
2 changes: 0 additions & 2 deletions configs/r2s_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions configs/riscv64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions configs/x86_64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ BR2_PACKAGE_CONFD=y
BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_CURIOS_HTTPD=y
BR2_PACKAGE_CURIOS_NFTABLES=y
BR2_PACKAGE_EXECD=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_FACTORY=y
Expand All @@ -151,7 +150,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
Expand Down
26 changes: 24 additions & 2 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,37 @@ All notable changes to the project are documented in this file.
### Changes
- Allow setting IP address directly on VLAN filtering bridges. This
only works when the bridge is an untagged member of a (single) VLAN.
- cli: usability -- showing log files now automatically jump to the end
of the file, where the latest events are
- cli: usability -- showing container status, or other status that
overflows the terminal horizontally, now wrap the lines and exit the
pager immediately if the contents fit on the first screen
- The default log level of the mDNS responder, `avahi-daemon`, has been
adjusted to make it less verbose. Now only `LOG_NOTICE` and higher
severity is logged -- making it very quiet

### Fixes

- Fix #685: DSA conduit interface not always detected. Previous
attempt at a fix (v24.10.2) mitigated the issue, but did not
completely solve it.
- Fix #835: redesign how the system creates/deletes containers from the
`running-config`. Prior to this change, all removal and creation was
handled by a separate queue that ran asynchronously from the `confd`
process. This could lead to situations where new configurations are
applied before the queue had been fully processed. After this change
containers are deleted synchronously and new containers are created
in the same flow as during normal runtime operation (start/upgrade)
- Fix start of containers with `manual=True` option should now work
again, regression in v24.11.0
- Stop the zeroconf (IPv4LL) agent, `avahi-autoipd`, when removing an
interface, e.g., `br0`
- Creating more than one container trigger restarts of previously set
up containers. Which in some cases may cause these earlier ones to
end up in an inconsistent state
- Prevent traffic assigned to locally terminated VLANs from being
forwarded, when the underlying ports are simultaneously attached to a
VLAN filtering bridge.
forwarded, when the underlying ports are simultaneously attached to
a VLAN filtering bridge.


[v24.11.0][] - 2024-11-20
Expand Down
6 changes: 0 additions & 6 deletions package/execd/tmpfiles.conf
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
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,
Expand Down
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
Expand Down
2 changes: 1 addition & 1 deletion package/finit/0003-plugins-refactor-rtc.so.patch
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.
Expand Down
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
Expand Down
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
Expand Down
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
Expand Down
Loading

0 comments on commit 3fd4f2c

Please sign in to comment.