1 #!/bin/bash -euxo pipefail
3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: Apache-2.0
10 while $SUDO fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do
11 echo "APT: Waiting for apt/dpkg locks to be released..."
17 $SUDO DEBIAN_FRONTEND=noninteractive apt-get --yes update
19 # Install gnupg and dirmgr or gpg key checks will fail
20 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
25 # For good measure, apt-get upgrade
26 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes upgrade
28 # Make sure cloud-init is installed
29 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install cloud-init
30 if [[ ! -d /var/lib/cloud/scripts/per-boot ]]; then
31 mkdir -p /var/lib/cloud/scripts/per-boot
34 TMP_LSB=`/usr/bin/lsb_release -c -s`
35 LSB_RELEASE_CODENAME=${TMP_LSB//[$'\t\r\n ']}
37 # Add the arvados apt repository
38 echo "# apt.arvados.org" |$SUDO tee --append /etc/apt/sources.list.d/apt.arvados.org.list
39 echo "deb http://apt.arvados.org/$LSB_RELEASE_CODENAME $LSB_RELEASE_CODENAME${REPOSUFFIX} main" |$SUDO tee --append /etc/apt/sources.list.d/apt.arvados.org.list
41 # Add the arvados signing key
42 cat /tmp/1078ECD7.asc | $SUDO apt-key add -
44 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get install --yes debian-keyring debian-archive-keyring
47 $SUDO /bin/sed -ri 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
48 $SUDO /usr/sbin/locale-gen
50 # Install some packages we always need
51 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get --yes update
52 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
58 libcurl4-openssl-dev \
64 # Install the Arvados packages we need
65 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
66 python3-arvados-fuse \
68 arvados-docker-cleaner \
71 # Get Go and build singularity
73 mkdir -p /var/lib/arvados
74 rm -rf /var/lib/arvados/go/
75 curl -s https://storage.googleapis.com/golang/go${goversion}.linux-amd64.tar.gz | tar -C /var/lib/arvados -xzf -
76 ln -sf /var/lib/arvados/go/bin/* /usr/local/bin/
78 singularityversion=3.7.4
79 curl -Ls https://github.com/sylabs/singularity/archive/refs/tags/v${singularityversion}.tar.gz | tar -C /var/lib/arvados -xzf -
80 cd /var/lib/arvados/singularity-${singularityversion}
82 # build dependencies for singularity
83 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
84 make build-essential libssl-dev uuid-dev cryptsetup
86 echo $singularityversion > VERSION
87 ./mconfig --prefix=/var/lib/arvados
89 make -C ./builddir install
90 ln -sf /var/lib/arvados/bin/* /usr/local/bin/
92 # set `mksquashfs mem` in the singularity config file if it is configured
93 if [ "$MKSQUASHFS_MEM" != "" ]; then
94 echo "mksquashfs mem = ${MKSQUASHFS_MEM}" >> /var/lib/arvados/etc/singularity/singularity.conf
97 # Print singularity version installed
100 # Remove unattended-upgrades if it is installed
101 wait_for_apt_locks && $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes remove unattended-upgrades --purge
103 # Configure arvados-docker-cleaner
104 $SUDO mkdir -p /etc/arvados/docker-cleaner
105 $SUDO echo -e "{\n \"Quota\": \"10G\",\n \"RemoveStoppedContainers\": \"always\"\n}" > /etc/arvados/docker-cleaner/docker-cleaner.json
107 # Enable cgroup accounting
108 $SUDO sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"/g' /etc/default/grub
111 # Set a higher ulimit and the resolver (if set) for docker
112 if [ "x$RESOLVER" != "x" ]; then
113 SET_RESOLVER="--dns ${RESOLVER}"
116 $SUDO sed "s/ExecStart=\(.*\)/ExecStart=\1 --default-ulimit nofile=10000:10000 ${SET_RESOLVER}/g" \
117 /lib/systemd/system/docker.service \
118 > /etc/systemd/system/docker.service
120 $SUDO systemctl daemon-reload
122 # docker should not start on boot: we restart it inside /usr/local/bin/ensure-encrypted-partitions.sh,
123 # and the BootProbeCommand might be "docker ps -q"
124 $SUDO systemctl disable docker
126 # Make sure user_allow_other is set in fuse.conf
127 $SUDO sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
129 # Add crunch user with sudo powers
130 $SUDO adduser --disabled-password --gecos "Crunch user,,,," crunch
131 # Do not require a password to sudo
132 echo -e "# for the crunch user\ncrunch ALL=(ALL) NOPASSWD:ALL" | $SUDO tee /etc/sudoers.d/91-crunch
134 # Set up the ssh public key for the crunch user
135 $SUDO mkdir /home/crunch/.ssh
136 $SUDO mv /tmp/crunch-authorized_keys /home/crunch/.ssh/authorized_keys
137 $SUDO chown -R crunch:crunch /home/crunch/.ssh
138 $SUDO chmod 600 /home/crunch/.ssh/authorized_keys
139 $SUDO chmod 700 /home/crunch/.ssh/
141 # Make sure we resolve via the provided resolver IP if set. Prepending is good enough because
142 # unless 'rotate' is set, the nameservers are queried in order (cf. man resolv.conf)
143 if [ "x$RESOLVER" != "x" ]; then
144 $SUDO sed -i "s/#prepend domain-name-servers 127.0.0.1;/prepend domain-name-servers ${RESOLVER};/" /etc/dhcp/dhclient.conf
146 # Set up the cloud-init script that will ensure encrypted disks
147 $SUDO mv /tmp/usr-local-bin-ensure-encrypted-partitions.sh /usr/local/bin/ensure-encrypted-partitions.sh
148 $SUDO chmod 755 /usr/local/bin/ensure-encrypted-partitions.sh
149 $SUDO chown root:root /usr/local/bin/ensure-encrypted-partitions.sh
150 $SUDO mv /tmp/etc-cloud-cloud.cfg.d-07_compute_arvados_dispatch_cloud.cfg /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg
151 $SUDO chown root:root /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg
153 if [ "$NVIDIA_GPU_SUPPORT" == "1" ]; then
154 # $DIST should not have a dot if there is one in /etc/os-release (e.g. 18.04)
155 DIST=$(. /etc/os-release; echo $ID$VERSION_ID | tr -d '.')
156 # We need a kernel and matching headers
157 if [[ "$DIST" =~ ^debian ]]; then
158 $SUDO apt-get -y install linux-image-cloud-amd64 linux-headers-cloud-amd64
159 elif [ "$CLOUD" == "azure" ]; then
160 $SUDO apt-get -y install linux-image-azure linux-headers-azure
161 elif [ "$CLOUD" == "aws" ]; then
162 $SUDO apt-get -y install linux-image-aws linux-headers-aws
166 $SUDO apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/$DIST/x86_64/7fa2af80.pub
167 $SUDO apt-get -y install software-properties-common
168 $SUDO add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/$DIST/x86_64/ /"
169 $SUDO add-apt-repository contrib
171 $SUDO apt-get -y install cuda
173 # Install libnvidia-container, the tooling for Docker/Singularity
174 curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | \
176 if [ "$DIST" == "debian11" ]; then
177 # As of 2021-12-16 libnvidia-container and friends are only available for
178 # Debian 10, not yet Debian 11. Install experimental rc1 package as per this
180 # https://github.com/NVIDIA/nvidia-docker/issues/1549#issuecomment-989670662
181 curl -s -L https://nvidia.github.io/libnvidia-container/debian10/libnvidia-container.list | \
182 $SUDO tee /etc/apt/sources.list.d/libnvidia-container.list
183 $SUDO sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/libnvidia-container.list
185 # here, $DIST should have a dot if there is one in /etc/os-release (e.g. 18.04)...
186 DIST=$(. /etc/os-release; echo $ID$VERSION_ID)
187 curl -s -L https://nvidia.github.io/libnvidia-container/$DIST/libnvidia-container.list | \
188 $SUDO tee /etc/apt/sources.list.d/libnvidia-container.list
191 if [ "$DIST" == "debian10" ]; then
192 # Debian 10 comes with Docker 18.xx, we need 19.03 or later
193 curl -fsSL https://download.docker.com/linux/debian/gpg | $SUDO gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
194 echo deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian/ buster stable | \
195 $SUDO tee /etc/apt/sources.list.d/docker.list
197 $SUDO apt-get -yq --no-install-recommends install docker-ce=5:19.03.15~3-0~debian-buster
199 $SUDO sed "s/ExecStart=\(.*\)/ExecStart=\1 --default-ulimit nofile=10000:10000 ${SET_RESOLVER}/g" \
200 /lib/systemd/system/docker.service \
201 > /etc/systemd/system/docker.service
203 $SUDO systemctl daemon-reload
205 # docker should not start on boot: we restart it inside /usr/local/bin/ensure-encrypted-partitions.sh,
206 # and the BootProbeCommand might be "docker ps -q"
207 $SUDO systemctl disable docker
210 $SUDO apt-get -y install libnvidia-container1 libnvidia-container-tools nvidia-container-toolkit