-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
70 lines (53 loc) · 2.36 KB
/
install.sh
File metadata and controls
70 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
set -euo pipefail
trap 'sleep infinity' EXIT
volume_mount="/runtime"
host_path=$(awk -v path="$volume_mount" '$5 == path {print $4; exit}' /proc/self/mountinfo)
if [ -z "${host_path}" ]; then
echo "ERROR: Could not determine host path for volume ${volume_mount}"
exit 1
fi
# Add the host mount point
# e.g /docker/volumes/1_runsc/_data -> /mnt/data/docker/volumes/1_runsc/_data
host_path="/mnt/data${host_path}"
echo "Volume host path: ${host_path}"
echo "Installing runsc runtime binaries to volume..."
rsync -av --delete /opt/ "${volume_mount}/bin/"
"${volume_mount}"/bin/runsc --version
"${volume_mount}"/bin/containerd-shim-runsc-v1 -v
echo "Binaries installed successfully!"
helper_image="${HELPER_IMAGE:-docker.io/library/alpine:latest}"
conf_path="/host/run/systemd/system/balena.service.d/runsc.conf"
# create custom drop-in to add runsc runtime to balena service
custom_conf="[Service]
Environment=\"PATH=${host_path}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"
Environment=\"BALENAD_EXTRA_ARGS=--add-runtime runsc=${host_path}/bin/runsc\"
"
# check if drop-in already exists and matches desired content
if docker run --rm -v /run:/host/run:ro "${helper_image}" sh -c \
"[ -f '${conf_path}' ] && echo '${custom_conf}' > /tmp/runsc.conf.tmp && cmp -s '${conf_path}' /tmp/runsc.conf.tmp"; then
echo "runsc runtime already registered with balena service. No changes needed."
exit 0
fi
# install drop-in under the host OS /run path so it is cleared on reboot
echo "Installing runsc runtime drop-in to balena service..."
docker run --rm -v /run:/host/run:rw "${helper_image}" sh -c \
"mkdir -p '$(dirname ${conf_path})' && echo '${custom_conf}' > '${conf_path}'"
# reload the systemd daemon (same as systemctl daemon-reload)
echo "Reloading systemd daemon..."
dbus-send \
--system \
--dest=org.freedesktop.systemd1 \
--type=method_call \
--print-reply \
/org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.Reload
# restart the balena service (same as systemctl restart balena.service)
echo "Restarting balena service..."
dbus-send \
--system \
--dest=org.freedesktop.systemd1 \
--type=method_call \
--print-reply \
/org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.RestartUnit \
string:"balena.service" string:"replace"
echo "runsc runtime registered successfully!"