blob: 475c6eb229d1d560394cd4e4232a85dac23e7fcb (
plain)
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
|
the first thing we need is python 3.4+ which I install by hand:
prereqs:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev libreadline6-dev
wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz
tar -xvzf Python-3.4.1.tgz
cd Python-3.4.1
./configure --prefix=/opt/python3
make
sudo make altinstall
Then we need postgres and the geospatial libs:
apt-get install postgresql postgresql-contrib binutils libproj-dev gdal-bin
postgis 2 i also do from source:
wget http://download.osgeo.org/postgis/source/postgis-2.1.3.tar.gz
tar -xvzf postgis-2.1.3.tar.gz
cd postgis-2.1.3
preqs:
apt-get install libpq-dev postgresql-server-dev-all libxml2 libgeos-dev libxml2-dev gdal-bin libgdal-dev
./configure
make
sudo make install
Then you just need to create a db user and database
sudo su - postgres
createuser -P -s -e luxagraf
The with regular user:
createdb luxagraf -U luxagraf -W -hlocalhost
psql -U luxagraf -W -hlocalhost -d luxagraf
and when you're in postgres:
CREATE EXTENSION postgis;
Then just load the data:
psql -U luxagraf -W -hlocalhost -d luxagraf -f fullbak.sql (or whatever your backupfile is)
The last thing is a virtualenv for our project using python3.4
#make sure you use the right pip (included with python 3.4+)
sudo /opt/python3/bin/pip3.4 install virtualenv
then cd to proj dir and do:
/opt/python3/bin/virtualenv --distribute --python=/opt/python3/bin/python3-4 venv
then activate and install what you need
---
Once that's set up we need to connect gunicorn to nginx via supervisor.
sudo apt-get install supervisor
That will install and start supervisor. Let's add an init script so that supervisord starts up should the server need to reboot. so create the file
/etc/init.d/supervisord
And grab the appropriate [init script from the supervisor project](https://github.com/Supervisor/initscripts). I use the Debian script from that link. Paste that script into `/etc/init.d/supervisord` and save. Then make it executable:
sudo chmod +x /etc/init.d/supervisord
Now, make sure supervisor isn't running:
supervisorctl shutdown
And add supervisor to
With Supervisor installed you can start and watch apps by creating configuration files in the `/etc/supervisor/conf.d` directory. You might do something like this, in, for example, `/etc/supervisor/conf.d/helloworld.conf`:
[program:helloworld]
command = /home/<username>/apps/mydjangoapp/venv/bin/gunicorn -c /home/<username>/apps/mydjangoapp/config/gunicorn_config.py config.wsgi
directory = /home/<username>/apps/mydjangoapp/
user = <non-privledged-user>
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/helloworld.log
stderr_logfile = /var/log/supervisor/helloworld_err.log
You'll need to fill in the correct paths based on your server setup, replacing <username> with your username and `mydjangoapp/etc...` with the actual path to the gunicorn app. This also assumes your gunicorn config file lives in `mydjangoapp/config/`. We'll get to that file in a minute.
First, let's tell supervisor about our new app:
sudo supervisorctl reread
You should see a message `helloworld available`. So Supervisor knows about our app, let's actually add it.
sudo supervisorctl update
Now you should see a message that says something like `helloworld: added process group`. Supervisor is now aware of our hello world app and will make sure it automatically starts up whenever our server reboots. You can check the status of our gunicorn app with:
sudo supervisorctl status
|