2014-04-27 21:46:59 +00:00
|
|
|
#!/bin/sh
|
2014-06-10 00:05:16 +00:00
|
|
|
|
2016-07-06 08:45:32 +00:00
|
|
|
set -o errexit
|
2014-04-27 21:46:59 +00:00
|
|
|
|
2018-10-15 17:05:23 +00:00
|
|
|
# If the legacy /tmp/resin-supervisor exists on the host, a container might
|
|
|
|
# already be using to take an update lock, so we symlink it to the new
|
|
|
|
# location so that the supervisor can see it
|
|
|
|
[ -d /mnt/root/tmp/resin-supervisor ] &&
|
2018-10-23 15:17:35 +00:00
|
|
|
( [ -d /mnt/root/tmp/balena-supervisor ] || ln -s ./resin-supervisor /mnt/root/tmp/balena-supervisor )
|
2018-10-15 17:05:23 +00:00
|
|
|
|
|
|
|
# Otherwise, if the lockfiles directory doesn't exist
|
|
|
|
[ -d /mnt/root/tmp/balena-supervisor ] ||
|
|
|
|
mkdir -p /mnt/root/tmp/balena-supervisor
|
2014-04-27 21:46:59 +00:00
|
|
|
|
2016-06-23 18:07:18 +00:00
|
|
|
# If DOCKER_ROOT isn't set then default it
|
|
|
|
if [ -z "${DOCKER_ROOT}" ]; then
|
|
|
|
DOCKER_ROOT=/mnt/root/var/lib/rce
|
|
|
|
fi
|
2016-07-06 08:45:32 +00:00
|
|
|
|
2016-06-23 18:07:18 +00:00
|
|
|
# Mount the DOCKER_ROOT path equivalent in the container fs
|
|
|
|
DOCKER_LIB_PATH=${DOCKER_ROOT#/mnt/root}
|
2016-07-06 08:45:32 +00:00
|
|
|
|
2016-06-23 18:07:18 +00:00
|
|
|
if [ ! -d "${DOCKER_LIB_PATH}" ]; then
|
|
|
|
ln -s "${DOCKER_ROOT}" "${DOCKER_LIB_PATH}"
|
2016-06-09 05:15:24 +00:00
|
|
|
fi
|
2018-03-16 14:01:50 +00:00
|
|
|
|
|
|
|
if [ -z "$DOCKER_SOCKET" ]; then
|
|
|
|
export DOCKER_SOCKET=/run/docker.sock
|
|
|
|
fi
|
|
|
|
|
|
|
|
export DBUS_SYSTEM_BUS_ADDRESS="unix:path=/mnt/root/run/dbus/system_bus_socket"
|
|
|
|
|
2018-03-13 11:41:06 +00:00
|
|
|
# Include self-signed CAs, should they exist
|
2019-09-02 16:39:13 +00:00
|
|
|
if [ -n "${BALENA_ROOT_CA}" ]; then
|
2018-03-13 11:41:06 +00:00
|
|
|
if [ ! -e '/etc/ssl/certs/balenaRootCA.pem' ]; then
|
2020-08-26 15:46:49 +00:00
|
|
|
echo "${BALENA_ROOT_CA}" > /etc/ssl/certs/balenaRootCA.pem
|
|
|
|
|
|
|
|
# Include the balenaRootCA in the system store for services like Docker
|
2018-03-13 11:41:06 +00:00
|
|
|
mkdir -p /usr/local/share/ca-certificates
|
|
|
|
echo "${BALENA_ROOT_CA}" > /usr/local/share/ca-certificates/balenaRootCA.crt
|
|
|
|
update-ca-certificates
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-02-13 10:49:07 +00:00
|
|
|
# Mount the host kernel module path onto the expected location
|
|
|
|
# We need to do this as busybox doesn't support using a custom location
|
2019-02-14 13:49:03 +00:00
|
|
|
if [ ! -d /lib/modules ]; then
|
|
|
|
ln -s /mnt/root/lib/modules /lib/modules
|
|
|
|
fi
|
2019-05-15 07:39:54 +00:00
|
|
|
# Now load the ip6_tables kernel module, so we can do
|
|
|
|
# filtering on ipv6 addresses. Don't fail here if the
|
|
|
|
# modprobe fails, as this can either be that the module is
|
|
|
|
# already loaded or that the kernel module isn't present. In
|
|
|
|
# the former case, this is fine for runtime, and in the
|
|
|
|
# latter it means that the supervisor will fail later on, so
|
|
|
|
# not a problem.
|
|
|
|
modprobe ip6_tables || true
|
2019-02-13 10:49:07 +00:00
|
|
|
|
2022-03-07 22:10:51 +00:00
|
|
|
export BASE_LOCK_DIR="/tmp/balena-supervisor/services"
|
|
|
|
export LOCKFILE_UID=65534
|
|
|
|
|
|
|
|
# Cleanup leftover Supervisor-created lockfiles from any previous processes.
|
|
|
|
# Supervisor-created lockfiles have a UID of 65534.
|
2022-04-13 16:29:45 +00:00
|
|
|
find "/mnt/root${BASE_LOCK_DIR}" -type f -user "${LOCKFILE_UID}" -name "*updates.lock" -delete || true
|
2022-03-07 22:10:51 +00:00
|
|
|
|
2020-04-21 11:56:58 +00:00
|
|
|
if [ "${LIVEPUSH}" = "1" ]; then
|
2020-04-14 09:50:21 +00:00
|
|
|
exec npx nodemon --watch src --watch typings --ignore tests -e js,ts,json \
|
2020-04-06 16:29:59 +00:00
|
|
|
--exec node -r ts-node/register/transpile-only src/app.ts
|
2020-04-06 08:53:34 +00:00
|
|
|
else
|
|
|
|
exec node /usr/src/app/dist/app.js
|
|
|
|
fi
|