File size: 2,630 Bytes
f9f1a35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash -e

# Copyright 2017 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# At least one GPU is considered available iff COLAB_GPU=1.
export COLAB_GPU="$([[ -c /dev/nvidiactl ]] && echo 1)"

/usr/local/colab/bin/oom_monitor.sh &

# Start the Colab proxy to the Jupyter kernel manager.
# TODO(b/267667580): Evaluate use of tcmalloc here and possibly other places.
( while true; do
  GCE_METADATA_HOST="${VM_GCE_METADATA_HOST}" \
  LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4' \
  /usr/colab/bin/kernel_manager_proxy \
    --listen_port="${KMP_LISTEN_PORT}" \
    --target_port="${KMP_TARGET_PORT}" \
    ${KMP_EXTRA_ARGS} || true
  sleep 1
done & )

# Start fresh to isolate user-initiated actions from VM build & startup events.
for f in /var/log/apt/history.log /var/log/pip.log; do
  mv "$f" "${f}.bak-run.sh" 2>/dev/null || true  # Ignore missing files.
done

# Warm disk buffers for modules we need for kernel startup. (cf: b/116536906)
if [[ "${COLAB_WARMUP_DEFAULTS}" == "1" ]]; then
  python3 -c "import google.colab._kernel"
  python3 -c "import matplotlib"
  # importing tensorflow on a TPU VM causes the process to acquire the TPU for
  # the duration of the import. This makes the TPU effectively unacquirable for
  # the duration of the warmup, which can break things like probers.
  if [[ "${COLAB_TPU_1VM}" == "1" ]]; then
    python3 -c "import tensorflow"
  else
    python3 -c "import tensorflow" &
  fi
fi

# Start the server to handle /files and /api/contents requests.
/usr/local/bin/colab-fileshim.py ${COLAB_FILESHIM_EXTRA_ARGS} &

# Link NVidia tools from a read-only volume mount.
for f in $(ls /opt/bin/.nvidia 2>/dev/null); do
  ln -st /opt/bin "/opt/bin/.nvidia/${f}"
  ln -st /usr/bin "/opt/bin/.nvidia/${f}"
done

cd /

# Start the node server.
if [[ "${COLAB_HUMAN_READABLE_NODE_LOGS}" == "1" ]]; then
  PIPE=/tmp/.node.out
  if ! [[ -p "${PIPE}" ]]; then
    mkfifo "${PIPE}"
  fi
  /datalab/web/node_modules/bunyan/bin/bunyan \
    -l "${COLAB_NODE_LOG_LEVEL:-info}" < "${PIPE}" &
  exec >& "${PIPE}"
fi
exec /tools/node/bin/node /datalab/web/app.js