Skip to content

Commit 0e3fd2c

Browse files
authored
Start Supervisor container with its cidfile mounted to /run/cid (#4276)
Use the --cidfile Docker CLI argument when starting the container and bind-mount the generated file containing full ID of the container to the container itself. Using --mount instead of --volume is needed, as --volume is racy and creates empty directory volume at the destination path instead. This is prerequisite for home-assistant/supervisor#6006 but can come handy for other cases too.
1 parent 9a1e001 commit 0e3fd2c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -e
1111
# Init supervisor
1212
SUPERVISOR_DATA=/mnt/data/supervisor
1313
SUPERVISOR_STARTUP_MARKER="/run/supervisor/startup-marker"
14+
SUPERVISOR_CIDFILE="${SUPERVISOR_DATA}/hassio_supervisor.cid"
1415
SUPERVISOR_STARTSCRIPT_VERSION="/mnt/data/.hassos-supervisor-version"
1516
SUPERVISOR_IMAGE="ghcr.io/home-assistant/${SUPERVISOR_ARCH}-hassio-supervisor"
1617

@@ -58,8 +59,8 @@ if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then
5859
docker tag "${SUPERVISOR_IMAGE}:${SUPERVISOR_VERSION}" "${SUPERVISOR_IMAGE}:latest"
5960
else
6061
# Pull failed, updater info might be corrupted or the release might have
61-
# been removed from the container registry, delete the updater info
62-
# to start from scratch on next try.
62+
# been removed from the container registry, delete the updater info
63+
# to start from scratch on next try.
6364
echo "[ERROR] Supervisor download failed."
6465
rm -f "${SUPERVISOR_DATA}/updater.json"
6566
exit 1
@@ -87,12 +88,18 @@ fi
8788

8889
# If Supervisor container is missing, create it
8990
if [ -z "${SUPERVISOR_CONTAINER_ID}" ]; then
91+
# We need to remove the CID file here, Docker will refuse to start if the
92+
# file is present. Single instance is ensured by other code paths.
93+
[ -f "${SUPERVISOR_CIDFILE}" ] && rm -f "${SUPERVISOR_CIDFILE}"
94+
9095
echo "[INFO] Creating a new Supervisor container..."
9196
# shellcheck disable=SC2086
9297
docker container create \
9398
--name hassio_supervisor \
9499
--privileged --security-opt apparmor="hassio-supervisor" \
95100
--oom-score-adj=-300 \
101+
--cidfile "${SUPERVISOR_CIDFILE}" \
102+
--mount type=bind,src="${SUPERVISOR_CIDFILE}",dst=/run/cid,readonly \
96103
-v /run/docker.sock:/run/docker.sock:rw \
97104
-v /run/containerd/containerd.sock:/run/containerd/containerd.sock:rw \
98105
-v /run/systemd/journal/socket:/run/systemd/journal/socket:rw \

0 commit comments

Comments
 (0)