-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup-script.sh
60 lines (49 loc) · 2.03 KB
/
startup-script.sh
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
# [START startup]
set -v
# Talk to the metadata server to get the project id
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
# Install logging monitor. The monitor will automatically pickup logs sent to
# syslog.
# [START logging]
curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash
service google-fluentd restart &
# [END logging]
# Install dependencies from apt
apt-get update
apt-get install -yq \
git build-essential supervisor python python-dev python-pip libffi-dev \
libssl-dev python-pandas
# Create a pythonapp user. The application will run as this user.
useradd -m -d /home/pythonapp pythonapp
# pip from apt is out of date, so make it update itself and install virtualenv.
pip install --upgrade pip virtualenv
# Get the source code from the Google Cloud Repository
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/$PROJECTID /opt/app
# Install app dependencies
virtualenv /opt/app/spyre_example/env
/opt/app/spyre_example/env/bin/pip install -r /opt/app/spyre_example/requirements.txt
# Make sure the pythonapp user owns the application code
chown -R pythonapp:pythonapp /opt/app
# Configure supervisor to start gunicorn inside of our virtualenv and run the
# application.
cat >/etc/supervisor/conf.d/python-app.conf << EOF
[program:spyreexample]
directory=/opt/app/spyre_example
command=/opt/app/spyre_example/env/bin/python2.7 /opt/app/spyre_example/app.py
autostart=true
autorestart=true
user=pythonapp
# Environment variables ensure that the application runs inside of the
# configured virtualenv.
environment=VIRTUAL_ENV="/opt/app/spyre_example/env/",PATH="/opt/app/spyre_example/env/bin",\
HOME="/home/pythonapp",USER="pythonapp"
stdout_logfile=syslog
stderr_logfile=syslog
EOF
supervisorctl reread
supervisorctl update
# Application should now be running under supervisor
# [END startup]