| 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() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 # Install the Chrome sandbox | 59 # Install the Chrome sandbox |
| 60 cp /opt/app/clovis/binaries/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox | 60 cp /opt/app/clovis/binaries/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox |
| 61 chown root:root /usr/local/sbin/chrome-devel-sandbox | 61 chown root:root /usr/local/sbin/chrome-devel-sandbox |
| 62 chmod 4755 /usr/local/sbin/chrome-devel-sandbox | 62 chmod 4755 /usr/local/sbin/chrome-devel-sandbox |
| 63 | 63 |
| 64 # Make sure the pythonapp user owns the application code | 64 # Make sure the pythonapp user owns the application code |
| 65 chown -R pythonapp:pythonapp /opt/app | 65 chown -R pythonapp:pythonapp /opt/app |
| 66 | 66 |
| 67 # Create the configuration file for this deployment. | 67 # Create the configuration file for this deployment. |
| 68 DEPLOYMENT_CONFIG_PATH=/opt/app/clovis/deployment_config.json | 68 DEPLOYMENT_CONFIG_PATH=/opt/app/clovis/deployment_config.json |
| 69 TASKQUEUE_TAG=`get_instance_metadata taskqueue_tag` |
| 69 cat >$DEPLOYMENT_CONFIG_PATH << EOF | 70 cat >$DEPLOYMENT_CONFIG_PATH << EOF |
| 70 { | 71 { |
| 71 "project_name" : "$PROJECTID", | 72 "project_name" : "$PROJECTID", |
| 72 "cloud_storage_path" : "$CLOUD_STORAGE_PATH", | 73 "cloud_storage_path" : "$CLOUD_STORAGE_PATH", |
| 73 "chrome_path" : "/opt/app/clovis/binaries/chrome", | 74 "chrome_path" : "/opt/app/clovis/binaries/chrome", |
| 74 "src_path" : "/opt/app/clovis/src" | 75 "src_path" : "/opt/app/clovis/src", |
| 76 "taskqueue_tag" : "$TASKQUEUE_TAG" |
| 75 } | 77 } |
| 76 EOF | 78 EOF |
| 77 | 79 |
| 78 # Check if auto-start is enabled | 80 # Check if auto-start is enabled |
| 79 AUTO_START=`get_instance_metadata auto-start` | 81 AUTO_START=`get_instance_metadata auto-start` |
| 80 | 82 |
| 81 # Exit early if auto start is not enabled. | 83 # Exit early if auto start is not enabled. |
| 82 if [ "$AUTO_START" != "true" ]; then | 84 if [ "$AUTO_START" == "false" ]; then |
| 83 exit 1 | 85 exit 1 |
| 84 fi | 86 fi |
| 85 | 87 |
| 86 # Configure supervisor to start gunicorn inside of our virtualenv and run the | 88 # Configure supervisor to start the worker inside of our virtualenv. |
| 87 # applicaiton. | |
| 88 cat >/etc/supervisor/conf.d/python-app.conf << EOF | 89 cat >/etc/supervisor/conf.d/python-app.conf << EOF |
| 89 [program:pythonapp] | 90 [program:pythonapp] |
| 90 directory=/opt/app/clovis/src/tools/android/loading/gce | 91 directory=/opt/app/clovis/src/tools/android/loading/gce |
| 91 command=/opt/app/clovis/env/bin/gunicorn --workers=1 --bind 0.0.0.0:8080 \ | 92 command=python worker.py --config $DEPLOYMENT_CONFIG_PATH |
| 92 'main:StartApp('\"$DEPLOYMENT_CONFIG_PATH\"')' | |
| 93 autostart=true | 93 autostart=true |
| 94 autorestart=true | 94 autorestart=true |
| 95 user=pythonapp | 95 user=pythonapp |
| 96 # Environment variables ensure that the application runs inside of the | 96 # Environment variables ensure that the application runs inside of the |
| 97 # configured virtualenv. | 97 # configured virtualenv. |
| 98 environment=VIRTUAL_ENV="/opt/app/clovis/env", \ | 98 environment=VIRTUAL_ENV="/opt/app/clovis/env", \ |
| 99 PATH="/opt/app/clovis/env/bin:/usr/bin", \ | 99 PATH="/opt/app/clovis/env/bin:/usr/bin", \ |
| 100 HOME="/home/pythonapp",USER="pythonapp", \ | 100 HOME="/home/pythonapp",USER="pythonapp", \ |
| 101 CHROME_DEVEL_SANDBOX="/usr/local/sbin/chrome-devel-sandbox" | 101 CHROME_DEVEL_SANDBOX="/usr/local/sbin/chrome-devel-sandbox" |
| 102 stdout_logfile=syslog | 102 stdout_logfile=syslog |
| 103 stderr_logfile=syslog | 103 stderr_logfile=syslog |
| 104 EOF | 104 EOF |
| 105 | 105 |
| 106 supervisorctl reread | 106 supervisorctl reread |
| 107 supervisorctl update | 107 supervisorctl update |
| 108 | 108 |
| OLD | NEW |