|
2 | 2 |
|
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | | -export CONTAINERD_VERSION=1.3.4 |
6 | | - |
7 | 5 | main() { |
8 | 6 | echo "INFO: Welcome! nomad-driver-containerd setup." |
9 | | - check_root |
10 | | - check_os |
11 | | - check_nomad |
12 | | - check_golang |
13 | | - |
14 | 7 | echo "WARN: Some installation steps are time consuming. Please be patient!" |
15 | 8 |
|
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 |
33 | 21 | fi |
34 | | - setup_containerd |
35 | 22 |
|
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 |
43 | 25 | echo "INFO: Cleanup any old binaries." |
44 | 26 | make clean >/dev/null 2>&1 |
45 | 27 | 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 |
47 | 29 | 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 |
49 | 31 | 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 |
52 | 34 | echo "INFO: Reload nomad.service systemd unit." |
53 | 35 | systemctl daemon-reload |
54 | 36 | echo "INFO: Starting nomad server + nomad-driver-containerd." |
55 | | - systemctl start nomad || (cleanup && exit 1) |
| 37 | + systemctl start nomad |
56 | 38 | if ! systemctl -q is-active "nomad.service"; then |
57 | 39 | echo "ERROR: nomad.service didn't come up. journalctl -u nomad.service for more info." |
58 | 40 | exit 1 |
59 | 41 | 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) |
136 | 42 | 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." |
141 | 44 | } |
142 | 45 |
|
143 | 46 | drop_nomad_unit_file() { |
|
192 | 95 | mv containerd.service /lib/systemd/system/containerd.service |
193 | 96 | } |
194 | 97 |
|
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 | | - |
235 | 98 | main "$@" |
0 commit comments