-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry.sh
More file actions
executable file
·113 lines (105 loc) · 4.17 KB
/
sentry.sh
File metadata and controls
executable file
·113 lines (105 loc) · 4.17 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Inlcude tools
. tools.sh
# VARIABLES
SENTRY_USER=sentry
SENTRY_HOST=`get_eth0_ip`
SENTRY_DB_HOST=$SENTRY_HOST
SENTRY_DB=sentry_db
SENTRY_DB_USER=$SENTRY_USER
SENTRY_DB_USER_PASSWORD="`get_hash`"
SENTRY_CONFIG_FILE=/home/$SENTRY_USER/.sentry/sentry.conf.py
SENTRY_WORKERS_SCRIPT=/usr/local/bin/start_sentry_workers
SENTRY_WEB_SCRIPT=/usr/local/bin/start_sentry_webui
# Create Sentry User
sudo adduser $SENTRY_USER
sudo adduser $SENTRY_USER sudo
# Install Pre-requirements
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential python-setuptools python-dev libffi-dev libxml2-dev libxslt1-dev python-pip nginx supervisor -y
# Install Postgresql
sudo ./postgres.sh
# Install Redis
sudo ./redis.sh
# Install psycopg2
sudo pip install psycopg2
# Install Pillow Dependencies
sudo apt-get install python-imaging libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
# Install Sentry
sudo pip install sentry
# Create database and user
sudo -u postgres psql -U postgres -d postgres -c "CREATE DATABASE $SENTRY_DB;"
sudo -u postgres psql -U postgres -d postgres -c "CREATE USER $SENTRY_DB_USER WITH ENCRYPTED PASSWORD '$SENTRY_DB_USER_PASSWORD';"
sudo -u postgres psql -U postgres -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE $SENTRY_DB TO $SENTRY_DB_USER;"
#
# SENTRY SETUP
#
# Initialize config file
SENTRY_CONFIG_SETUP_SED="s|'ENGINE': 'django.db.backends.sqlite3'|'ENGINE': 'django.db.backends.postgresql_psycopg2'|g;s|'NAME': os.path.join(CONF_ROOT, 'sentry.db')|'NAME': '$SENTRY_DB'|g;s|'USER': 'postgres'|'USER': '$SENTRY_USER'|g;s|'PASSWORD': ''|'PASSWORD': '$SENTRY_DB_USER_PASSWORD'|g;s|'HOST': ''|'HOST': '$SENTRY_DB_HOST'|g;s|'PORT': ''|'PORT': '5432'|g;s|SENTRY_URL_PREFIX = 'http://sentry.example.com'|SENTRY_URL_PREFIX = 'http://$SENTRY_HOST'|g"
SENTRY_CONFIG_SETUP_CMD=`echo -e "sentry init
sed -i.bak \"$SENTRY_CONFIG_SETUP_SED\" $SENTRY_CONFIG_FILE
# Initialize databases
sentry upgrade"`
# Apply configuration file changes
su - $SENTRY_USER -c "$SENTRY_CONFIG_SETUP_CMD"
#
# SETUP WEB INTERFACE USIN nginx
#
sudo rm /etc/nginx/sites-enabled/default
echo -e "server {
# listen on port 80
listen 80;
# for requests to these domains
server_name $SENTRY_HOST;
# keep logs in these files
access_log /var/log/nginx/sentry.access.log;
error_log /var/log/nginx/sentry.error.log;
location / {
proxy_pass http://localhost:9000;
proxy_redirect off;
proxy_read_timeout 5m;
# make sure these HTTP headers are set properly
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}" | sudo tee -a /etc/nginx/sites-available/sentry
cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/sentry
# Restart Nginx Service
sudo service nginx restart
#
# SETUP SUPERVISORD SERVICES
#
# Create Workers Service
SENTRY_WORKERS_SCRIPT_SRC="#!/bin/bash\n/usr/local/bin/sentry --config=/home/$SENTRY_USER/.sentry/sentry.conf.py celery worker -B"
echo -e "$SENTRY_WORKERS_SCRIPT_SRC" | sudo tee -a $SENTRY_WORKERS_SCRIPT
sudo chmod +x $SENTRY_WORKERS_SCRIPT
SENTRY_WORKERS_SUPERVISOR_CONF="[program:sentry-workers]
command=\"$SENTRY_WORKERS_SCRIPT\"
directory=/home/$SENTRY_USER
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/supervisor/sentry_workers.err.log
stdout_logfile=/var/log/supervisor/sentry_workers.out.log
user=$SENTRY_USER"
echo -e "$SENTRY_WORKERS_SUPERVISOR_CONF" | sudo tee -a /etc/supervisor/conf.d/sentryworkers.conf
# Create Web Interfaces Service
SENTRY_WEB_SCRIPT_SRC="#!/bin/bash\n/usr/local/bin/sentry --config=/home/$SENTRY_USER/.sentry/sentry.conf.py start http"
echo -e "$SENTRY_WEB_SCRIPT_SRC" | sudo tee -a $SENTRY_WEB_SCRIPT
sudo chmod +x $SENTRY_WEB_SCRIPT
SENTRY_WEB_SUPERVISOR_CONF="[program:sentry-web]
command=\"$SENTRY_WEB_SCRIPT\"
directory=/home/$SENTRY_USER
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/supervisor/sentry_web.err.log
stdout_logfile=/var/log/supervisor/sentry_web.out.log
user=$SENTRY_USER"
echo -e "$SENTRY_WEB_SUPERVISOR_CONF" | sudo tee -a /etc/supervisor/conf.d/sentryweb.conf
# Start Services
sudo killall supervisord
sudo supervisord