1 #!/bin/bash -euxo pipefail
3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: Apache-2.0
11 wait_for_apt_locks() {
12 while $SUDO fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do
13 echo "APT: Waiting for apt/dpkg locks to be released..."
20 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -qq --yes "$@"
23 download_and_install() {
25 local dest="$1"; shift
26 curl -fsSL "$url" | $SUDO install "$@" /dev/stdin "$dest"
31 echo "Working directory is '${WORKDIR}'"
33 ### 1. Configure apt preferences
35 if [[ "${PIN_PACKAGES:-true}" != false ]]; then
36 $SUDO install -d /etc/apt/preferences.d
37 $SUDO install -m 0644 \
38 "$WORKDIR/etc-apt-preferences.d-arvados.pref" \
39 /etc/apt/preferences.d/arvados.pref
42 ### 2. Install all base packages we need
45 # Add the debian keys (but don't abort if we can't find them, e.g. on Ubuntu where we don't need them)
46 safe_apt install debian-keyring debian-archive-keyring 2>/dev/null || true
48 # Install gnupg and dirmgr or gpg key checks will fail
59 libcurl4-openssl-dev \
72 software-properties-common
74 safe_apt remove --purge unattended-upgrades
76 ### 3. Set up third-party apt repositories and install packages we need from them
78 $SUDO add-apt-repository contrib
79 $SUDO install -d /etc/apt/keyrings
81 # Add the Arvados apt source
82 download_and_install https://apt.arvados.org/pubkey.gpg /etc/apt/keyrings/arvados.asc
83 $SUDO install -m 644 /dev/stdin /etc/apt/sources.list.d/arvados.sources <<EOF
85 URIs: https://apt.arvados.org/$VERSION_CODENAME
86 Suites: $VERSION_CODENAME${REPOSUFFIX:-}
88 Signed-by: /etc/apt/keyrings/arvados.asc
91 # Add the Docker apt source
92 DOCKER_URL="https://download.docker.com/linux/$DISTRO_ID"
93 curl -fsSL "$DOCKER_URL/gpg" | $SUDO gpg --dearmor -o /etc/apt/keyrings/docker.gpg
94 $SUDO install -m 644 /dev/stdin /etc/apt/sources.list.d/docker.sources <<EOF
97 Suites: $VERSION_CODENAME
99 Signed-by: /etc/apt/keyrings/docker.gpg
102 # Add the NVIDIA CUDA apt source
103 # Note that the "keyring" package also installs the apt source
104 NVIDIA_URL="https://developer.download.nvidia.com/compute/cuda/repos/$(echo "$DISTRO_ID$VERSION_ID" | tr -d .)/x86_64"
105 CUDA_KEYRING_DEB=cuda-keyring_1.1-1_all.deb
106 curl -fsSL -o "$WORKDIR/$CUDA_KEYRING_DEB" "$NVIDIA_URL/$CUDA_KEYRING_DEB"
107 wait_for_apt_locks && $SUDO dpkg -i "$WORKDIR/$CUDA_KEYRING_DEB"
109 # Add the NVIDIA container toolkit apt source
110 download_and_install \
111 https://nvidia.github.io/libnvidia-container/gpgkey \
112 /etc/apt/keyrings/nvidia-container-toolkit.asc
113 download_and_install \
114 https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
115 /etc/apt/sources.list.d/nvidia-container-toolkit.list
116 $SUDO sed -i 's@^deb http@deb [signed-by=/etc/apt/keyrings/nvidia-container-toolkit.asc] http@' \
117 /etc/apt/sources.list.d/nvidia-container-toolkit.list
120 safe_apt install python3-arvados-fuse arvados-docker-cleaner
121 safe_apt install --no-install-recommends docker-ce
123 ### 4. Compute node system configuration
125 mkdir -p /var/lib/cloud/scripts/per-boot
128 $SUDO /bin/sed -ri 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
129 $SUDO /usr/sbin/locale-gen
131 # Set a higher ulimit and the resolver (if set) for docker
132 $SUDO install -d /etc/docker
133 $SUDO install -m 644 /dev/stdin /etc/docker/daemon.json <<EOFDOCKER
142 ${RESOLVER:+ , \"dns\": \"$RESOLVER\"}
146 # docker should not start on boot: we restart it inside /usr/local/bin/ensure-encrypted-partitions.sh,
147 # and the BootProbeCommand might be "docker ps -q"
148 $SUDO systemctl disable docker
150 # Configure arvados-docker-cleaner
151 $SUDO mkdir -p /etc/arvados/docker-cleaner
152 $SUDO echo -e "{\n \"Quota\": \"10G\",\n \"RemoveStoppedContainers\": \"always\"\n}" > /etc/arvados/docker-cleaner/docker-cleaner.json
154 # Enable cgroup accounting (forcing cgroups v1)
155 $SUDO echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=0"' >> /etc/default/grub
158 # Make sure user_allow_other is set in fuse.conf
159 $SUDO sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
161 # Add crunch user with sudo powers
162 $SUDO adduser --disabled-password --gecos "Crunch user,,,," crunch
163 # Do not require a password to sudo
164 echo -e "# for the crunch user\ncrunch ALL=(ALL) NOPASSWD:ALL" | $SUDO tee /etc/sudoers.d/91-crunch
166 # Set up the ssh public key for the crunch user
167 $SUDO mkdir /home/crunch/.ssh
168 $SUDO mv ${WORKDIR}/crunch-authorized_keys /home/crunch/.ssh/authorized_keys
169 $SUDO chown -R crunch:crunch /home/crunch/.ssh
170 $SUDO chmod 600 /home/crunch/.ssh/authorized_keys
171 $SUDO chmod 700 /home/crunch/.ssh/
173 # Make sure we resolve via the provided resolver IP if set. Prepending is good enough because
174 # unless 'rotate' is set, the nameservers are queried in order (cf. man resolv.conf)
175 if [ "x$RESOLVER" != "x" ]; then
176 $SUDO sed -i "s/#prepend domain-name-servers 127.0.0.1;/prepend domain-name-servers ${RESOLVER};/" /etc/dhcp/dhclient.conf
179 # AWS_EBS_AUTOSCALE is not always set, work around unset variable check
180 EBS_AUTOSCALE=${AWS_EBS_AUTOSCALE:-}
182 if [ "$EBS_AUTOSCALE" != "1" ]; then
183 # Set up the cloud-init script that will ensure encrypted disks
184 $SUDO mv ${WORKDIR}/usr-local-bin-ensure-encrypted-partitions.sh /usr/local/bin/ensure-encrypted-partitions.sh
186 download_and_install "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" "${WORKDIR}/awscliv2.zip"
187 unzip -q ${WORKDIR}/awscliv2.zip -d ${WORKDIR} && $SUDO ${WORKDIR}/aws/install
188 # Pinned to v2.4.5 because we apply a patch below
189 #export EBS_AUTOSCALE_VERSION=$(curl --silent "https://api.github.com/repos/awslabs/amazon-ebs-autoscale/releases/latest" | jq -r .tag_name)
190 export EBS_AUTOSCALE_VERSION="ee323f0751c2b6f733692e805b51b9bf3c251bac"
191 cd /opt && $SUDO git clone https://github.com/arvados/amazon-ebs-autoscale.git
192 cd /opt/amazon-ebs-autoscale && $SUDO git checkout $EBS_AUTOSCALE_VERSION
194 # Set up the cloud-init script that makes use of the AWS EBS autoscaler
195 $SUDO mv ${WORKDIR}/usr-local-bin-ensure-encrypted-partitions-aws-ebs-autoscale.sh /usr/local/bin/ensure-encrypted-partitions.sh
198 $SUDO chmod 755 /usr/local/bin/ensure-encrypted-partitions.sh
199 $SUDO chown root:root /usr/local/bin/ensure-encrypted-partitions.sh
200 $SUDO mv ${WORKDIR}/etc-cloud-cloud.cfg.d-07_compute_arvados_dispatch_cloud.cfg /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg
201 $SUDO chown root:root /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg
203 if [ "$NVIDIA_GPU_SUPPORT" == "1" ]; then
204 # We need a kernel and matching headers
205 if [[ "$DISTRO_ID" == debian ]]; then
206 safe_apt install linux-image-cloud-amd64 linux-headers-cloud-amd64
207 elif [ "$CLOUD" == "azure" ]; then
208 safe_apt install linux-image-azure linux-headers-azure
209 elif [ "$CLOUD" == "aws" ]; then
210 safe_apt install linux-image-aws linux-headers-aws
212 safe_apt install cuda libnvidia-container1 libnvidia-container-tools nvidia-container-toolkit
214 # Various components fail to start, and cause systemd to boot in degraded
215 # state, if the system does not actually have an NVIDIA GPU. Configure the
216 # image to adapt at boot time.
218 # Don't load modules unconditionally.
219 # Instead load them if hardware is detected.
220 if [[ -f /etc/modules-load.d/nvidia.conf ]]; then
221 $SUDO mv /etc/modules-load.d/nvidia.conf /etc/modules-load.d/nvidia.avail
223 $SUDO install "$WORKDIR/usr-local-bin-detect-gpu.sh" /usr/local/bin/detect-gpu.sh
224 $SUDO install -d /etc/systemd/system/systemd-modules-load.service.d
225 $SUDO install -m 0644 \
226 "$WORKDIR/etc-systemd-system-systemd-modules-load.service.d-detect-gpu.conf" \
227 /etc/systemd/system/systemd-modules-load.service.d/detect-gpu.conf
229 # Don't start the persistence daemon.
230 # Instead rely on crunch-run's CUDA initialization.
231 $SUDO systemctl disable nvidia-persistenced.service
234 # Get Go and build singularity
235 mkdir -p /var/lib/arvados
236 rm -rf /var/lib/arvados/go/
237 curl -fsSL https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz |
238 tar -C /var/lib/arvados -xz
239 ln -sf /var/lib/arvados/go/bin/* /usr/local/bin/
241 singularityversion=3.10.4
243 git clone --recurse-submodules https://github.com/sylabs/singularity
245 git checkout v${singularityversion}
246 echo $singularityversion > VERSION
247 ./mconfig --prefix=/var/lib/arvados
249 make -C ./builddir install
250 ln -sf /var/lib/arvados/bin/* /usr/local/bin/
252 # set `mksquashfs mem` in the singularity config file if it is configured
253 if [ "$MKSQUASHFS_MEM" != "" ]; then
254 echo "mksquashfs mem = ${MKSQUASHFS_MEM}" >> /var/lib/arvados/etc/singularity/singularity.conf
257 # Print singularity version installed
258 singularity --version