summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJonathan Bauer2018-04-25 18:55:40 +0200
committerJonathan Bauer2018-04-25 18:55:40 +0200
commitb8e5e189b3e6224c3e094496dfaf2966e60f56a8 (patch)
tree6320b485a117897a762ef1b2c54942574a9ceddc /core
parent[vbox] only add floppy controller if missing (diff)
parent[idleaction] Add kexec-reboot support (diff)
downloadmltk-b8e5e189b3e6224c3e094496dfaf2966e60f56a8.tar.gz
mltk-b8e5e189b3e6224c3e094496dfaf2966e60f56a8.tar.xz
mltk-b8e5e189b3e6224c3e094496dfaf2966e60f56a8.zip
Merge branch 'master' of git.openslx.org:openslx-ng/mltk
Diffstat (limited to 'core')
-rwxr-xr-xcore/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action6
-rwxr-xr-xcore/modules/kexec-reboot/data/opt/openslx/bin/kexec-reboot4
-rwxr-xr-xcore/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm14
-rwxr-xr-xcore/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap87
4 files changed, 82 insertions, 29 deletions
diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action
index 57ffcc04..7a1b2afd 100755
--- a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action
+++ b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action
@@ -12,7 +12,7 @@ if [ "$1" = "--detach" ]; then
fi
if [ $# -lt 1 ]; then
- echo "$0 [--detach] <reboot|poweroff> [delay_minutes]" >&2
+ echo "$0 [--detach] <reboot|poweroff|kexec-reboot> [delay_minutes]" >&2
exit 2
fi
@@ -49,7 +49,7 @@ if [ -n "$TS" ]; then
fi
fi
-if [ "$MODE" != "reboot" ] && [ "$MODE" != "poweroff" ]; then
+if [ "$MODE" != "reboot" ] && [ "$MODE" != "poweroff" ] && [ "$MODE" != "kexec-reboot" ]; then
slxlog --echo "idleaction-failed-call" "Invalid call to idleaction-scheduled_action. Mode '$MODE' unknown." >&2
exit 3
fi
@@ -79,7 +79,7 @@ runaction () {
[ "$NUM" = "0" ] && break
if [ "$MINUTES" != "X" ]; then
USERS=0
- if [ "$MODE" = "reboot" ]; then
+ if [ "${MODE#*-}" = "reboot" ]; then
MESSAGE="Das System wird in $MINUTES Minute(n) neugestartet, bitte beenden Sie Ihre Sitzung.
The system will reboot in $MINUTES minute(s). Please save your work and end the session."
else
diff --git a/core/modules/kexec-reboot/data/opt/openslx/bin/kexec-reboot b/core/modules/kexec-reboot/data/opt/openslx/bin/kexec-reboot
new file mode 100755
index 00000000..60197f50
--- /dev/null
+++ b/core/modules/kexec-reboot/data/opt/openslx/bin/kexec-reboot
@@ -0,0 +1,4 @@
+#!/bin/ash
+
+exec systemctl start kexec.target
+
diff --git a/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm b/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm
index ae9cdf41..72cd961e 100755
--- a/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm
+++ b/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm
@@ -145,9 +145,7 @@ readonly SOAP_ENVELOPE="/opt/openslx/bwidm_soap.xml"
# now the pam-type specific part starts
if [ "x$PAM_TYPE" == "xauth" ]; then
- HA='Accept: text/html; application/vnd.paos+xml'
- HP='PAOS: ver="urn:liberty:paos:2003-08";"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp"'
- CT='Content-Type: application/vnd.paos+xml; charset=utf-8'
+ CT='Content-Type: text/xml; charset=utf-8'
NOW=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
HOST=$(echo "${USER_ECP_URL}" | awk -F '/' '{print $3}')
RID="_c${RANDOM}a${RANDOM}f${RANDOM}f${RANDOM}e${RANDOM}e${RANDOM}"
@@ -161,19 +159,19 @@ if [ "x$PAM_TYPE" == "xauth" ]; then
# to be sure everything is working as expected
# we will first send a wrong password and expect a 401
echo "machine ${HOST} login ${USER_USERNAME} password ___invalid-INVALID++~" > "${NETRC}"
- ret=$(curl --connect-timeout 5 --max-time 15 -o /dev/null -w "%{http_code}" -d "${REQUEST}" -H "$CT" -H "$HP" -H "$HA" --basic --netrc-file "$NETRC" "$USER_ECP_URL")
+ ret=$(curl --connect-timeout 5 --max-time 15 -o /dev/null -w "%{http_code}" -d "${REQUEST}" -H "$CT" --basic --netrc-file "$NETRC" "$USER_ECP_URL")
if [ "x$ret" != "x401" ]; then
# this means something else is bad, just exit
echo "False authentication attempt did not return 401 as expected but: $ret"
- rm -- "${NETRC}"
+ rm -f -- "${NETRC}"
exit 7
fi
- # the fake auth call behaved as expected, do the actualy login
+ # the fake auth call behaved as expected, do the actual login
echo "machine ${HOST} login ${USER_USERNAME} password ${USER_PASSWORD}" > "${NETRC}"
- ret=$(curl --connect-timeout 5 --max-time 15 -o /dev/null -w "%{http_code}" -d "${REQUEST}" -H "$CT" -H "$HP" -H "$HA" --basic --netrc-file "$NETRC" "$USER_ECP_URL")
+ ret=$(curl --connect-timeout 5 --max-time 15 -o /dev/null -w "%{http_code}" -d "${REQUEST}" -H "$CT" --basic --netrc-file "$NETRC" "$USER_ECP_URL")
echo "machine ${HOST} login ${USER_USERNAME} password ********************" > "${NETRC}" # It should be a tmpfs but you never know
- rm -- "${NETRC}"
+ rm -f -- "${NETRC}"
if [ "x$ret" == "x200" ]; then
# auth succeeded, lets create a local user representing the bwIDM user
diff --git a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap
index f8bd5682..3cc5fe22 100755
--- a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap
+++ b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap
@@ -20,41 +20,92 @@
# So make sure you're up to date
make_swap () {
- [ $# -ne 2 ] && echo "make_swap: Wrong parameter count $#" && exit 1
+ [ $# -ne 2 ] && echo "make_swap: Wrong parameter count $#" && return 1
local USE="$1"
local DEV="$2"
- echo "$USE" > "/sys/block/zram${DEV}/disksize"
- mkswap "/dev/zram${DEV}"
- swapon "/dev/zram${DEV}" -p 1000 # high priority (in case we have hdd swap 0x82, prefer zram)
+ local STREAMS="$3"
+ echo "$USE" > "/sys/block/zram${DEV}/disksize" || return 1
+ [ -n "$STREAMS" ] && echo "$STREAMS" > "/sys/block/zram${DEV}/max_comp_streams"
+ (
+ mkswap "/dev/zram${DEV}"
+ swapon "/dev/zram${DEV}" -p 1000 # high priority (in case we have hdd swap 0x82, prefer zram)
+ ) &
}
-CPUS=$(grep -c -E "^processor.*[0-9]+$" "/proc/cpuinfo")
+# Count physical CPUs
+CPUS=$(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -u | wc -l) # cat for *
if [ -z "$CPUS" ]; then
echo "ERROR: Could not determine CPU core count"
- exit 1
+else
+ CPUS=1
+fi
+
+KERN=$(uname -r)
+if [ "${KERN%%.*}" -le 4 ]; then
+ DEVS=$CPUS
+ [ "$DEVS" -gt "16" ] && DEVS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit
+ STREAMS=
+else
+ DEVS=1
+ STREAMS=$CPUS
fi
-[ "$CPUS" -gt "16" ] && CPUS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit
-if ! modprobe zram "num_devices=$CPUS"; then
+if [ -e "/sys/class/zram-control/hot_add" ]; then
+ : # nothing to do, loaded and hot_add available
+elif ! modprobe zram "num_devices=$DEVS"; then
echo "ERROR: Could not load zram module"
exit 1
fi
TOTAL=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
-USE=$(( $TOTAL / ( 2 * $CPUS ) ))
-echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap per core"
-USE=$(( $USE * 1024 ))
+USE=$(( TOTAL / ( 2 * DEVS ) ))
+echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap each for $DEVS devices."
+USE=$(( USE * 1024 ))
DEV=0
-while [ "$DEV" -lt "$CPUS" ]; do
- make_swap "$USE" "$DEV" &
- LAST=$!
- DEV=$(( $DEV + 1 ))
+NUM=0
+FAILS=0
+while [ "$NUM" -lt "$DEVS" ]; do
+ if [ -e "/sys/block/zram${DEV}" ]; then
+ if ! [ -e "/sys/block/zram${DEV}/initstate" ] || [ "$(cat "/sys/block/zram${DEV}/initstate")" = 0 ]; then
+ if make_swap "$USE" "$DEV" "$STREAMS"; then
+ NUM=$(( NUM + 1 ))
+ fi
+ fi
+ DEV=$(( DEV + 1 ))
+ elif [ -e "/sys/class/zram-control/hot_add" ]; then
+ DEV=$(cat /sys/class/zram-control/hot_add)
+ if [ -z "$DEV" ]; then
+ echo "ERROR: Cannot hot_add another zram device"
+ break
+ fi
+ if make_swap "$USE" "$DEV" "$STREAMS"; then
+ NUM=$(( NUM + 1 ))
+ else
+ FAILS=$(( FAILS + 1 ))
+ if [ "$FAILS" -gt 4 ]; then
+ echo "ERROR: Could not swap on hot added device -- giving up"
+ break
+ fi
+ fi
+ DEV=$(( DEV + 1 ))
+ else
+ echo "ERROR: Cannot add another zram device: No hot_add support"
+ break
+ fi
done
+# Increase min free memory so we have enough mem available when trying to move
+# something to zram swap. We want 1%, or at least 64MiB
+CURRENT=$(cat "/proc/sys/vm/min_free_kbytes")
+TOTAL=$(awk '{ if ($1 == "MemTotal:") { print $2; exit } }' /proc/meminfo)
+WANT=$(( TOTAL / 100 ))
+[ "$WANT" -gt 65535 ] || WANT=65535 # minimum 64M
+if [ "$CURRENT" -lt "$WANT" ]; then
+ echo "$WANT" > "/proc/sys/vm/min_free_kbytes"
+fi
+
# Wait, so we don't trigger swap.target too early
-while kill -0 "$LAST"; do
- usleep 100000
-done
+wait
exit 0