-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[program:celery-beat] | ||
directory=PROJECT_PATH | ||
command=PROJECT_PATH/python/bin/celery -A PROJECT_NAME beat -s ./celerybeat-schedule -l info | ||
autostart=true | ||
autorestart=true | ||
redirect_stderr=true | ||
stdout_logfile=PROJECT_PATH/log/celery-beat.log | ||
stdout_logfile_maxbytes=30MB | ||
stdout_logfile_backups=10 | ||
startsects=10 | ||
numprocs=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[program:celery] | ||
directory=PROJECT_PATH | ||
user=nobody | ||
command=PROJECT_PATH/python/bin/celery -A PROJECT_NAME worker -l info | ||
autostart=true | ||
autorestart=true | ||
redirect_stderr=true | ||
stdout_logfile=PROJECT_PATH/log/celery.log | ||
stdout_logfile_maxbytes=30MB | ||
stdout_logfile_backups=10 | ||
startsecs=10 | ||
stopwaitsecs=600 | ||
numprocs=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
python-software-properties | ||
software-properties-common | ||
build-essential | ||
postgresql-9.1 | ||
postgresql-server-dev-9.1 | ||
libxml2-dev | ||
libproj-dev | ||
libjson0-dev | ||
xsltproc | ||
docbook-xsl | ||
docbook-mathml | ||
gdal-bin | ||
binutils | ||
libxml2 | ||
libxml2-dev | ||
libxml2-dev | ||
checkinstall | ||
proj | ||
libpq-dev | ||
libgdal1-dev | ||
postgresql-contrib | ||
python-setuptools | ||
python-virtualenv | ||
python-dev | ||
git-core | ||
supervisor | ||
nginx-full | ||
nginx-common | ||
openssl | ||
zlib-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
from fabric.api import * | ||
from fabric.contrib.files import append | ||
from fabric.colors import green | ||
import random | ||
import json | ||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | ||
secret_key = ''.join(random.SystemRandom().choice(chars) for _ in range(50)) | ||
|
||
|
||
|
||
# Put host(s) configuration here or use -h switch on command line | ||
# env.hosts = '' | ||
# env.password = '' | ||
|
||
git_repo = 'https://github.com/ninuxorg/nodeshot.git' | ||
|
||
|
||
def initialize(): | ||
install_dirs = ('root_dir','deploy_dir','project_dir') | ||
for install_dir in install_dirs: | ||
if install_dir not in globals(): | ||
initialize_dirs() | ||
|
||
def initialize_server(): | ||
if 'server_name' not in globals(): | ||
global server_name | ||
server_name = prompt('Server name: ') | ||
|
||
def initialize_db(): | ||
db_params = ('db_user','db_pass') | ||
for db_param in db_params: | ||
if db_param not in globals(): | ||
global db_user | ||
global db_pass | ||
db_user = prompt('Set database user: ', default='nodeshot') | ||
db_pass = prompt('Set database user password: ', ) | ||
|
||
def initialize_dirs(): | ||
global root_dir | ||
global deploy_dir | ||
global project_dir | ||
global project_name | ||
root_dir = prompt('Set install directory ( including trailing slash ): ', default='/var/www/') | ||
project_name = prompt('Set project name: ', default='myproject') | ||
deploy_dir = '%snodeshot/' % root_dir | ||
project_dir = '%sprojects/%s' % (deploy_dir,project_name) | ||
|
||
def uninstall(): | ||
initialize() | ||
with cd(project_dir): | ||
run('cat dependencies.txt | xargs apt-get -y purge') | ||
|
||
def install(): | ||
initialize() | ||
initialize_server() | ||
initialize_db() | ||
install_git() | ||
clone() | ||
install_dependencies() | ||
create_virtual_env() | ||
install_requirements() | ||
create_project() | ||
create_db() | ||
create_settings() | ||
sync_data() # Fails if settings are not correctly set | ||
nginx_config() | ||
supervisor_config() | ||
redis_install() | ||
start_server() | ||
|
||
def update(): | ||
initialize() | ||
pull() | ||
install_requirements() | ||
sync_data() | ||
|
||
def clone(): | ||
initialize() | ||
print(green("Cloning repository...")) | ||
with hide('stdout', 'stderr'): | ||
run('mkdir -p %s' % root_dir) | ||
with cd (root_dir): | ||
run('git clone %s nodeshot' % git_repo ) | ||
with cd (deploy_dir): | ||
run ('git checkout deploy_test') # to be removed when merged into master | ||
|
||
def install_git(): | ||
print(green("Installing Git...")) | ||
with hide('stdout', 'stderr'): | ||
run('apt-get -y install git-core') | ||
|
||
def install_dependencies(): | ||
initialize() | ||
print(green("Installing required packages. This may take a while...")) | ||
with hide( 'stdout', 'stderr'): | ||
with cd('%sINSTALL' % deploy_dir): | ||
run('cat dependencies.txt | xargs apt-get -y install') | ||
with cd('/tmp'): | ||
run('cp %sINSTALL/install* . && ./install_GEOS.sh && ./install_Postgis.sh' % deploy_dir ) | ||
|
||
def pull(): | ||
initialize() | ||
with cd (deploy_dir): | ||
run('pwd') | ||
run('git pull') | ||
|
||
def create_virtual_env(): | ||
initialize() | ||
print(green("Creating virtual env...")) | ||
with hide( 'stdout', 'stderr'): | ||
run ('mkdir -p %s' % project_dir) | ||
with cd (project_dir): | ||
run('virtualenv python') | ||
|
||
def install_requirements(): | ||
initialize() | ||
print(green("Installing requirements. This may take a while...")) | ||
with hide( 'stdout', 'stderr'): | ||
virtual_env = 'source python/bin/activate' | ||
pip_command = 'python/bin/pip install -r %srequirements.txt' % deploy_dir | ||
distribute_command = 'python/bin/pip install -U distribute' | ||
with cd (project_dir): | ||
run( virtual_env + ' && ' + pip_command + ' && ' + distribute_command) | ||
|
||
def create_project(): | ||
initialize() | ||
print(green("Creating project...")) | ||
virtual_env = 'source python/bin/activate' | ||
template_name = "%sINSTALL/project_template" % deploy_dir | ||
create_project_command = "django-admin.py startproject %s --template=%s ." % (project_name,template_name) | ||
with hide( 'stdout', 'stderr'): | ||
with cd (project_dir): | ||
run( virtual_env + ' && ' + create_project_command ) | ||
|
||
def create_db(): | ||
initialize_db() | ||
print(green("Configuring DB...")) | ||
with hide( 'stdout', 'stderr'): | ||
run ('su - postgres -c "createdb nodeshot"') | ||
run ('su - postgres -c "psql nodeshot -c \'CREATE EXTENSION hstore;\'"') | ||
run ('su - postgres -c "psql nodeshot -c \'CREATE EXTENSION postgis;\'"') | ||
run ('su - postgres -c "psql nodeshot -c \'CREATE EXTENSION postgis_topology;\'"') | ||
run ('su - postgres -c "createuser %s -R -S -D "' % db_user) | ||
run ('sudo -u postgres psql -U postgres -d postgres -c \"alter user %s with password \'%s\';\"' % (db_user,db_pass)) | ||
run ('su - postgres -c "psql -c \'GRANT ALL PRIVILEGES ON DATABASE "nodeshot" to %s \'"' % db_user) | ||
|
||
def create_settings(): | ||
initialize() | ||
initialize_db() | ||
initialize_server() | ||
print(green("Creating Nodeshot config...")) | ||
settings= {} | ||
settings['app_path'] = "APP_PATH = '%s' " % deploy_dir | ||
settings['domain'] = "DOMAIN = '%s' " % server_name | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.contrib.gis.db.backends.postgis', | ||
'NAME': 'nodeshot', | ||
'USER': db_user, | ||
'PASSWORD': db_pass, | ||
'HOST': '127.0.0.1', | ||
'PORT': '', | ||
} | ||
} | ||
|
||
db_settings = json.dumps(DATABASES) | ||
with cd ('%s/%s' % (project_dir,project_name)): | ||
run('rm -f local_settings.py') | ||
for setting,value in settings.iteritems(): | ||
append('local_settings.py', value) | ||
append('local_settings.py', 'DATABASES = %s' % db_settings) | ||
|
||
def sync_data(): | ||
initialize() | ||
print(green("Initializing Nodeshot...")) | ||
virtual_env = 'source python/bin/activate' | ||
sync_command = 'python manage.py syncdb && python manage.py migrate && python manage.py collectstatic --noinput' | ||
with cd (project_dir): | ||
run('mkdir log' ) | ||
run('touch log/%s.error.log' % project_name ) | ||
run('chmod 666 log/%s.error.log' % project_name) | ||
run( virtual_env + ' && ' + sync_command) | ||
|
||
def nginx_config(): | ||
initialize() | ||
initialize_server() | ||
print(green("Configuring Nginx...")) | ||
nginx_dir = '/etc/nginx/ssl' | ||
run ('mkdir -p %s' % nginx_dir) | ||
with cd (nginx_dir): | ||
print(green("Insert Certificate details...")) | ||
run ('openssl req -new -x509 -nodes -out server.crt -keyout server.key') | ||
run('cp /etc/nginx/uwsgi_params /etc/nginx/sites-available/') | ||
#run ('mkdir -p /var/www/nodeshot/public_html') | ||
|
||
run ('cp %sINSTALL/nodeshot.yourdomain.com /etc/nginx/sites-available/nodeshot.yourdomain.com' % deploy_dir) | ||
|
||
with cd('/etc/nginx/sites-available'): | ||
run ('sed \'s/nodeshot.yourdomain.com/%s/g\' nodeshot.yourdomain.com > %s' % (server_name,server_name)) | ||
run ('sed -i \'s#PROJECT_PATH#%s#g\' %s ' % (project_dir,server_name)) | ||
run ('sed -i \'s#PROJECT_NAME#%s#g\' %s ' % (project_name,server_name)) | ||
run ('ln -s /etc/nginx/sites-available/%s /etc/nginx/sites-enabled/%s' % (server_name,server_name)) | ||
|
||
def supervisor_config(): | ||
initialize() | ||
print(green("Configuring Supervisor...")) | ||
with hide( 'stdout', 'stderr'): | ||
run ('pip install uwsgi') | ||
with cd (project_dir): | ||
run ('cp %sINSTALL/uwsgi.ini .' % deploy_dir) | ||
run ('sed -i \'s#PROJECT_PATH#%s#g\' uwsgi.ini ' % project_dir) | ||
run ('sed -i \'s#PROJECT_NAME#%s#g\' uwsgi.ini ' % project_name) | ||
run ('cp %sINSTALL/uwsgi.conf /etc/supervisor/conf.d/uwsgi.conf' % deploy_dir) | ||
run ('cp %sINSTALL/celery.conf /etc/supervisor/conf.d/celery.conf' % deploy_dir) | ||
run ('cp %sINSTALL/celery-beat.conf /etc/supervisor/conf.d/celery-beat.conf' % deploy_dir) | ||
with cd ('/etc/supervisor/conf.d/'): | ||
run ('sed -i \'s#PROJECT_PATH#%s#g\' uwsgi.conf ' % project_dir) | ||
run ('sed -i \'s#PROJECT_PATH#%s#g\' celery.conf ' % project_dir) | ||
run ('sed -i \'s#PROJECT_NAME#%s#g\' celery.conf ' % project_name) | ||
run ('sed -i \'s#PROJECT_PATH#%s#g\' celery-beat.conf ' % project_dir) | ||
run ('sed -i \'s#PROJECT_NAME#%s#g\' celery-beat.conf ' % project_name) | ||
run('supervisorctl update') | ||
|
||
def redis_install(): | ||
initialize() | ||
print(green("Installing redis...")) | ||
with hide( 'stdout', 'stderr'): | ||
virtual_env = 'source python/bin/activate' | ||
pip_command = 'python/bin/pip install -U celery[redis]' | ||
run('add-apt-repository -y ppa:chris-lea/redis-server') | ||
run('apt-get -y update') | ||
run('apt-get -y install redis-server') | ||
with cd (project_dir): | ||
run( virtual_env + ' && ' + pip_command) | ||
|
||
def start_server(): | ||
initialize() | ||
print(green("Starting Nodeshot server...")) | ||
with cd (project_dir): | ||
run('service nginx restart && supervisorctl restart all') | ||
print(green("Nodeshot server started")) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
wget http://download.osgeo.org/geos/geos-3.3.8.tar.bz2 && | ||
tar xvfj geos-3.3.8.tar.bz2 && | ||
cd geos-3.3.8 && | ||
./configure && | ||
make && | ||
make install && | ||
cd .. && | ||
rm -rf geos-3.3.8.tar.bz2 geos-3.3.8.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
wget http://download.osgeo.org/postgis/source/postgis-2.0.3.tar.gz && | ||
tar xfvz postgis-2.0.3.tar.gz && | ||
cd postgis-2.0.3 && | ||
./configure && | ||
make && | ||
make install && | ||
ldconfig && | ||
make comments-install && | ||
cd .. && | ||
rm -rf postgis-2.0.3.tar.gz postgis-2.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
server { | ||
listen 443; ## listen for ipv4; this line is default and implied | ||
#listen [::]:443 default ipv6only=on; ## listen for ipv6 | ||
|
||
root /var/www/nodeshot/public_html; | ||
index index.html index.htm; | ||
|
||
# error log | ||
error_log PROJECT_PATH/log/nginx.error.log error; | ||
|
||
# Make site accessible from hostanme | ||
# change this according to your domain/hostanme | ||
server_name nodeshot.yourdomain.com; | ||
|
||
# set client body size # | ||
client_max_body_size 5M; | ||
|
||
ssl on; | ||
ssl_certificate ssl/server.crt; | ||
ssl_certificate_key ssl/server.key; | ||
|
||
ssl_session_timeout 5m; | ||
|
||
ssl_protocols SSLv3 TLSv1; | ||
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP; | ||
ssl_prefer_server_ciphers on; | ||
|
||
location / { | ||
uwsgi_pass 127.0.0.1:3031; | ||
include uwsgi_params; | ||
uwsgi_param HTTP_X_FORWARDED_PROTO https; | ||
} | ||
|
||
location /static/ { | ||
alias PROJECT_PATH/PROJECT_NAME/static/; | ||
} | ||
|
||
location /media/ { | ||
alias PROJECT_PATH/PROJECT_NAME/media/; | ||
} | ||
|
||
#error_page 404 /404.html; | ||
|
||
# redirect server error pages to the static page /50x.html | ||
# | ||
#error_page 500 502 503 504 /50x.html; | ||
#location = /50x.html { | ||
# root /usr/share/nginx/www; | ||
#} | ||
|
||
# deny access to .htaccess files, if Apache's document root | ||
# concurs with nginx's one | ||
# | ||
#location ~ /\.ht { | ||
# deny all; | ||
#} | ||
} | ||
|
||
server { | ||
listen 80; ## listen for ipv4; this line is default and implied | ||
listen [::]:80 default ipv6only=on; ## listen for ipv6 | ||
|
||
# Make site accessible from hostanme on port 80 | ||
# change this according to your domain/hostanme | ||
server_name nodeshot.yourdomain.com; | ||
|
||
# redirect all requests to https | ||
return 301 https://$host$request_uri; | ||
} |
Oops, something went wrong.