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.
95 lines
1.6 KiB
Bash
95 lines
1.6 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
|
|
|
|
|
|
|
|
# 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
|
|
chmod 640 /etc/nomad.d/nomad.hcl
|
|
chown nomad:nomad /etc/nomad.d/nomad.hcl
|
|
|
|
if [ $nomaduser == "nomad" ]; then
|
|
|
|
# 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
|
|
|
|
[Service]
|
|
User = root
|
|
Group = root
|
|
ExecReload=/bin/kill -HUP \$MAINPID
|
|
ExecStart=/usr/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
|
|
|
|
# write server config
|
|
cat >/etc/nomad.d/server.hcl <<EOF
|
|
server {
|
|
enabled = true
|
|
bootstrap_expect = 1
|
|
}
|
|
client {
|
|
enabled = true
|
|
}
|
|
consul {
|
|
address = "127.0.0.1:8500"
|
|
}
|
|
EOF
|
|
chmod 640 /etc/nomad.d/server.hcl
|
|
chown nomad:nomad /etc/nomad.d/server.hcl
|
|
|
|
#else
|
|
|
|
# write client config
|
|
# cat >/etc/nomad.d/client.hcl <<EOF
|
|
#client {
|
|
# enabled = true
|
|
#}
|
|
#EOF
|
|
# chmod 640 /etc/nomad.d/client.hcl
|
|
# chown nomad:nomad /etc/nomad.d/client.hcl
|
|
|
|
fi
|
|
|
|
# reload systemd
|
|
systemctl daemon-reload
|
|
|
|
echo "Done! Run systemctl start to use nomad."
|