Browse Source

start/stop script

standalone
Nicolas Massé 5 years ago
parent
commit
b5a5df7f8c
  1. 52
      cluster
  2. 2
      local.env.sample
  3. 6
      main.tf
  4. 12
      post-install.tf
  5. 30
      templates/start.sh
  6. 22
      templates/stop.sh

52
cluster

@ -70,6 +70,30 @@ function apply () {
openshift-install --dir="$cluster_name" wait-for install-complete
}
function start () {
local cluster_name="${1:-}"
if [ ! -d "$cluster_name" ]; then
echo "Cluster '$cluster_name' does not exist!"
exit 1
fi
scp "$cluster_name/start.sh" "$LIBVIRT_USER@$LIBVIRT_SERVER:/tmp/start.sh"
ssh "$LIBVIRT_USER@$LIBVIRT_SERVER" /tmp/start.sh
}
function stop () {
local cluster_name="${1:-}"
if [ ! -d "$cluster_name" ]; then
echo "Cluster '$cluster_name' does not exist!"
exit 1
fi
scp "$cluster_name/stop.sh" "$LIBVIRT_USER@$LIBVIRT_SERVER:/tmp/stop.sh"
ssh "$LIBVIRT_USER@$LIBVIRT_SERVER" /tmp/stop.sh
}
function post_install_nfs () {
local cluster_name="${1:-}"
@ -155,6 +179,8 @@ if [ ! -e "local.env" ]; then
fi
source local.env
export LC_ALL=C
export LANG=C
case "${1:-}" in
init)
@ -165,6 +191,30 @@ init)
shift
bootstrap "$@"
;;
start)
if [ -z "${2:-}" ]; then
echo "Usage: $0 start cluster-name"
exit 1
fi
shift
start "$@"
;;
stop)
if [ -z "${2:-}" ]; then
echo "Usage: $0 stop cluster-name"
exit 1
fi
shift
stop "$@"
;;
apply)
if [ -z "${2:-}" ]; then
echo "Usage: $0 apply cluster-name"
exit 1
fi
shift
apply "$@"
;;
apply)
if [ -z "${2:-}" ]; then
echo "Usage: $0 apply cluster-name"
@ -190,7 +240,7 @@ post-install)
post_install "$@"
;;
*)
echo "Usage: $0 {init|apply|post-install|destroy} cluster-name"
echo "Usage: $0 {init|apply|post-install|destroy|start|stop} cluster-name"
exit 1
;;
esac

2
local.env.sample

@ -5,3 +5,5 @@ export GOOGLE_CLIENT_ID="client_id"
export GOOGLE_CLIENT_SECRET="client_secret"
export LE_EMAIL="user@redhat.com"
export OCP_ADMIN="user@redhat.com"
export LIBVIRT_USER="user"
export LIBVIRT_SERVER="libvirt.server"

6
main.tf

@ -25,9 +25,11 @@ terraform {
}
locals {
ocp_nodes = { for i in concat(libvirt_domain.bootstrap, libvirt_domain.master, libvirt_domain.worker) : i.name => i.network_interface.0.addresses[0] }
master_nodes = { for i in libvirt_domain.master : i.name => i.network_interface.0.addresses[0] }
worker_nodes = { for i in libvirt_domain.worker : i.name => i.network_interface.0.addresses[0] }
bootstrap_nodes = { for i in libvirt_domain.bootstrap : i.name => i.network_interface.0.addresses[0] }
additional_nodes = { (libvirt_domain.lb.name) = cidrhost(var.network_ip_range, 4), (libvirt_domain.storage.name) = libvirt_domain.storage.network_interface.0.addresses[0] }
all_nodes = merge(local.ocp_nodes, local.additional_nodes)
all_nodes = merge(local.additional_nodes, local.master_nodes, local.worker_nodes, local.bootstrap_nodes)
}
output "machines" {

12
post-install.tf

@ -16,6 +16,18 @@ resource "local_file" "dns_config" {
file_permission = "0644"
}
resource "local_file" "stop_sh" {
content = templatefile("${path.module}/templates/stop.sh", { masters = libvirt_domain.master.*.name, workers = libvirt_domain.worker.*.name, lb = libvirt_domain.lb.name, storage = libvirt_domain.storage.name })
filename = "${var.cluster_name}/stop.sh"
file_permission = "0755"
}
resource "local_file" "start_sh" {
content = templatefile("${path.module}/templates/start.sh", { masters = local.master_nodes, workers = local.worker_nodes, others = local.additional_nodes })
filename = "${var.cluster_name}/start.sh"
file_permission = "0755"
}
resource "null_resource" "dnsmasq_config" {
triggers = {
network_id = libvirt_network.ocp_net.id

30
templates/start.sh

@ -0,0 +1,30 @@
#!/bin/sh
set -Eeuo pipefail
trap "exit" INT
function start () {
for i; do
sudo virsh start "$i" || true
done
}
function wait_for_ip () {
echo "Waiting for $1 to come online..."
while ! ping -n -c4 -i.2 $2 -q &>/dev/null; do
sleep 1
done
}
%{for host, ip in others~}
start "${host}"
wait_for_ip "${host}" "${ip}"
%{endfor~}
%{for host, ip in masters~}
start "${host}"
%{endfor~}
%{for host, ip in workers~}
start "${host}"
%{endfor~}

22
templates/stop.sh

@ -0,0 +1,22 @@
#!/bin/sh
set -Eeuo pipefail
trap "exit" INT
function stop_group () {
for i; do
sudo virsh shutdown "$i" --mode=agent || true
done
for i; do
echo "Waiting for $i to shutdown..."
while sudo virsh list --name | egrep -q "^$i\$"; do
sleep 1
continue
done
done
}
stop_group %{for host in workers}"${host}" %{endfor}
stop_group %{for host in masters}"${host}" %{endfor}
stop_group "${lb}" "${storage}"
Loading…
Cancel
Save