add nomad bootstrap script
parent
514f636692
commit
8fe9dc7517
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
# Nomad Bootstrap Script
|
||||
# Params:
|
||||
# client : bootstraps as client
|
||||
|
||||
# exit on error
|
||||
set -e
|
||||
|
||||
# create nomad dir
|
||||
mkdir -p /opt/nomad
|
||||
|
||||
# create nomad user
|
||||
useradd --system --home /etc/nomad.d --shell /bin/false nomad
|
||||
|
||||
nomaduser=nomad
|
||||
nomadgroup=nomad
|
||||
|
||||
if [ "$#" -eq 1 ] && [ "$1" == "-client" ]; then
|
||||
echo "bootstraping as nomad client"
|
||||
nomaduser=root
|
||||
nomadgroup=root
|
||||
fi
|
||||
|
||||
|
||||
# write systemd conf
|
||||
cat >/etc/systemd/system/nomad.service <<EOF
|
||||
[Unit]
|
||||
Description = Nomad
|
||||
Documentation = https://nomadproject.io/docs/
|
||||
Wants = network-online.target
|
||||
After = network-online.target
|
||||
|
||||
Wants = consul.service
|
||||
After = consul.service
|
||||
|
||||
[Service]
|
||||
User = $nomaduser
|
||||
Group = $nomadgroup
|
||||
ExecReload=/bin/kill -HUP \$MAINPID
|
||||
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad.d
|
||||
KillMode=process
|
||||
KillSignal=SIGINT
|
||||
LimitNOFILE=65536
|
||||
LimitNPROC=infinity
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
TasksMax=infinity
|
||||
OOMScoreAdjust=-1000
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# create config dir
|
||||
mkdir -p /etc/nomad.d && chmod 700 /etc/nomad.d
|
||||
|
||||
# write common nomad config
|
||||
cat >/etc/nomad.d/nomad.hcl <<EOF
|
||||
datacenter = "dc1"
|
||||
data_dir = "/opt/nomad"
|
||||
EOF
|
||||
|
||||
if [ $nomaduser == "nomad" ]; then
|
||||
|
||||
# write server config
|
||||
cat >/etc/nomad.d/server.hcl <<EOF
|
||||
server {
|
||||
enabled = true
|
||||
bootstrap_expect = 1
|
||||
}
|
||||
EOF
|
||||
|
||||
else
|
||||
|
||||
# write client config
|
||||
cat >/etc/nomad.d/client.hcl <<EOF
|
||||
client {
|
||||
enabled = true
|
||||
}
|
||||
EOF
|
||||
|
||||
fi
|
||||
|
||||
# reload systemd
|
||||
systemctl daemon-reload
|
||||
|
||||
# enable and start service
|
||||
systemctl enable --now nomad.service
|
||||
|
||||
echo "Done! Nomad service enabled and started."
|
Loading…
Reference in New Issue