Last active
August 30, 2019 09:41
-
-
Save devops-rob/dd6f11af22e96f4f18c54daceea3f1e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function packagereqchecker { | |
declare -a packages=("wget" "setroubleshoot-server" "selinux-policy-devel" "unzip") | |
for app in "${packages[@]}"; | |
do | |
echo $app | |
if yum list installed $app 2>&1 > /dev/null; | |
then | |
echo "$app is already installed" | |
else | |
yum install $app -y > /dev/null | |
fi | |
done | |
} | |
function consul_user { | |
if id "consul" > /dev/null 2>&1; then | |
echo "consul user already exists" | |
else | |
sudo useradd --system --home /etc/consul.d --shell /bin/false consul | |
fi | |
if [ ! -d /opt/consul ]; then | |
sudo mkdir -p /opt/consul | |
sudo chown -R consul:consul /opt/consul | |
sudo chmod -R 777 /opt/consul | |
fi | |
} | |
function consul_installer { | |
if consul; | |
then | |
echo "consul is already installed" | |
else | |
CONSUL_VERSION="1.6.0" | |
wget -O consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip | |
unzip consul.zip | |
chown root:root consul | |
mv consul /usr/local/bin/ | |
consul -autocomplete-install | |
complete -C /usr/local/bin/consul consul | |
fi | |
} | |
function consul_config { | |
if [ -f /etc/consul.d/tls/ ]; | |
then | |
echo "config directory already exists" | |
else | |
sudo mkdir -p /etc/consul.d/tls | |
sudo chown -R consul:consul /etc/consul.d | |
sudo touch /etc/consul.d/consul.hcl | |
sudo chmod -R 644 /etc/consul.d/tls | |
fi | |
} | |
function systemd_config { | |
if [ -f /etc/systemd/system/consul.service ]; | |
then | |
echo "consul service is already cofigured" | |
else | |
touch /etc/systemd/system/consul.service | |
cat > /etc/systemd/system/consul.service <<EOF | |
[Unit] | |
Description="HashiCorp Consul - A service mesh solution" | |
Documentation=https://www.consul.io/ | |
Requires=network-online.target | |
After=network-online.target | |
ConditionFileNotEmpty=/etc/consul.d/consul.hcl | |
[Service] | |
User=consul | |
Group=consul | |
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d/ | |
ExecReload=/usr/local/bin/consul reload | |
KillMode=process | |
Restart=on-failure | |
LimitNOFILE=65536 | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl daemon-reload | |
fi | |
} | |
packagereqchecker | |
consul_installer | |
consul_config | |
consul_user | |
systemd_config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment