50 lines
1.6 KiB
Bash
Executable File
50 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Prepares the host for sandbox sessions: installs gVisor, creates the
|
|
# spawner group and runs the dedicated sandbox Docker daemon.
|
|
# Called by deploy.sh as root. Safe to run repeatedly: the sandbox daemon
|
|
# only restarts when its configuration changed, so live sessions survive.
|
|
set -euo pipefail
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "run as root" >&2
|
|
exit 1
|
|
fi
|
|
|
|
repo_root=$(cd "$(dirname "$0")/../.." && pwd)
|
|
|
|
if ! command -v runsc >/dev/null; then
|
|
apt-get update
|
|
apt-get install -y curl gnupg
|
|
curl -fsSL https://gvisor.dev/archive.key \
|
|
| gpg --dearmor --yes -o /usr/share/keyrings/gvisor-archive-keyring.gpg
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] https://storage.googleapis.com/gvisor/releases release main" \
|
|
> /etc/apt/sources.list.d/gvisor.list
|
|
apt-get update
|
|
apt-get install -y runsc
|
|
fi
|
|
|
|
getent group sandbox-spawner >/dev/null || groupadd --system sandbox-spawner
|
|
|
|
changed=0
|
|
install_if_changed() {
|
|
if ! cmp -s "$1" "$2"; then
|
|
install -D -m 0644 "$1" "$2"
|
|
changed=1
|
|
fi
|
|
}
|
|
|
|
install_if_changed "$repo_root/deploy/docker-sandbox/daemon.json" /etc/docker-sandbox/daemon.json
|
|
install_if_changed "$repo_root/deploy/systemd/sandbox.slice" /etc/systemd/system/sandbox.slice
|
|
install_if_changed "$repo_root/deploy/systemd/docker-sandbox.service" /etc/systemd/system/docker-sandbox.service
|
|
|
|
if [[ $changed == 1 ]]; then
|
|
systemctl daemon-reload
|
|
fi
|
|
systemctl start sandbox.slice
|
|
systemctl enable --quiet docker-sandbox.service
|
|
if [[ $changed == 1 ]]; then
|
|
systemctl restart docker-sandbox.service
|
|
else
|
|
systemctl start docker-sandbox.service
|
|
fi
|