balena-supervisor/tools/dind/start-resin-supervisor
Petros Angelatos bba1da370b
logger: Remove pubnub leftovers
Change-type: minor
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2018-07-18 12:31:10 -07:00

64 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# Adapted from: https://github.com/resin-os/meta-resin/blob/v2.12.5/meta-resin-common/recipes-containers/docker-disk/docker-resin-supervisor-disk/start-resin-supervisor
source /usr/sbin/resin-vars
if ! balena inspect $SUPERVISOR_IMAGE:$SUPERVISOR_TAG > /dev/null; then
balena load --input /usr/src/supervisor-image.tar
fi
if [ -f /mnt/data/apps.json ]; then
preloaded_img=$(jq --raw-output ".[0].imageId" /mnt/data/apps.json || echo "")
if [ "$preloaded_img" != "" ] && ! balena inspect $preloaded_img; then
balena pull $preloaded_img
fi
fi
EXTRA_MOUNTS=""
if [ -d /resin-supervisor/dist ]; then
EXTRA_MOUNTS="${EXTRA_MOUNTS} -v /resin-supervisor/dist:/usr/src/app/dist"
fi
if [ -d /resin-supervisor/node_modules ]; then
EXTRA_MOUNTS="${EXTRA_MOUNTS} -v /resin-supervisor/node_modules:/usr/src/app/node_modules"
fi
SUPERVISOR_IMAGE_ID=$(balena inspect --format='{{.Id}}' $SUPERVISOR_IMAGE:$SUPERVISOR_TAG)
SUPERVISOR_CONTAINER_IMAGE_ID=$(balena inspect --format='{{.Image}}' resin_supervisor || echo "")
runSupervisor() {
balena rm --force resin_supervisor || true
balena run --privileged --name resin_supervisor \
--net=host \
-v /var/run/balena.sock:/var/run/balena.sock \
-v $CONFIG_PATH:/boot/config.json \
-v /mnt/data/apps.json:/boot/apps.json \
-v /resin-data/resin-supervisor:/data \
-v /proc/net/fib_trie:/mnt/fib_trie \
-v /var/log/supervisor-log:/var/log \
-v /:/mnt/root \
-e DOCKER_ROOT=/mnt/root/var/lib/docker \
-e DOCKER_SOCKET=/var/run/balena.sock \
-e BOOT_MOUNTPOINT=$BOOT_MOUNTPOINT \
-e API_ENDPOINT=$API_ENDPOINT \
-e REGISTRY_ENDPOINT=$REGISTRY_ENDPOINT \
-e MIXPANEL_TOKEN=$MIXPANEL_TOKEN \
-e DELTA_ENDPOINT=$DELTA_ENDPOINT \
-e LED_FILE=${LED_FILE} \
-e LISTEN_PORT=$LISTEN_PORT \
-e SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE}:${SUPERVISOR_TAG} \
${EXTRA_MOUNTS} \
${SUPERVISOR_IMAGE}:${SUPERVISOR_TAG}
}
if [ -z "$SUPERVISOR_IMAGE_ID" ]; then
# No supervisor image exists on the device, try to pull it
systemctl start update-resin-supervisor
elif [ "$SUPERVISOR_IMAGE_ID" = "$SUPERVISOR_CONTAINER_IMAGE_ID" ]; then
# Supervisor image exists, and the current supervisor container is created from
balena start --attach resin_supervisor
else
# No supervisor container exists or there's a different supervisor image to run
runSupervisor
fi