You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
1.5 KiB
Bash
90 lines
1.5 KiB
Bash
#!/bin/bash
|
|
# Nomad Bootstrap Script
|
|
# Params:
|
|
# client : bootstraps as client
|
|
|
|
# exit on error
|
|
set -e
|
|
|
|
# create nomad dir
|
|
mkdir -p /opt/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
|
|
chown nomad:nomad /etc/nomad.d/nomad.hcl
|
|
|
|
if [ $nomaduser == "nomad" ]; then
|
|
|
|
# write server config
|
|
cat >/etc/nomad.d/server.hcl <<EOF
|
|
server {
|
|
enabled = true
|
|
bootstrap_expect = 1
|
|
}
|
|
ui {
|
|
enabled = true
|
|
}
|
|
EOF
|
|
chown nomad:nomad /etc/nomad.d/server.hcl
|
|
else
|
|
|
|
# write client config
|
|
cat >/etc/nomad.d/client.hcl <<EOF
|
|
client {
|
|
enabled = true
|
|
}
|
|
EOF
|
|
chown nomad:no
|
|
|
|
fi
|
|
|
|
# reload systemd
|
|
systemctl daemon-reload
|
|
|
|
echo "Done! Run systemctl start to use nomad."
|