]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
storage_deploy: auto-deploys a storage server (not yet functional!)
authorThilo Fromm <thilo.fromm@profitbricks.com>
Tue, 23 Apr 2013 16:25:05 +0000 (18:25 +0200)
committerThilo Fromm <thilo.fromm@profitbricks.com>
Tue, 23 Apr 2013 16:25:05 +0000 (18:25 +0200)
Signed-off-by: Thilo Fromm <thilo.fromm@profitbricks.com>
storage_deploy.sh [new file with mode: 0755]

diff --git a/storage_deploy.sh b/storage_deploy.sh
new file mode 100755 (executable)
index 0000000..972e499
--- /dev/null
@@ -0,0 +1,145 @@
+#!/bin/bash
+
+#
+# Storage server auto-deploy script
+#
+
+rexec() {
+    local srv="$1" ; shift
+
+    ssh -o UserKnownHostsFile=/dev/null     \
+        -o StrictHostKeyChecking=no         \
+        -o PasswordAuthentication=no        \
+        -o ConnectTimeout=1                 \
+        -q root@$srv "$@" || {
+        echo
+        echo "    FAILED. Aborting."
+        echo "     Failed command was '$@'"
+        echo
+        return 1; }
+}
+# ----
+
+while_with_timeout() {
+    local timeout="$1"
+    if [ "$2" = "not" ] ; then
+        local negation="yes"
+        shift
+    fi
+    local condition="$2"
+    local then="$3"
+
+    local start_time=`date +%s`
+
+    if [ "$negation" = "yes" ] ; then
+        until $condition >/dev/null 2>&1; do
+            [ `date +%s` -ge $((start_time + timeout)) ] && return 1
+            $then
+        done
+    else
+        while $condition >/dev/null 2>&1; do
+            [ `date +%s` -ge $((start_time + timeout)) ] && return 1
+            $then
+        done
+    fi
+
+    return 0
+}
+# ----
+
+wait_for_reboot() {
+    local timeout="$1"
+    local srv="$2"
+
+    echo -n "       Waiting for '$srv' to shut down:"
+    while_with_timeout $timeout "ping -c1 -w1 $srv" "echo -n ." || {
+        echo
+        echo "    ERROR: Server did not shut down after 100 seconds."
+        echo
+        return 1
+    }
+    echo
+
+    echo -n "       Waiting for '$srv' to come back:"
+    while_with_timeout $timeout "not" "ping -c1 -w1 $srv" "echo -n ." || {
+        echo
+        echo "    ERROR: Server did not come back after 100 seconds."
+        echo
+        return 1
+    }
+    echo
+
+    echo -n "       Waiting for '$srv' to start its SSH service:"
+    while_with_timeout $timeout "rexec $srv true" "echo -n ." || {
+        echo
+        echo "    ERROR: Server did not start ssh after 100 seconds."
+        echo
+        return 1
+    }
+    echo
+}
+# ----
+
+# 
+# M A I N
+#
+
+main() {
+
+    [ $# -ne 1 ] && {
+        echo
+        echo "    USAGE: $0 <remote-ip>"
+        echo "               remote-ip  IP address of the remote to be "
+        echo "               converted into a storage server."
+        echo 
+
+        exit 1
+    }
+
+    local storage_ip="$1"
+
+    echo "    Cloning pb-overlay in initial bootstrap system"
+    rexec "$storage_ip" "cd /tmp && git clone git://git/so/pb-overlay.git" \
+        || return 1
+
+    echo "    Creating Storage root FS partitions and disk array"
+    rexec "$storage_ip" "cd /tmp/pb-overlay/scripts && ./storage-create-root sda sdb" \
+        || return 1
+
+    echo "    Installing root system (gentoo) from tarball"
+    rexec "$storage_ip" "cd /tmp/pb-overlay/scripts && ./install-gentoo-storage" \
+        || return 1
+
+    echo "    Rebooting"
+    rexec "$storage_ip" "reboot" || return 1
+    wait_for_reboot 100 $storage_ip || { echo "    ABORT"; return 1; }
+
+    echo "    Cloning pb-overlay in storage root FS"
+    rexec "$storage_ip" "cd /tmp && git clone git://git/so/pb-overlay.git" \
+        || return 1
+
+    echo "    Creating storage disk array"
+    rexec "$storage_ip" "cd /tmp/pb-overlay/scripts && ./storage-create-storage sdc sdd sde sdf" \
+        || return 1
+
+    echo "    Rebooting"
+    rexec "$storage_ip" "reboot" ||  return 1
+    wait_for_reboot 100 $storage_ip || { echo "    ABORT"; return 1; }
+}
+
+
+
+
+
+#
+# DEBUG DEBUG DEBUG
+#
+ssh-keygen -f "/home/thilo/.ssh/known_hosts" -R 192.168.49.78
+cat /home/thilo/.ssh/id_rsa.pub | ssh root@192.168.49.78 'mkdir .ssh; cat >.ssh/authorized_keys'
+
+#
+# Be nice and enable sourcing of this script w/o side effects
+
+[ `basename "$0"` = "storage_deploy.sh" ] && main $@
+
+