From a6469135d6222a1c27fbe0a48c41a6b808210da3 Mon Sep 17 00:00:00 2001
From: Arie Peterson <arie@greenhost.nl>
Date: Wed, 14 Nov 2018 17:33:04 +0100
Subject: [PATCH] Move control container invocation to separate script

---
 bootstrap.sh     | 23 +++++++++++++++++++++--
 control-shell.sh | 15 +++++++++++++++
 control.sh       |  7 +------
 get-control.sh   |  2 +-
 4 files changed, 38 insertions(+), 9 deletions(-)
 create mode 100755 control-shell.sh

diff --git a/bootstrap.sh b/bootstrap.sh
index 086380cd7..9ae40adf0 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -8,8 +8,27 @@ else
     host=$1
 fi
 
+prepareNode()
+{
+    ssh "root@${host}" "bash -s" -- "$host" <prepare-node.sh
+}
+
+getControl()
+{
+    ssh "root@${host}" "bash -s" -- <get-control.sh
+    scp "./control-shell.sh" "root@${host}:/oas/bin/control-shell.sh"
+}
+
+setup()
+{
+    ssh -t "root@${host}" "CONTROL=bootstrap /bin/bash --init-file /oas/bin/control-shell.sh"
+}
+
 if [ -z "$2" ]
 then
-    ssh "root@${host}" "bash -s" -- "$host" <prepare-node.sh
+    prepareNode
+    getControl
+    setup
+else
+    $2
 fi
-ssh "root@${host}" "bash -s" -- <get-control.sh
diff --git a/control-shell.sh b/control-shell.sh
new file mode 100755
index 000000000..5eb9ed4dc
--- /dev/null
+++ b/control-shell.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+if [ "$CONTROL" == "bootstrap" ]
+then
+    echo "Bootstrapping cluster..."
+    command="/control/bin/control setup"
+else
+    echo "Starting control shell..."
+    command="/bin/bash --init-file /control/.bashrc"
+fi
+docker run --rm -it \
+    -v /oas:/oas \
+    -v /oas/local/control:/control/local \
+    --name oas-control \
+    docker.greenhost.net/openappstack/control \
+    $command
diff --git a/control.sh b/control.sh
index 93b407d42..1ecb24788 100755
--- a/control.sh
+++ b/control.sh
@@ -8,9 +8,4 @@ else
     host=$1
 fi
 
-ssh -t "root@${host}" "docker run --rm -it \
-    -v /oas:/oas \
-    -v /oas/local/control:/control/local \
-    --name oas-control \
-    docker.greenhost.net/openappstack/control \
-    /bin/bash"
+ssh -t "root@${host}" "/oas/bin/control-shell.sh"
diff --git a/get-control.sh b/get-control.sh
index 8fcc7df56..e68516283 100644
--- a/get-control.sh
+++ b/get-control.sh
@@ -4,7 +4,7 @@ hostname=$(hostname)
 configDir="/oas/config"
 sshKeyFile="${configDir}/ssh_key"
 
-mkdir -p "/oas/local/control"
+mkdir -p "/oas/local/control" "/oas/bin"
 
 # Set up ssh access from local control container.
 if ! [ -f "$sshKeyFile" ]
-- 
GitLab