From 3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 26 Nov 2013 19:08:35 +0100 Subject: [rfs-stage32] Add 'slxlog', a utility for remote logging --- .../rootfs-stage32/data/opt/openslx/bin/slxlog | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog (limited to 'remote') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog new file mode 100755 index 00000000..4df68cc0 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog @@ -0,0 +1,53 @@ +#!/opt/openslx/bin/ash + +################## +# Remote logging # +################## + +. /opt/openslx/config +[ -z "$SLX_REMOTE_LOG" ] && exit 3 + +LOGCHECK="/tmp/remote_log_check" +NOW=$(date +%s) + +[ $# -eq 0 ] && exit 0 + +TYPE="$1" + +# Simple spamcheck. Not very tamper-proof, but if you'd want to spam the server +# you could do it anyways. This is to protect from accidental loops calling this. +if [ -r "$LOGCHECK" ]; then + # Allow max 500 messages in total + LINES=$(cat "$LOGCHECK" | wc -l) + [ "$LINES" -gt 500 ] && exit 1 + # Allow max 5 of same type messages in 30 seconds + LAST=$(grep "$TYPE" "$LOGCHECK" | tail -n 5 | head -n 1 | awk '{print $1}') + if [ -n "$LAST" ]; then + DIFF="$[ $NOW - $LAST ]" + [ "$DIFF" -lt "30" ] && exit 2 + fi +fi +echo "$NOW $TYPE" >> "$LOGCHECK" +chmod 0666 "$LOGCHECK" + +if [ $# -lt 2 ]; then + MSG="Missing text for $@" +else + MSG="$2" +fi +MSG="[$(whoami)] $MSG" + +if [ $# -gt 2 ]; then + EXTRA="$3" +fi + +if [ -r "$EXTRA" ]; then + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc@$EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +elif [ -n "$EXTRA" ]; then + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc=Missing $EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +else + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +fi + +exit 0 + -- cgit v1.2.3-55-g7522 From 12de3fe8d8616efb2b7da0e557b17982020f490f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 26 Nov 2013 19:25:41 +0100 Subject: [rfs-stage32] Add remote logging to mount_export and setup_partitions --- .../data/opt/openslx/scripts/systemd-mount_export | 23 ++++++++++++++++++---- .../opt/openslx/scripts/systemd-setup_partitions | 14 ++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) (limited to 'remote') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_export b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_export index c71dc9f6..c76634c7 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_export +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-mount_export @@ -23,17 +23,32 @@ if [[ "$SLX_STAGE4" == dnbd3* ]]; then echo "... didn't work ($RET)" sleep 2 done - [ "$RET" -ne "0" ] && exit $RET + if [ "$RET" -ne "0" ]; then + slxlog "mount-stage4" "Could not get stage4 via dnbd3 ($IMAGE) ($SLX_DNBD3_PRIO_SERVERS / $SERVERS)" + exit $RET + fi echo "Mounting $dnbd3 to $MOUNTPOINT" - mount -t squashfs -o ro "$dnbd3" "$MOUNTPOINT" || { echo "Fail."; exit 1; } + if ! mount -t squashfs -o ro "$dnbd3" "$MOUNTPOINT"; then + slxlog "mount-stage4" "Could not mount stage4 from '$dnbd3' to '$MOUNTPOINT' ($SRV, $IMAGE)" + echo "Fail." + exit 1 + fi else # Try nfs echo "Mounting ${SLX_STAGE4} to $MOUNTPOINT" - mount -t nfs -o ro,async,nolock,vers=3 "$SLX_STAGE4" "$MOUNTPOINT" || { echo "Fail." && exit 1; } + if ! mount -t nfs -o ro,async,nolock,vers=3 "$SLX_STAGE4" "$MOUNTPOINT"; then + slxlog "mount-stage4" "Could not mount stage4 from '$SLX_STAGE4' to '$MOUNTPOINT'" + echo "Fail." + exit 1 + fi fi echo "Appending $MOUNTPOINT to /" -mount -o "remount,add:1:$MOUNTPOINT=ro" / || { echo "Fail." && exit 1; } +if ! mount -o "remount,add:1:$MOUNTPOINT=ro" /; then + slxlog "mount-stage4" "Could not append mounted stage4 at '$MOUNTPOINT to aufs at /" + echo "Fail." + exit 1 +fi # dbus reload needed eg. for gnome etc. and perhaps other service files which stage4 needs: systemctl reload dbus.service diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions index 0f419366..07bd628e 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions @@ -14,6 +14,7 @@ ############################################################################# +# Mount point for persistent scratch partition (type 45) PERSISTENT="/opt/openslx/persistent" # General formatter for the /tmp partition on a local harddisk @@ -105,20 +106,23 @@ echo "Partitions:" cat "/etc/disk.partition" # Check for standard swap partitions and make them available to the system +HAVE_SWAP=no for hdpartnr in $(sed -n -e "/ 82 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" - swapon "$hdpartnr" -p 10 + swapon "$hdpartnr" -p 10 && HAVE_SWAP=yes done # We use special non assigned partition type (id44) for harddisk scratch # space, thus no normal filesystem will be incidentally deleted or # corrupted +HAVE_TEMP=no for hdpartnr in $(sed -n -e "/ 44 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do # check for supported filesystem and formatter if diskfm "$hdpartnr"; then # echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready mount_temp "$mopt" "$hdpartnr" || continue echo -e "${hdpartnr}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" + HAVE_TEMP=yes break else echo "formatting failed for some reason" @@ -155,8 +159,12 @@ done mount -a # Make huge tmpfs if nothing could be mounted for /tmp -if [ "$(mount | grep -c "on /tmp ")" = "0" ]; then - mount_temp -t tmpfs -o size=10G none +if [ "$HAVE_TEMP" = "no" ]; then + mount_temp -t tmpfs -o size=20G none + slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" +fi +if [ "$HAVE_SWAP" = "no" ]; then + slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" fi # Add zram swap -- cgit v1.2.3-55-g7522 From b31955796c2b5b8ec18a17efa4d9582c2b5787de Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 26 Nov 2013 19:58:44 +0100 Subject: [rfs-stage32] Add curl, remove lots of required binaries which should come with our busybox. This might break things if we rely on extended features in stage32, but generally we should try to adapt to the busybox versions --- remote/rootfs/rootfs-stage32/rootfs-stage32.conf | 8 +------- remote/rootfs/rootfs-stage32/rootfs-stage32.conf.opensuse | 1 + remote/rootfs/rootfs-stage32/rootfs-stage32.conf.ubuntu | 1 + 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'remote') diff --git a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf index 5d8966f1..085b6ecc 100644 --- a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf +++ b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf @@ -3,25 +3,19 @@ REQUIRED_MODULES=" " REQUIRED_BINARIES=" bash - more + curl less agetty - cat - false loadkeys setfont login sulogin - mount - umount mount.nfs4 umount.nfs4 - fdisk mkfs.xfs mkfs.ext3 mkfs.ext4 mkfs.jfs - rm blkid modprobe ps diff --git a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.opensuse b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.opensuse index 91e28a7b..b5630284 100644 --- a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.opensuse +++ b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.opensuse @@ -5,6 +5,7 @@ REQUIRED_INSTALLED_PACKAGES=" timezone libcap2 jfsutils + curl " REQUIRED_CONTENT_PACKAGES=" timezone diff --git a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.ubuntu b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.ubuntu index 2df7df77..646c39a0 100644 --- a/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.ubuntu +++ b/remote/rootfs/rootfs-stage32/rootfs-stage32.conf.ubuntu @@ -5,6 +5,7 @@ REQUIRED_INSTALLED_PACKAGES=" xfsprogs ntpdate jfsutils + curl " REQUIRED_DIRECTORIES=" /lib/xtables -- cgit v1.2.3-55-g7522