setup.sh: Fix issues.
This commit is contained in:
parent
c7d64bc732
commit
d41fd1e0a6
45
setup.sh
45
setup.sh
@ -3,18 +3,21 @@
|
||||
set -euo pipefail
|
||||
|
||||
export CONTAINERD_VERSION=1.3.4
|
||||
export GOBIN="/usr/local/go/bin/go"
|
||||
|
||||
main() {
|
||||
echo "INFO: Welcome! nomad-driver-containerd setup."
|
||||
check_root
|
||||
check_os
|
||||
check_nomad
|
||||
check_golang
|
||||
read -p "INFO: Download containerd (Y/N)? Press Y to continue. " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborting setup..."
|
||||
exit 0
|
||||
fi
|
||||
pushd /tmp
|
||||
pushd /tmp >/dev/null 2>&1
|
||||
curl -L --silent -o containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz
|
||||
tar -C /usr/local -xzf containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz
|
||||
rm -f containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz
|
||||
@ -29,7 +32,7 @@ main() {
|
||||
systemctl daemon-reload
|
||||
echo "INFO: Starting containerd daemon."
|
||||
systemctl start containerd
|
||||
popd
|
||||
popd >/dev/null 2>&1
|
||||
read -p "INFO: Setup nomad server + nomad-driver-containerd (Y/N)? Press Y to continue. " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
@ -37,14 +40,15 @@ main() {
|
||||
exit 0
|
||||
fi
|
||||
echo "INFO: Cleanup any old binaries."
|
||||
make clean
|
||||
make clean >/dev/null 2>&1
|
||||
echo "INFO: Build nomad-driver-containerd binary: containerd-driver."
|
||||
make build
|
||||
make build >/dev/null 2>&1
|
||||
echo "INFO: Create plugin-dir for containerd-driver: /tmp/nomad-driver-containerd."
|
||||
mkdir -p /tmp/nomad-driver-containerd
|
||||
echo "INFO: Move containerd-driver to /tmp/nomad-driver-containerd."
|
||||
mv containerd-driver /tmp/nomad-driver-containerd
|
||||
drop_nomad_unit_file echo $PWD
|
||||
local curr_dir=$(echo $PWD)
|
||||
drop_nomad_unit_file $curr_dir
|
||||
echo "INFO: Reload nomad.service systemd unit."
|
||||
systemctl daemon-reload
|
||||
echo "INFO: Starting nomad server + nomad-driver-containerd."
|
||||
@ -53,7 +57,7 @@ main() {
|
||||
}
|
||||
|
||||
drop_nomad_unit_file() {
|
||||
local curr_dir=$1
|
||||
local nomad=$(which nomad)
|
||||
# Drop nomad server (dev) + nomad-driver-containerd systemd unit file into /lib/systemd/system.
|
||||
cat << EOF > nomad.service
|
||||
# /lib/systemd/system/nomad.service
|
||||
@ -63,7 +67,7 @@ Documentation=https://nomadproject.io
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/nomad agent -dev -config=$curr_dir/example/agent.hcl -plugin-dir=/tmp/nomad-driver-containerd
|
||||
ExecStart=$nomad agent -dev -config=$1/example/agent.hcl -plugin-dir=/tmp/nomad-driver-containerd
|
||||
KillMode=process
|
||||
Delegate=yes
|
||||
LimitNOFILE=1048576
|
||||
@ -77,7 +81,6 @@ EOF
|
||||
mv nomad.service /lib/systemd/system/nomad.service
|
||||
}
|
||||
|
||||
|
||||
drop_containerd_unit_file() {
|
||||
# Drop containerd systemd unit file into /lib/systemd/system.
|
||||
cat << EOF > containerd.service
|
||||
@ -105,6 +108,27 @@ EOF
|
||||
mv containerd.service /lib/systemd/system/containerd.service
|
||||
}
|
||||
|
||||
check_golang() {
|
||||
set +e
|
||||
stat $GOBIN >/dev/null 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
if [ $rc -ne 0 ];then
|
||||
echo "ERROR: Golang is missing. Please install golang >=1.11 to continue with the setup."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_nomad() {
|
||||
set +e
|
||||
which nomad >/dev/null 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
if [ $rc -ne 0 ];then
|
||||
echo "ERROR: Nomad is missing. Please install nomad >=0.11 to continue with the setup."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [ $(id -u) != 0 ]; then
|
||||
@ -114,8 +138,11 @@ check_root() {
|
||||
}
|
||||
|
||||
check_os() {
|
||||
set +e
|
||||
cat /etc/os-release|grep -q -i "Ubuntu"
|
||||
if [ $? -ne 0 ];then
|
||||
rc=$?
|
||||
set -e
|
||||
if [ $rc -ne 0 ];then
|
||||
echo "ERROR: Unsupported host OS. Run tests on Ubuntu."
|
||||
exit 1
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user