OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Script executed at instance startup. It installs the required dependencies, | 5 # Script executed at instance startup. It installs the required dependencies, |
6 # downloads the source code, and starts a web server. | 6 # downloads the source code, and starts a web server. |
7 | 7 |
8 set -v | 8 set -v |
9 | 9 |
10 get_instance_metadata() { | 10 get_instance_metadata() { |
11 curl -fs http://metadata/computeMetadata/v1/instance/attributes/$1 \ | 11 curl -fs http://metadata/computeMetadata/v1/instance/attributes/$1 \ |
12 -H "Metadata-Flavor: Google" | 12 -H "Metadata-Flavor: Google" |
13 } | 13 } |
14 | 14 |
15 # Talk to the metadata server to get the project id | 15 # Talk to the metadata server to get the project id and the instance id |
16 PROJECTID=$(curl -s \ | 16 PROJECTID=$(curl -s \ |
17 "http://metadata.google.internal/computeMetadata/v1/project/project-id" \ | 17 "http://metadata.google.internal/computeMetadata/v1/project/project-id" \ |
18 -H "Metadata-Flavor: Google") | 18 -H "Metadata-Flavor: Google") |
19 | 19 |
| 20 INSTANCE_ID=$(curl -s \ |
| 21 "http://metadata.google.internal/computeMetadata/v1/instance/hostname" \ |
| 22 -H "Metadata-Flavor: Google") |
| 23 |
20 # Install dependencies from apt | 24 # Install dependencies from apt |
21 apt-get update | 25 apt-get update |
22 # Basic dependencies | 26 # Basic dependencies |
23 apt-get install -yq git supervisor python-pip python-dev unzip | 27 apt-get install -yq git supervisor python-pip python-dev unzip |
24 # Web server dependencies | 28 # Web server dependencies |
25 apt-get install -yq libffi-dev libssl-dev | 29 apt-get install -yq libffi-dev libssl-dev |
26 # Chrome dependencies | 30 # Chrome dependencies |
27 apt-get install -yq libpangocairo-1.0-0 libXcomposite1 libXcursor1 libXdamage1 \ | 31 apt-get install -yq libpangocairo-1.0-0 libXcomposite1 libXcursor1 libXdamage1 \ |
28 libXi6 libXtst6 libnss3 libcups2 libgconf2-4 libXss1 libXrandr2 \ | 32 libXi6 libXtst6 libnss3 libcups2 libgconf2-4 libXss1 libXrandr2 \ |
29 libatk1.0-0 libasound2 libgtk2.0-0 | 33 libatk1.0-0 libasound2 libgtk2.0-0 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 70 |
67 # Create the configuration file for this deployment. | 71 # Create the configuration file for this deployment. |
68 DEPLOYMENT_CONFIG_PATH=/opt/app/clovis/deployment_config.json | 72 DEPLOYMENT_CONFIG_PATH=/opt/app/clovis/deployment_config.json |
69 TASKQUEUE_TAG=`get_instance_metadata taskqueue_tag` | 73 TASKQUEUE_TAG=`get_instance_metadata taskqueue_tag` |
70 cat >$DEPLOYMENT_CONFIG_PATH << EOF | 74 cat >$DEPLOYMENT_CONFIG_PATH << EOF |
71 { | 75 { |
72 "project_name" : "$PROJECTID", | 76 "project_name" : "$PROJECTID", |
73 "cloud_storage_path" : "$CLOUD_STORAGE_PATH", | 77 "cloud_storage_path" : "$CLOUD_STORAGE_PATH", |
74 "chrome_path" : "/opt/app/clovis/binaries/chrome", | 78 "chrome_path" : "/opt/app/clovis/binaries/chrome", |
75 "src_path" : "/opt/app/clovis/src", | 79 "src_path" : "/opt/app/clovis/src", |
76 "taskqueue_tag" : "$TASKQUEUE_TAG" | 80 "taskqueue_tag" : "$TASKQUEUE_TAG", |
| 81 "trace_database_filename" : "trace_database_${INSTANCE_ID}.json" |
77 } | 82 } |
78 EOF | 83 EOF |
79 | 84 |
80 # Check if auto-start is enabled | 85 # Check if auto-start is enabled |
81 AUTO_START=`get_instance_metadata auto-start` | 86 AUTO_START=`get_instance_metadata auto-start` |
82 | 87 |
83 # Exit early if auto start is not enabled. | 88 # Exit early if auto start is not enabled. |
84 if [ "$AUTO_START" == "false" ]; then | 89 if [ "$AUTO_START" == "false" ]; then |
85 exit 1 | 90 exit 1 |
86 fi | 91 fi |
(...skipping 12 matching lines...) Expand all Loading... |
99 PATH="/opt/app/clovis/env/bin:/usr/bin", \ | 104 PATH="/opt/app/clovis/env/bin:/usr/bin", \ |
100 HOME="/home/pythonapp",USER="pythonapp", \ | 105 HOME="/home/pythonapp",USER="pythonapp", \ |
101 CHROME_DEVEL_SANDBOX="/usr/local/sbin/chrome-devel-sandbox" | 106 CHROME_DEVEL_SANDBOX="/usr/local/sbin/chrome-devel-sandbox" |
102 stdout_logfile=syslog | 107 stdout_logfile=syslog |
103 stderr_logfile=syslog | 108 stderr_logfile=syslog |
104 EOF | 109 EOF |
105 | 110 |
106 supervisorctl reread | 111 supervisorctl reread |
107 supervisorctl update | 112 supervisorctl update |
108 | 113 |
OLD | NEW |