2022-03-24 04:46:07 +00:00
|
|
|
#!/bin/bash
|
2021-08-24 10:26:37 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
get_default_url() {
|
|
|
|
process=$1
|
|
|
|
version=$2
|
|
|
|
wget -O- "${VERSION_SERVER_URL}/processes/${process}/${version}/url?os=linux&arch=${GOARCH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_binary() {
|
|
|
|
binary=$1
|
|
|
|
url=$2
|
|
|
|
wget -O "/tmp/${binary}.zip" "${url}"
|
|
|
|
unzip -p "/tmp/${binary}.zip" > "/app/${binary}"
|
|
|
|
rm "/tmp/${binary}.zip"
|
|
|
|
chmod u+x "/app/${binary}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# install storagenode and storagenode-updater binaries
|
|
|
|
# during run of the container to not to release new docker image
|
|
|
|
# on each new version of the storagenode binary.
|
|
|
|
if [ ! -f "storagenode-updater" ]; then
|
|
|
|
echo "downloading storagenode-updater"
|
|
|
|
get_binary storagenode-updater "$(get_default_url storagenode-updater minimum)"
|
|
|
|
|
|
|
|
if ./storagenode-updater should-update storagenode-updater \
|
|
|
|
--binary-location /app/storagenode-updater \
|
|
|
|
--identity-dir identity \
|
|
|
|
--version.server-address="${VERSION_SERVER_URL}" 2>/dev/null
|
|
|
|
then
|
|
|
|
echo "updating storagenode-updater"
|
|
|
|
get_binary storagenode-updater "$(get_default_url storagenode-updater suggested)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "storagenode" ]; then
|
|
|
|
echo "downloading storagenode"
|
|
|
|
|
|
|
|
if ./storagenode-updater should-update storagenode \
|
|
|
|
--identity-dir identity \
|
|
|
|
--version.server-address="${VERSION_SERVER_URL}" 2>/dev/null
|
|
|
|
then
|
|
|
|
get_binary storagenode "$(get_default_url storagenode suggested)"
|
|
|
|
else
|
|
|
|
get_binary storagenode "$(get_default_url storagenode minimum)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-05-10 12:22:47 +01:00
|
|
|
SUPERVISOR_SERVER="${SUPERVISOR_SERVER:-unix}"
|
|
|
|
|
2021-08-24 10:26:37 +01:00
|
|
|
RUN_PARAMS="${RUN_PARAMS:-} --config-dir config"
|
|
|
|
RUN_PARAMS="${RUN_PARAMS} --identity-dir identity"
|
|
|
|
RUN_PARAMS="${RUN_PARAMS} --metrics.app-suffix=-alpha"
|
|
|
|
RUN_PARAMS="${RUN_PARAMS} --metrics.interval=30m"
|
|
|
|
|
|
|
|
if [ -n "${VERSION_SERVER_URL:-}" ]; then
|
|
|
|
RUN_PARAMS="${RUN_PARAMS} --version.server-address=${VERSION_SERVER_URL}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${AUTO_UPDATE:-}" != "true" ]; then
|
|
|
|
AUTO_UPDATE="false"
|
|
|
|
fi
|
|
|
|
|
|
|
|
SNO_RUN_PARAMS="${RUN_PARAMS} --console.address=:14002"
|
|
|
|
if [ -n "${STORAGE:-}" ]; then
|
|
|
|
SNO_RUN_PARAMS="${SNO_RUN_PARAMS} --storage.allocated-disk-space=${STORAGE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${ADDRESS:-}" ]; then
|
|
|
|
SNO_RUN_PARAMS="${SNO_RUN_PARAMS} --contact.external-address=${ADDRESS}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${EMAIL:-}" ]; then
|
|
|
|
SNO_RUN_PARAMS="${SNO_RUN_PARAMS} --operator.email=${EMAIL}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${WALLET:-}" ]; then
|
|
|
|
SNO_RUN_PARAMS="${SNO_RUN_PARAMS} --operator.wallet=${WALLET}"
|
|
|
|
fi
|
|
|
|
|
2022-12-02 22:25:13 +00:00
|
|
|
if [ -n "${LOG_LEVEL:-}" ]; then
|
|
|
|
SNO_RUN_PARAMS="${SNO_RUN_PARAMS} --log.level=${LOG_LEVEL}"
|
|
|
|
fi
|
|
|
|
|
2021-08-24 10:26:37 +01:00
|
|
|
if [ "${SETUP:-}" = "true" ]; then
|
2022-03-24 04:46:07 +00:00
|
|
|
echo "Running ./storagenode setup $SNO_RUN_PARAMS ${*}"
|
2022-02-24 12:04:19 +00:00
|
|
|
exec ./storagenode setup ${SNO_RUN_PARAMS} ${*}
|
2021-08-24 10:26:37 +01:00
|
|
|
else
|
2022-02-24 12:04:19 +00:00
|
|
|
sed -i \
|
|
|
|
"s#^command=/app/storagenode-updater\$#command=/app/storagenode-updater run --binary-location /app/storagenode ${RUN_PARAMS} #" \
|
|
|
|
/etc/supervisor/supervisord.conf
|
|
|
|
|
|
|
|
sed -i \
|
|
|
|
"s#^command=/app/storagenode\$#command=/app/storagenode run ${SNO_RUN_PARAMS} ${*}#" \
|
|
|
|
/etc/supervisor/supervisord.conf
|
|
|
|
|
2022-04-21 11:46:05 +01:00
|
|
|
# remove explicit user flag when container is run as non-root
|
|
|
|
if [ $EUID != "0" ]; then
|
|
|
|
sed -i "s#^user=root##" /etc/supervisor/supervisord.conf
|
|
|
|
fi
|
|
|
|
|
2022-05-10 12:22:47 +01:00
|
|
|
#
|
|
|
|
case ${SUPERVISOR_SERVER} in
|
|
|
|
unix) # default
|
|
|
|
;;
|
|
|
|
public_port)
|
|
|
|
# replace unix_http_server section to inet_http_server
|
|
|
|
sed -i "s#^\[unix_http_server\]\$#\[inet_http_server\]#" /etc/supervisor/supervisord.conf
|
|
|
|
# replace unix socket file with tcp public port
|
|
|
|
sed -i "s#^file=/etc/supervisor/supervisor.sock\$#port=*:9001#" /etc/supervisor/supervisord.conf
|
|
|
|
# set server url to http server address
|
|
|
|
sed -i "s#^serverurl=unix:///etc/supervisor/supervisor.sock\$#serverurl=http://127.0.0.1:9001#" /etc/supervisor/supervisord.conf
|
|
|
|
;;
|
|
|
|
private_port)
|
|
|
|
# replace unix_http_server section to inet_http_server
|
|
|
|
sed -i "s#^\[unix_http_server\]\$#\[inet_http_server\]#" /etc/supervisor/supervisord.conf
|
|
|
|
# replace unix socket file with tcp private port .i.e. listens on only localhost
|
|
|
|
sed -i "s#^file=/etc/supervisor/supervisor.sock\$#port=127.0.0.1:9001#" /etc/supervisor/supervisord.conf
|
|
|
|
# set server url to http server address
|
|
|
|
sed -i "s#^serverurl=unix:///etc/supervisor/supervisor.sock\$#serverurl=http://127.0.0.1:9001#" /etc/supervisor/supervisord.conf
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid value '${SUPERVISOR_SERVER}' for SUPERVISOR_SERVER. Expected 'unix', 'public_port' or 'private_port'"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-02-24 12:04:19 +00:00
|
|
|
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
2021-08-24 10:26:37 +01:00
|
|
|
fi
|