summaryrefslogtreecommitdiffstats
path: root/core/modules/kexec-reboot/data/opt/openslx/scripts/systemd-kexec_load
blob: b6c11e6216f8876bae59058ea436b2b64cf95617 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/ash

kexec=$(which kexec 2>/dev/null)
if [ -z "$kexec" ]; then
	echo "Failed to find kexec binary in PATH. Exiting."
	exit 1
fi

# download_retry <url> <path>
download_retry() {
	[ $# -ne 2 ] && return 1
	for TIMEOUT in 1 1 2 3 END; do
		[ "x$TIMEOUT" = "xEND" ] && break
		if wget -T 2 -O "$2" "$1"; then
			return 0
			break
		fi
		sleep $TIMEOUT
	done
	return 1
}

kexec_load() {
	. /opt/openslx/config
	local DIR="$(mktemp -d)"

	for FILE in kernel initramfs-stage31; do
		if ! download_retry "http://${SLX_KCL_SERVERS}/${SLX_BASE_PATH}/${FILE}" "${DIR}/${FILE}" ; then
			echo "Failed to download ${FILE}."
			exit 1
		fi
	done
	if download_retry "http://${SLX_KCL_SERVERS}/tftp/bwlp.cpio" "${DIR}/bwlp.cpio"; then
		cat "${DIR}/initramfs-stage31" "${DIR}/bwlp.cpio" > "${DIR}/initramfs-tmp"
		mv -f -- "${DIR}/initramfs-tmp" "${DIR}/initramfs-stage31"
	fi
	if ! kexec -l "${DIR}/kernel" --initrd "${DIR}/initramfs-stage31" --reuse-cmdline; then
		echo "Failed to load kernel/initrd from ${DIR}"
		exit 1
	fi
}

kexec_load