Moved common patches

This commit is contained in:
Manfred Touron 2014-10-23 18:08:52 +02:00
parent f31e695620
commit aba3da2a7f
5 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#!/bin/sh
# description "executable which retrieves server metadata (TEXT)"
# author "Online Labs Cloud Team <cloud-team@labs.online.net>"
CODE=0
while [ $CODE -ne 200 ]
do
METADATA_URL=${METADATA_URL:-"http://169.254.42.42/conf"}
RESPONSE=$(curl --silent --write-out "\n%{http_CODE}\n" $METADATA_URL)
CODE=$(echo "$RESPONSE" | sed -n '$p')
BODY=$(echo "$RESPONSE" | sed '$d')
test $CODE -eq 200 && break
sleep 5
done
if [ "$#" -ne 1 ]; then
echo "$BODY"
else
key="$1"
echo "$BODY" | grep "^$key=" | cut -d= -f2 | sed "s/^['\"]//;s/['\"]$//"
fi

View File

@ -0,0 +1,15 @@
#!/bin/sh
# description "executable which retrieves server metadata (JSON)"
# author "Online Labs Cloud Team <cloud-team@labs.online.net>"
CODE=0
while [ $CODE -ne 200 ]
do
RESPONSE=$(curl --silent --write-out "\n%{http_CODE}\n" http://169.254.42.42/conf?format=json)
CODE=$(echo "$RESPONSE" | sed -n '$p')
BODY=$(echo "$RESPONSE" | sed '$d')
test $CODE -eq 200 && break
sleep 5
done
echo "$BODY"

View File

@ -0,0 +1,74 @@
#!/bin/sh
# Thanks to the LTSP project
# If the root /dev/nbd0 device is unmounted on shutdown then nbd read
# errors occur, and if it isn't, then # the nbd-server process on the server
# doesn't terminate.
# Called by init scripts on reboot or shutdown.
case "$RUNLEVEL" in
0)
key="o"
command="poweroff -f"
;;
6)
key="b"
command="reboot"
;;
*)
echo "nbd-disconnect should only be called by initscripts on reboot/shutdown." >&2
exit 1
;;
esac
disconnect() {
# Stop trapping
trap - 0 HUP INT QUIT KILL SEGV PIPE TERM
# ltsp-client-core.upstart needs "console output" to show stderr
echo "nbd-disconnect executing: " >&2
# Cache the command in order to use it after nbd-client disconnects
$command --version >/dev/null 2>&1
nbd-client -d "$root"
$command
# Hopefully this should never be reached
echo "$key" > /proc/sysrq-trigger
}
# Disconnect swap nbd devices first
while read device etc; do
case "$device" in
/dev/nbd[0-9])
swapoff "$device"
nbd-client -d "$device"
;;
/dev/mapper/swap[0-9])
nbd_device=$(cryptsetup status "$device" | awk '/device:/{print $2}')
swapoff "$device"
cryptsetup remove "$device"
case "$nbd_device" in
/dev/nbd[1-9])
nbd-client -d "$nbd_device"
;;
esac
;;
esac
done < /proc/swaps
# If we're not using an nbd root, exit
unset root
for param in $(cat /proc/cmdline); do
case "$param" in
root=/dev/nbd[0-9])
root="${param#root=}"
;;
esac
done
test -n "$root" || exit 0
trap "disconnect" 0 HUP INT QUIT KILL SEGV PIPE TERM
sync
# Give up to 5 seconds for other services to be called.
# If they finish before that time, process termination will start, and the trap
# will be called.
sleep 5

View File

@ -0,0 +1,70 @@
#!/bin/bash
METADATA_CACHE=`mktemp -u`
get_metadata() {
if [ ! -f $METADATA_CACHE ]; then
/usr/local/bin/oc-metadata > $METADATA_CACHE
fi
}
get_value() {
# Get value from metadata
key="$1"
grep "^$key=" "$METADATA_CACHE" | cut -d= -f2 | sed "s/^['\"]//;s/['\"]$//"
}
get_nbd_client_conf() {
keys=$(get_value VOLUMES)
cat <<EOF
# If you don't want to reconfigure this package after installing, uncomment
# the following line:
#AUTO_GEN="n"
# If you don't want the init script to kill nbd-client devices that aren't
# specified in this configuration file, set the following to "false":
KILLALL="false"
# Note that any statical settings in this file will be preserved
# regardless of the setting of AUTO_GEN, so its use is only recommended
# if you set things in a dynamical way (e.g., through a database)
EOF
conf_id=0
for key in $keys; do
# Do not include the rootfs in nbd configuration file. It has been mounted
# from the initramfs, we won't want it to be disconnected when
# /etc/rc6.d/K34nbd-client is executed.
test $key -eq 0 && continue
# NBD_TYPE[x]=r => raw (no other setup than to run the client)
cat <<EOF
#
NBD_TYPE[$conf_id]=r
NBD_DEVICE[$conf_id]=/dev/nbd$key
NBD_HOST[$conf_id]=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://\(.*\):.*|\1|')
NBD_PORT[$conf_id]=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://.*:\(.*\)|\1|')
EOF
conf_id=$((conf_id + 1))
done
}
nbd_clients_connection() {
/etc/init.d/nbd-client start
keys=$(get_value VOLUMES)
for key in $keys; do
test $key -eq 0 && continue
NBD_DEVICE=/dev/nbd$key
until nbd-client -c $NBD_DEVICE
do
/etc/init.d/nbd-client start
sleep 5
done
done
}
get_metadata
get_nbd_client_conf > /etc/nbd-client
nbd_clients_connection
rm $METADATA_CACHE

View File

@ -0,0 +1,29 @@
#!/bin/sh
# description "synchronizes kernel module"
# author "Online Labs Cloud Team <cloud-team@labs.online.net>"
DIR=/lib/modules
mkdir -p $DIR
TMP_DIR=`mktemp -d -p $DIR`
KVERSION=`uname -r`
TIMEOUT=10
clean() {
rm -rf "$TMP_DIR" 2>/dev/null
}
trap 'clean' INT TERM EXIT
if [ ! -d $DIR/${KVERSION} ]
then
wget --timeout=${TIMEOUT} --quiet --no-check-certificate -r --no-parent \
--reject "index.html*" --reject "robots.txt" \
--no-host-directories --cut-dirs 3 --directory-prefix \
$TMP_DIR http://mirror.cloud.online.net/kernel/${KVERSION}/modules/${KVERSION}/
if [ $? -eq 0 ]
then
mkdir -p $DIR/${KVERSION}
mv $TMP_DIR/${KVERSION} $DIR
fi
fi