summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lwirzenius@wikimedia.org>2020-09-18 16:20:38 +0300
committerLars Wirzenius <lwirzenius@wikimedia.org>2020-09-18 16:20:38 +0300
commit1fa4d74be20a1aa7a94e44070b445fc5a224387b (patch)
tree121a9b66cd0e1b98c7f403b9eb285208564fe5c0
parentbf7a156b8eb2939e603cce3063569db3463bd20b (diff)
downloadick-contractor-1fa4d74be20a1aa7a94e44070b445fc5a224387b.tar.gz
start/stop
-rwxr-xr-xcontra.sh43
-rw-r--r--ssh.config.in6
-rwxr-xr-xvm-qemu.sh2
3 files changed, 50 insertions, 1 deletions
diff --git a/contra.sh b/contra.sh
new file mode 100755
index 0000000..341c34a
--- /dev/null
+++ b/contra.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+set -eu
+
+wait_for_ssh()
+{
+ while ! ssh "$@" true 2>/dev/null
+ do
+ sleep 5
+ done
+}
+
+update_ssh_config()
+{
+ sed "s/<PORT>/$3/g" "$1" > "$2"
+}
+
+main()
+{
+ local image
+ local port
+ local pubkey
+ local pid
+
+ image="$1"
+ port="$2"
+ pubkey="$3"
+
+ update_ssh_config ssh.config.in ssh.config "$port"
+
+ ./vm-qemu.sh "$image" "$port" "$pubkey" > qemu.out &
+ pid="$!"
+
+ wait_for_ssh -F ssh.config contractor
+
+ echo "wait a minute"
+ sleep 60
+
+ ssh -F ssh.config contractor '(sleep 2; sudo poweroff) &'
+ wait "$pid"
+}
+
+main "$@"
diff --git a/ssh.config.in b/ssh.config.in
new file mode 100644
index 0000000..ad023ce
--- /dev/null
+++ b/ssh.config.in
@@ -0,0 +1,6 @@
+host contractor
+hostname localhost
+user debian
+port <PORT>
+userknownhostsfile /dev/null
+stricthostkeychecking accept-new
diff --git a/vm-qemu.sh b/vm-qemu.sh
index ab39ef1..71a9698 100755
--- a/vm-qemu.sh
+++ b/vm-qemu.sh
@@ -2,7 +2,7 @@
#
# Create a new VM using libvirt on the local host.
-set -eux
+set -eu
verbose()