summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
diff options
context:
space:
mode:
authorJonathan Bauer2019-07-24 11:45:44 +0200
committerJonathan Bauer2019-07-24 11:45:44 +0200
commit9976b7469f43239a5e6a128f676c7ecd2e5686b3 (patch)
treeaa519c12d23459f883ba5d614cf0f4614f7057be /builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
parent[slx-clock] remove deprecated file (diff)
downloadsystemd-init-9976b7469f43239a5e6a128f676c7ecd2e5686b3.tar.gz
systemd-init-9976b7469f43239a5e6a128f676c7ecd2e5686b3.tar.xz
systemd-init-9976b7469f43239a5e6a128f676c7ecd2e5686b3.zip
[dnbd3-rootfs] various improvements
* use slx-tools to download the config * use slx-network module instead of systemd-networkd * remove container_unpack_xmount scripts and make it a function * and more small things I can't think of ... :)
Diffstat (limited to 'builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh')
-rwxr-xr-xbuilder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh47
1 files changed, 23 insertions, 24 deletions
diff --git a/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh b/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
index 212bda75..5096be9b 100755
--- a/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
+++ b/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
@@ -6,55 +6,54 @@ core.import exceptions
core.import logging
type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
# endregion
+
exceptions.try
{
-[[ "$SLX_LOG_FILE_PATH" == "" ]] && SLX_LOG_FILE_PATH=/var/log/openslx
-logging.set_log_file "$SLX_LOG_FILE_PATH"
+logging.set_log_file "${SLX_LOG_FILE_PATH:-/var/log/openslx}"
# NOTE: "getarg" raises an exception so deactivate exceptions for now.
exceptions.deactivate
-configuration_file_name="$(getarg slx_configuration_filename=)"
-if [ -z "$configuration_file_name" ]; then
- configuration_file_name='config'
-fi
slx_server="$(getarg slxsrv=)"
slx_server_base="$(getarg slxbase=)"
exceptions.activate
+# build config_url
+config_url="http://${slx_server#@}/${slx_server_base}/config"
+
# check if system's uuid was set
if [ -s "/run/system-uuid" ]; then
uuid=$(cat "/run/system-uuid")
if [ -n "$uuid" ]; then
- uuid_url="?uuid=$uuid"
+ config_url="${config_url}?uuid=${uuid}"
fi
fi
-logging.info "Download SLX configuration from: \"$slx_server\"."
-(
-IFS=','
-for TIMEOUT in 1 1 2 3; do
- if wget -q -t 2 -T $TIMEOUT \
- "http://${slx_server#@}/${slx_server_base}/${configuration_file_name}${uuid_url}" \
- --output-document '/etc/openslx.tmp'; then
- break
- fi
-done
-)
+config_path="/etc/openslx.tmp"
-if [[ ! -s "/etc/openslx.tmp" ]]; then
- logging.warn "Downloading OpenSLX configuration file from any of the servers \"${slx_server}\" at location \"${slx_server_base}/${configuration_file_name}\" failed. Return code: $return_code"
- return 1
+logging.info "Downloading '$config_url'..."
+slx-tools download_retry "$config_url" > "$config_path"
+
+if [ ! -s "$config_path" ] ; then
+ logging.warn "Downloading OpenSLX configuration file from '$config_url' failed with: $return_code"
+ emergency_shell "CRITICAL: System unusable."
+fi
+
+if ! ash -n "$config_path"; then
+ logging.warn "Downloaded OpenSLX configuration failed syntax check!"
+ emergency_shell "CRITICAL: System unusable."
fi
# remember kcl server and base
-(
+{
echo "SLX_KCL_SERVERS='$slx_server'"
echo "SLX_BASE_PATH='$slx_server_base'"
+ echo "# Config fetched from $config_url"
+ echo "CONFIG_DOWNLOAD_TIME=$(sed -r 's/^([0-9]+)\.([0-9]+).*$/\1\2/' /proc/uptime)"
echo '#_RCONFIG_TAG'
-) > /etc/openslx
+} > /etc/openslx
# finally copy remote config into it
-cat /etc/openslx.tmp >> /etc/openslx
+cat "$config_path" >> /etc/openslx
# slxsrv overrides SLX_DNBD3_SERVERS if prefixed with @
[ "${slx_server#@}" != "${slx_server}" ] && sed -i "s/^SLX_DNBD3_SERVERS=.*/SLX_DNBD3_SERVERS='${slx_server#@}'/" "/etc/openslx"