From 66010a52badad44043361be790b69060d67887b0 Mon Sep 17 00:00:00 2001 From: Ayush Mukherjee Date: Tue, 7 Dec 2021 23:06:15 +0530 Subject: [PATCH] add consul bootstrap script --- consul-bootstrap.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 consul-bootstrap.sh diff --git a/consul-bootstrap.sh b/consul-bootstrap.sh new file mode 100755 index 0000000..1de6349 --- /dev/null +++ b/consul-bootstrap.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Hashicorp Consul bootstrap script +# Params: +# server : if present, bootstraps a server +# bind : bind interface address +# server-ip : server ip address + +# create directory if doesn't exist and set permissions +mkdir -p /opt/consul/{config, data} && chmod 700 /opt/consul + +# parameter setup +consulopts="-config-dir=/opt/consul/config -data-dir=/opt/consul/data" +consultype="client" + +# read parameters +while [[ "$#" -gt 0 ]] +do + case $1 in + -server) + consulopts+="-server " + consultype="server" + ;; + -bind) + consulopts+="-bind=$2 " + ;; + -server-ip) + consulopts+="-retry-join=$2 " + ;; + esac + shift +done + +printf "initializing consul $consultype with following options: \n%s\n" "$consulopts" + +consul=$(which consul) +$consul $consulopts