Files
actions-runner-controller/runner/startup.sh
T

71 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/bash
2022-04-12 23:02:06 +02:00
source logger.bash
function wait_for_process () {
local max_time_wait=30
local process_name="$1"
local waited_sec=0
while ! pgrep "$process_name" >/dev/null && ((waited_sec < max_time_wait)); do
2022-04-12 23:02:06 +02:00
log.debug "Process $process_name is not running yet. Retrying in 1 seconds"
log.debug "Waited $waited_sec seconds of $max_time_wait seconds"
sleep 1
((waited_sec=waited_sec+1))
if ((waited_sec >= max_time_wait)); then
return 1
fi
done
return 0
}
2021-03-31 09:29:21 +09:00
sudo /bin/bash <<SCRIPT
mkdir -p /etc/docker
2021-04-25 08:04:01 +03:00
echo "{}" > /etc/docker/daemon.json
2021-03-31 09:29:21 +09:00
if [ -n "${MTU}" ]; then
2021-04-25 08:04:01 +03:00
jq ".\"mtu\" = ${MTU}" /etc/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /etc/docker/daemon.json
2021-03-31 09:29:21 +09:00
# See https://docs.docker.com/engine/security/rootless/
echo "environment=DOCKERD_ROOTLESS_ROOTLESSKIT_MTU=${MTU}" >> /etc/supervisor/conf.d/dockerd.conf
fi
2021-04-25 08:04:01 +03:00
if [ -n "${DOCKER_REGISTRY_MIRROR}" ]; then
jq ".\"registry-mirrors\"[0] = \"${DOCKER_REGISTRY_MIRROR}\"" /etc/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /etc/docker/daemon.json
fi
2021-03-31 09:29:21 +09:00
SCRIPT
2022-04-12 23:02:06 +02:00
dump() {
local path=${1:?missing required <path> argument}
shift
printf -- "%s\n---\n" "${*//\{path\}/"$path"}" 1>&2
cat "$path" 1>&2
printf -- '---\n' 1>&2
}
2021-03-31 09:29:21 +09:00
2022-04-12 23:02:06 +02:00
for config in /etc/docker/daemon.json /etc/supervisor/conf.d/dockerd.conf; do
dump "$config" 'Using {path} with the following content:'
done
2021-03-31 09:29:21 +09:00
2022-04-12 23:02:06 +02:00
log.debug 'Starting supervisor daemon'
sudo /usr/bin/supervisord -n >> /dev/null 2>&1 &
2022-04-12 23:02:06 +02:00
log.debug 'Waiting for processes to be running...'
processes=(dockerd)
for process in "${processes[@]}"; do
wait_for_process "$process"
if [ $? -ne 0 ]; then
2022-04-12 23:02:06 +02:00
log.error "$process is not running after max time"
dump /var/log/dockerd.err.log 'Dumping {path} to aid investigation'
exit 1
2022-04-12 23:02:06 +02:00
else
log.debug "$process is running"
fi
done
if [ -n "${MTU}" ]; then
sudo ifconfig docker0 mtu ${MTU} up
fi
# Wait processes to be running
entrypoint.sh