Skip to content

Commit 3fd4f2c

Browse files
authored
Merge pull request #843 from kernelkit/drop-execd
Redesign and simplify container creation/removal
2 parents e39ef89 + fbabf0e commit 3fd4f2c

26 files changed

+381
-123
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service :%i pid:!/run/k8s-logger-%i.pid <usr/container:%i> \
2-
[2345] k8s-logger -cni %i -f local1 /run/containers/%i.fifo -- Logger for container %i
3-
sysv :%i pid:!/run/container:%i.pid <!pid/k8s-logger:%i> log kill:10 \
1+
task name:container-%i :setup \
2+
[2345] container -n %i setup -- Setup container %i
3+
sysv <!usr/container:%i> :%i pid:!/run/container:%i.pid log:prio:local1,tag:%i kill:10 \
44
[2345] container -n %i -- container %i

board/common/rootfs/usr/bin/pager

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
# -K :: exit immediately when an interrupt character (usually ^C) is typed
66
# -R :: Almost raw control charachters, only ANSI color escape sequences and
77
# OSC 8 hyperlink sequences are output. Allows veritcal scrolling
8-
# -S :: lines longer than the screen width are chopped (truncated), not wrapped
98
# -X :: No termcap initialization and deinitialization set to the terminal.
109
# This is what leaves the contents of the output on screen.
1110

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

15-
less -RISKd -FX "$@"
14+
less -RIKd -FX "$@"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
d /run/containers/args 0700 - -
2+
d /run/containers/files 0700 - -
3+
d /var/lib/containers 0700 - -
4+
d /var/lib/containers/oci 0700 - -
5+
d /run/cni 0755 - -
6+
L+ /var/lib/cni - - - - /run/cni

board/common/rootfs/usr/sbin/container

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/sh
22
# This script can be used to start, stop, create, and delete containers.
3-
# It is primarily used by confd to create jobs for execd to run from its
4-
# /run/containers/queue, but it can also be used manually.
3+
# It is what confd use, with the Finit [email protected] template, to set
4+
# up, run, and delete containers.
55
#
66
# NOTE: when creating/deleting containers, remember 'initctl reload' to
7-
# activate the changes! When called by confd, via execd, this is
8-
# already handled.
7+
# activate the changes! In confd this is already handled.
98
#
109
DOWNLOADS=/var/lib/containers/oci
1110
BUILTIN=/lib/oci
1211
TMPDIR=/var/tmp
1312
checksum=""
1413
extracted=
14+
timeout=30
1515
dir=""
1616
all=""
1717
env=""
@@ -126,7 +126,17 @@ unpack_archive()
126126
fi
127127
;;
128128
*) # docker://*, docker-archive:*, or URL
129-
echo "$image"
129+
if podman image exists "$image"; then
130+
echo "$image"
131+
return 0
132+
fi
133+
# XXX: use --retry=0 with Podman 5.0 or later.
134+
if ! id=$(podman pull --quiet "$image"); then
135+
log "Failed pulling $image"
136+
return 1
137+
fi
138+
# Echo image name to caller
139+
podman images --filter id="$id" --format "{{.Repository}}:{{.Tag}}"
130140
return 0
131141
;;
132142
esac
@@ -216,13 +226,10 @@ create()
216226
fi
217227

218228
if [ -z "$logging" ]; then
219-
logging="--log-driver k8s-file --log-opt path=/run/containers/$name.fifo"
229+
logging="--log-driver none"
220230
fi
221231

222-
# Pull quietly and don't retry on failure, we use execd for this,
223-
# or user retry manually when run interactively, we may have other
224-
# containers waiting to start that have an image locally already.
225-
# Use --retry=0 with Podman 5.0 or later.
232+
# When we get here we've already fetched, or pulled, the image
226233
args="$args --read-only --replace --quiet --cgroup-parent=containers $caps"
227234
args="$args --restart=$restart --systemd=false --tz=local $privileged"
228235
args="$args $vol $mount $hostname $entrypoint $env $port $logging"
@@ -253,6 +260,7 @@ create()
253260
if podman create --name "$name" --conmon-pidfile="$pidfn" $args "$image" $*; then
254261
[ -n "$quiet" ] || log "Successfully created container $name from $image"
255262
[ -n "$manual" ] || start "$name"
263+
256264
# Should already be enabled by confd (this is for manual use)
257265
initctl -bnq enable "container@${name}.conf"
258266
exit 0
@@ -272,16 +280,23 @@ delete()
272280
exit 1
273281
fi
274282

275-
# Should already be disabled (and stopped) by confd (this is for manual use)
276-
initctl -bnq disable "container@${name}.conf"
283+
# Should already be stopped, but if not ...
284+
container stop "$name"
285+
286+
while running "$name"; do
287+
_=$((timeout -= 1))
288+
if [ $timeout -le 0 ]; then
289+
err 1 "timed out waiting for container $1 to stop before deleting it."
290+
fi
291+
sleep 1
292+
done
277293

278294
podman rm -vif "$name" >/dev/null 2>&1
279295
[ -n "$quiet" ] || log "Container $name has been removed."
280296
}
281297

282298
waitfor()
283299
{
284-
timeout=$2
285300
while [ ! -f "$1" ]; do
286301
_=$((timeout -= 1))
287302
if [ $timeout -le 0 ]; then
@@ -353,6 +368,12 @@ netrestart()
353368
done
354369
}
355370

371+
cleanup()
372+
{
373+
log "Received signal, exiting."
374+
exit 1
375+
}
376+
356377
usage()
357378
{
358379
cat <<EOF
@@ -386,6 +407,7 @@ options:
386407
-q, --quiet Quiet operation, called from confd
387408
-r, --restart POLICY One of "no", "always", or "on-failure:NUM"
388409
-s, --simple Show output in simplified format
410+
-t, --timeout SEC Set timeout for delete/restart commands, default: 20
389411
-v, --volume NAME:PATH Create named volume mounted inside container on PATH
390412
391413
commands:
@@ -403,6 +425,7 @@ commands:
403425
restart [network] NAME Restart a (crashed) container or container(s) using network
404426
run NAME [CMD] Run a container interactively, with an optional command
405427
save IMAGE FILE Save a container image to an OCI tarball FILE[.tar.gz]
428+
setup NAME Create and set up container as a Finit task
406429
shell Start a shell inside a container
407430
show [image | volume] Show containers, images, or volumes
408431
stat Show continuous stats about containers (Ctrl-C aborts)
@@ -525,6 +548,10 @@ while [ "$1" != "" ]; do
525548
-s | --simple)
526549
simple=true
527550
;;
551+
-t | --timeout)
552+
shift
553+
timeout=$1
554+
;;
528555
-v | --volume)
529556
shift
530557
vol="$vol -v $1"
@@ -541,6 +568,8 @@ if [ -n "$cmd" ]; then
541568
shift
542569
fi
543570

571+
trap cleanup INT TERM
572+
544573
case $cmd in
545574
# Does not work atm., cannot attach to TTY because
546575
# we monitor 'podman start -ai foo' with Finit.
@@ -666,6 +695,20 @@ case $cmd in
666695
gzip "$file"
667696
fi
668697
;;
698+
setup)
699+
[ -n "$name" ] || err 1 "setup: missing container name."
700+
script=/run/containers/${name}.sh
701+
[ -x "$script" ] || err 1 "setup: $script does not exist or is not executable."
702+
while ! "$script"; do
703+
# Wait for address/route changes, or retry every 60 secods
704+
# shellcheck disable=2162,3045
705+
ip monitor address route | while read -t 60 _; do break; done
706+
707+
# On IP address/route changes, wait a few seconds more to ensure
708+
# the system has ample time to react and set things up for us.
709+
sleep 2
710+
done
711+
;;
669712
shell)
670713
podman exec -it "$1" sh -l
671714
;;
@@ -720,7 +763,6 @@ case $cmd in
720763
else
721764
name=$1
722765
stop "$name"
723-
timeout=20
724766
while running "$name"; do
725767
_=$((timeout -= 1))
726768
if [ $timeout -le 0 ]; then
@@ -781,7 +823,7 @@ case $cmd in
781823
[ -n "$cmd" ] && shift
782824
case $cmd in
783825
prune)
784-
podman volume $force prune
826+
podman volume prune $force
785827
;;
786828
*)
787829
false

configs/aarch64_defconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ BR2_PACKAGE_CONFD=y
134134
BR2_PACKAGE_CONFD_TEST_MODE=y
135135
BR2_PACKAGE_CURIOS_HTTPD=y
136136
BR2_PACKAGE_CURIOS_NFTABLES=y
137-
BR2_PACKAGE_EXECD=y
138137
BR2_PACKAGE_GENCERT=y
139138
BR2_PACKAGE_STATD=y
140139
BR2_PACKAGE_FACTORY=y
@@ -147,7 +146,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
147146
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
148147
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
149148
BR2_PACKAGE_IITO=y
150-
BR2_PACKAGE_K8S_LOGGER=y
151149
BR2_PACKAGE_KEYACK=y
152150
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y
153151
BR2_PACKAGE_LANDING=y

configs/r2s_defconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ INFIX_HOME="https://github.com/kernelkit/infix/"
175175
INFIX_DOC="https://github.com/kernelkit/infix/tree/main/doc"
176176
INFIX_SUPPORT="mailto:[email protected]"
177177
BR2_PACKAGE_CONFD=y
178-
BR2_PACKAGE_EXECD=y
179178
BR2_PACKAGE_GENCERT=y
180179
BR2_PACKAGE_STATD=y
181180
BR2_PACKAGE_FACTORY=y
@@ -188,7 +187,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
188187
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
189188
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
190189
BR2_PACKAGE_IITO=y
191-
BR2_PACKAGE_K8S_LOGGER=y
192190
BR2_PACKAGE_KEYACK=y
193191
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y
194192
BR2_PACKAGE_LANDING=y

configs/riscv64_defconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ INFIX_DOC="https://github.com/kernelkit/infix/tree/main/doc"
165165
INFIX_SUPPORT="mailto:[email protected]"
166166
BR2_PACKAGE_CONFD=y
167167
# BR2_PACKAGE_CONFD_TEST_MODE is not set
168-
BR2_PACKAGE_EXECD=y
169168
BR2_PACKAGE_GENCERT=y
170169
BR2_PACKAGE_STATD=y
171170
BR2_PACKAGE_FACTORY=y
@@ -178,7 +177,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
178177
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
179178
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
180179
BR2_PACKAGE_IITO=y
181-
BR2_PACKAGE_K8S_LOGGER=y
182180
BR2_PACKAGE_KEYACK=y
183181
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y
184182
BR2_PACKAGE_LANDING=y

configs/x86_64_defconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ BR2_PACKAGE_CONFD=y
138138
BR2_PACKAGE_CONFD_TEST_MODE=y
139139
BR2_PACKAGE_CURIOS_HTTPD=y
140140
BR2_PACKAGE_CURIOS_NFTABLES=y
141-
BR2_PACKAGE_EXECD=y
142141
BR2_PACKAGE_GENCERT=y
143142
BR2_PACKAGE_STATD=y
144143
BR2_PACKAGE_FACTORY=y
@@ -151,7 +150,6 @@ BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
151150
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
152151
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
153152
BR2_PACKAGE_IITO=y
154-
BR2_PACKAGE_K8S_LOGGER=y
155153
BR2_PACKAGE_KEYACK=y
156154
BR2_PACKAGE_KLISH_PLUGIN_INFIX=y
157155
BR2_PACKAGE_LANDING=y

doc/ChangeLog.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,37 @@ All notable changes to the project are documented in this file.
1010
### Changes
1111
- Allow setting IP address directly on VLAN filtering bridges. This
1212
only works when the bridge is an untagged member of a (single) VLAN.
13+
- cli: usability -- showing log files now automatically jump to the end
14+
of the file, where the latest events are
15+
- cli: usability -- showing container status, or other status that
16+
overflows the terminal horizontally, now wrap the lines and exit the
17+
pager immediately if the contents fit on the first screen
18+
- The default log level of the mDNS responder, `avahi-daemon`, has been
19+
adjusted to make it less verbose. Now only `LOG_NOTICE` and higher
20+
severity is logged -- making it very quiet
1321

1422
### Fixes
1523

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

2345

2446
[v24.11.0][] - 2024-11-20

package/execd/tmpfiles.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
d /run/containers/args 0700 - -
2-
d /run/containers/files 0700 - -
3-
d /var/lib/containers/oci 0755 - -
4-
d /run/containers/inbox 0700 - -
51
d /run/containers/queue 0700 - -
6-
d /run/cni 0755 - -
7-
L+ /var/lib/cni - - - - /run/cni

0 commit comments

Comments
 (0)