From e1845b1a6b26f4625de1831014c3dfacd1c773df Mon Sep 17 00:00:00 2001 From: x p k Date: Tue, 19 Feb 2019 23:33:44 +0800 Subject: [PATCH] new: mount-ro check --- sh/mount-ro-xinetd.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 sh/mount-ro-xinetd.sh diff --git a/sh/mount-ro-xinetd.sh b/sh/mount-ro-xinetd.sh new file mode 100755 index 0000000..3836fc1 --- /dev/null +++ b/sh/mount-ro-xinetd.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# script for use with xinetd to monitor readonly filesystem +# +# xinetd config +# service fsro +#{ +# disable = no +# flags = REUSE +# socket_type = stream +# type = UNLISTED +# port = 3333 +# wait = no +# user = nobody +# server = /usr/local/sbin/mount-ro-xinetd.sh +# log_on_failure += USERID +# only_from = 127.0.0.0/8 +#} +# + +function check_ok() { + MSG="$1 healthy" + LEN=$((${#MSG} + 2)) + echo -en "HTTP/1.1 200 OK\r\n" + echo -en "Content-Type: text/plain\r\n" + echo -en "Connection: close\r\n" + echo -en "Content-Length: $LEN\r\n" + echo -en "\r\n" + echo -en "$MSG\r\n" + sleep 0.1 + exit 0 +} + +function check_fail() { + MSG="$1" + LEN=$((${#MSG} + 2)) + echo -en "HTTP/1.1 503 Service Unavailable\r\n" + echo -en "Content-Type: text/plain\r\n" + echo -en "Connection: close\r\n" + echo -en "Content-Length: $LEN\r\n" + echo -en "\r\n" + echo -en "$MSG\r\n" + sleep 0.1 + exit 1 +} + +CHECK_PATH=/tmp +grep -q $CHECK_PATH /proc/mounts || check_fail "Mount missing: $CHECK_PATH" +dd if=/dev/urandom of=$CHECK_PATH/.test01 bs=1M count=10 status=none || check_fail "Write failed: $CHECK_PATH" +dd if=$CHECK_PATH/.test01 of=/dev/null bs=1M status=none || check_fail "Read failed: $CHECK_PATH" +check_ok "$CHECK_PATH"