1#!/bin/bash
2# Copyright 2017 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Source this rc script to prepare the environment for linux builds
17
18# Need to increase open files limit for c tests
19ulimit -n 32768
20
21# 1. Move docker's storage location to scratch disk so we don't run out of space.
22# 2. Use container registry mirror for pulling docker images (should make downloads faster)
23#    See https://cloud.google.com/container-registry/docs/using-dockerhub-mirroring
24GRPC_DOCKER_OPTS="--data-root=/tmpfs/docker --registry-mirror=https://mirror.gcr.io"
25
26# Update global docker configuration to have GRPC_DOCKER_OPTS
27P1NAME=$(ps -p 1 -o comm=)
28if [[ $P1NAME == *"systemd"* ]];  then
29  # https://stackoverflow.com/questions/27763340
30  sudo sed -i -E "s|ExecStart=(.*)//|EnvironmentFile=/etc/default/docker\nExecStart=\nExecStart=\1// \$DOCKER_OPTS|" /lib/systemd/system/docker.service
31  sudo systemctl daemon-reload
32  echo "DOCKER_OPTS=\"${GRPC_DOCKER_OPTS}\"" | sudo tee --append /etc/default/docker
33  sudo systemctl restart docker.service
34else
35  echo "DOCKER_OPTS=\"\${DOCKER_OPTS} ${GRPC_DOCKER_OPTS}\"" | sudo tee --append /etc/default/docker
36  sudo service docker restart
37fi
38
39git submodule update --init
40
41python3 -m pip install six
42
43# Allows the test driver to spin up a GDB subprocess and have it attach to
44# another subprocess of the test driver.
45sudo bash -c 'echo "0" > /proc/sys/kernel/yama/ptrace_scope'
46
47# check whether /tmpfs is mounted correctly
48(mount | grep -q 'on /tmpfs ') || (mount; echo 'BAD KOKORO WORKER WARNING: it seems that /tmpfs volume with scratch disk is not mounted in the kokoro worker. This can result in unexpected "out of disk space" errors.')
49
50# Uncomment the following line to debug "out of disk space" errors by print available disk space every 30seconds in the background
51# bash -c "while true; do echo 'periodic background disk usage check:'; df -h / /tmpfs; sleep 30; done;" &
52