Skip to content

Commit c1707df

Browse files
Setup script updates.
1 parent 765b08a commit c1707df

File tree

2 files changed

+24
-157
lines changed

2 files changed

+24
-157
lines changed

Vagrantfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ Vagrant.configure("2") do |config|
4343
tar -C /usr/local -xzf containerd-1.3.4.linux-amd64.tar.gz
4444
rm -f containerd-1.3.4.linux-amd64.tar.gz
4545
fi
46+
47+
# Run setup
48+
cd /home/vagrant/go/src/nomad-driver-containerd/vagrant
49+
./setup.sh
4650
SHELL
4751
end

vagrant/setup.sh

Lines changed: 20 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2,142 +2,45 @@
22

33
set -euo pipefail
44

5-
export CONTAINERD_VERSION=1.3.4
6-
75
main() {
86
echo "INFO: Welcome! nomad-driver-containerd setup."
9-
check_root
10-
check_os
11-
check_nomad
12-
check_golang
13-
147
echo "WARN: Some installation steps are time consuming. Please be patient!"
158

16-
# Save present working directory (pwd).
17-
curr_dir=$(echo $PWD)
18-
19-
if systemctl -q is-active "containerd.service"; then
20-
echo "WARN: Containerd detected on the system."
21-
read -p "INFO: Backup existing containerd and deploy containerd-${CONTAINERD_VERSION} (Y/N)? Press Y to continue. " -n 1 -r
22-
echo
23-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
24-
echo "INFO: Aborting setup..."
25-
exit 0
26-
fi
27-
systemctl stop containerd
28-
if [ -f "/lib/systemd/system/containerd.service" ]; then
29-
echo "INFO: Backup containerd systemd unit /lib/systemd/system/containerd.service."
30-
mv /lib/systemd/system/containerd.service /lib/systemd/system/containerd.service.bkp
31-
echo "WARN: Backup file saved at: /lib/systemd/system/containerd.service.bkp"
32-
fi
9+
# Save project root directory.
10+
root_dir="/home/vagrant/go/src/nomad-driver-containerd"
11+
pushd $root_dir >/dev/null 2>&1
12+
echo "INFO: Drop systemd unit containerd.service into /lib/systemd/system/containerd.service."
13+
drop_containerd_unit_file
14+
echo "INFO: Reload containerd.service systemd unit."
15+
systemctl daemon-reload
16+
echo "INFO: Starting containerd daemon."
17+
systemctl start containerd
18+
if ! systemctl -q is-active "containerd.service"; then
19+
echo "ERROR: containerd.service didn't come up. journalctl -u containerd.service for more info."
20+
exit 1
3321
fi
34-
setup_containerd
3522

36-
read -p "INFO: Setup nomad server + nomad-driver-containerd (Y/N)? Press Y to continue. " -n 1 -r
37-
echo
38-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
39-
echo "INFO: Aborting setup..."
40-
cleanup
41-
exit 0
42-
fi
23+
echo "INFO: Setup nomad server + nomad-driver-containerd."
24+
export PATH=$PATH:/usr/local/go/bin
4325
echo "INFO: Cleanup any old binaries."
4426
make clean >/dev/null 2>&1
4527
echo "INFO: Build nomad-driver-containerd binary: containerd-driver."
46-
make build >/dev/null 2>&1 || (cleanup && exit 1)
28+
make build >/dev/null 2>&1
4729
echo "INFO: Create plugin-dir for containerd-driver: /tmp/nomad-driver-containerd."
48-
mkdir -p /tmp/nomad-driver-containerd || (cleanup && exit 1)
30+
mkdir -p /tmp/nomad-driver-containerd
4931
echo "INFO: Move containerd-driver to /tmp/nomad-driver-containerd."
50-
mv containerd-driver /tmp/nomad-driver-containerd || (cleanup && exit 1)
51-
drop_nomad_unit_file $curr_dir
32+
mv containerd-driver /tmp/nomad-driver-containerd
33+
drop_nomad_unit_file $root_dir
5234
echo "INFO: Reload nomad.service systemd unit."
5335
systemctl daemon-reload
5436
echo "INFO: Starting nomad server + nomad-driver-containerd."
55-
systemctl start nomad || (cleanup && exit 1)
37+
systemctl start nomad
5638
if ! systemctl -q is-active "nomad.service"; then
5739
echo "ERROR: nomad.service didn't come up. journalctl -u nomad.service for more info."
5840
exit 1
5941
fi
60-
echo "INFO: Setup finished successfully."
61-
}
62-
63-
cleanup() {
64-
echo "INFO: Starting cleanup."
65-
pushd $curr_dir >/dev/null 2>&1
66-
if [ -f "/lib/systemd/system/containerd.service.bkp" ]; then
67-
if systemctl -q is-active "containerd.service"; then
68-
echo "INFO: Stopping containerd."
69-
systemctl stop containerd.service
70-
fi
71-
72-
if [ -f "/tmp/containerd.service" ]; then
73-
echo "INFO: Cleanup /tmp/containerd.service."
74-
rm -f /tmp/containerd.service
75-
fi
76-
77-
if [ -f "/lib/systemd/system/containerd.service" ]; then
78-
echo "INFO: Cleanup: /lib/systemd/system/containerd.service."
79-
rm -f /lib/systemd/system/containerd.service
80-
fi
81-
82-
if [ -f "/tmp/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz" ]; then
83-
echo "INFO: Cleanup: /tmp/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz."
84-
rm -f /tmp/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz
85-
fi
86-
fi
87-
88-
if systemctl -q is-active "nomad.service"; then
89-
echo "INFO: Stopping nomad server+nomad-driver-containerd."
90-
systemctl stop nomad
91-
fi
92-
93-
if [ -f "$curr_dir/nomad.service" ]; then
94-
echo "INFO: Cleanup $curr_dir/nomad.service."
95-
rm -f $curr_dir/nomad.service
96-
fi
97-
98-
if [ -f "/lib/systemd/system/nomad.service" ]; then
99-
echo "INFO: Cleanup: /lib/systemd/system/nomad.service."
100-
rm -f /lib/systemd/system/nomad.service
101-
fi
102-
103-
echo "INFO: Cleanup /tmp/nomad-driver-containerd."
104-
rm -rf /tmp/nomad-driver-containerd
105-
106-
echo "INFO: Cleanup containerd-driver binary."
107-
make clean >/dev/null 2>&1
108-
popd >/dev/null 2>&1
109-
echo "INFO: Cleanup complete."
110-
}
111-
112-
setup_containerd() {
113-
read -p "INFO: Download containerd (Y/N)? Press Y to continue. " -n 1 -r
114-
echo
115-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
116-
echo "INFO: Aborting setup..."
117-
cleanup
118-
exit 0
119-
fi
120-
pushd /tmp >/dev/null 2>&1
121-
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 || (cleanup && exit 1)
122-
tar -C /usr/local -xzf containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz || (cleanup && exit 1)
123-
rm -f containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz
124-
read -p "INFO: Drop systemd unit containerd.service into /lib/systemd/system/containerd.service (Y/N)? Press Y to continue. " -n 1 -r
125-
echo
126-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
127-
echo "INFO: Aborting setup..."
128-
cleanup
129-
exit 0
130-
fi
131-
drop_containerd_unit_file
132-
echo "INFO: Reload containerd.service systemd unit."
133-
systemctl daemon-reload
134-
echo "INFO: Starting containerd daemon."
135-
systemctl start containerd || (cleanup && exit 1)
13642
popd >/dev/null 2>&1
137-
if ! systemctl -q is-active "containerd.service"; then
138-
echo "ERROR: containerd.service didn't come up. journalctl -u containerd.service for more info."
139-
exit 1
140-
fi
43+
echo "INFO: Setup finished successfully."
14144
}
14245

14346
drop_nomad_unit_file() {
@@ -192,44 +95,4 @@ EOF
19295
mv containerd.service /lib/systemd/system/containerd.service
19396
}
19497

195-
check_golang() {
196-
set +e
197-
go version >/dev/null 2>&1
198-
rc=$?
199-
set -e
200-
if [ $rc -ne 0 ];then
201-
echo "ERROR: Golang is missing. Please install golang >=1.11 to continue with the setup."
202-
exit 1
203-
fi
204-
}
205-
206-
check_nomad() {
207-
set +e
208-
which nomad >/dev/null 2>&1
209-
rc=$?
210-
set -e
211-
if [ $rc -ne 0 ];then
212-
echo "ERROR: Nomad is missing. Please install nomad >=0.11 to continue with the setup."
213-
exit 1
214-
fi
215-
}
216-
217-
check_root() {
218-
if [ $(id -u) != 0 ]; then
219-
echo "ERROR: Run as root user."
220-
exit 1
221-
fi
222-
}
223-
224-
check_os() {
225-
set +e
226-
cat /etc/os-release|grep -q -i "Ubuntu"
227-
rc=$?
228-
set -e
229-
if [ $rc -ne 0 ];then
230-
echo "ERROR: Unsupported host OS. Run tests on Ubuntu."
231-
exit 1
232-
fi
233-
}
234-
23598
main "$@"

0 commit comments

Comments
 (0)