#!/bin/bash # Hashicorp Consul bootstrap script # Params: # server : if present, bootstraps a server # bind : bind interface address # server-ip : server ip address # exit on error set -e if [ "$#" -eq 0 ]; then echo "No options specified, exiting." exit 1 elif [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then echo "HashiCorp Consul Bootstrap Script. Provide:" echo "-server for server install," echo "-bind for the bind interface address," echo "-server-ip for the server ip address." exit 1 fi # create consul user useradd --system --home /etc/consul.d --shell /bin/false consul # create directory if doesn't exist and set permissions mkdir -p /etc/consul.d/ && chown -R consul:consul /etc/consul.d/ # create consul data dir and set permissions mkdir -p /opt/consul && chown -R consul:consul /opt/consul # write systemd conf cat >/etc/systemd/system/consul.service </etc/consul.d/consul.hcl </etc/consul.d/server.hcl <