uwsgi configuration + fabfile
authorgrzegorz.prokopczyk@gmail.com <grzegorz.prokopczyk@gmail.com>
Mon, 2 Mar 2015 14:41:20 +0000 (15:41 +0100)
committergrzegorz.prokopczyk@gmail.com <grzegorz.prokopczyk@gmail.com>
Mon, 2 Mar 2015 14:41:20 +0000 (15:41 +0100)
fabfile.py [new file with mode: 0644]
requirements_dev.txt
uwsgi.ini [new file with mode: 0644]

diff --git a/fabfile.py b/fabfile.py
new file mode 100644 (file)
index 0000000..1605a4a
--- /dev/null
@@ -0,0 +1,63 @@
+from fabric.api import *
+
+env.user = 'portal'
+env.hosts = ['agave5.man.poznan.pl']
+
+
+#################################################
+# server management (remote)
+#################################################
+
+PID_FILE = '/var/run/uwsgi.pid'
+
+
+@task
+def start():
+    with cd('qcg-portal'):
+        run("uwsgi --ini uwsgi.ini")
+
+
+@task
+def stop():
+    run("uwsgi --stop " + PID_FILE)
+
+
+@task
+def restart():
+    run("uwsgi --reload " + PID_FILE)
+
+
+def is_running():
+    with settings(hide('everything'), warn_only=True):
+        return not run("ps -p `cat {}`".format(PID_FILE), shell_escape=False).failed
+
+
+@task
+def status():
+    print "Server is",
+    print "running." if is_running() else "not running."
+
+
+#################################################
+# deployment (remote)
+#################################################
+
+@task
+def git_status():
+    with cd('qcg-portal'):
+        run("git status")
+
+
+@task
+def deploy(load_ex_data=False):
+    with cd('qcg-portal'):
+        run("git pull")
+
+        run("pip install -r requirements.txt")
+        run("python manage.py migrate qcg")
+        run("python manage.py collectstatic --noinput")
+
+        if is_running:
+            run("uwsgi --reload " + PID_FILE)
+        else:
+            run("uwsgi --ini uwsgi.ini")
\ No newline at end of file
index 64eaf2e..91510c3 100644 (file)
@@ -1,3 +1,4 @@
 -r requirements.txt
 django-sslserver
-django-debug-toolbar
\ No newline at end of file
+django-debug-toolbar
+Fabric
\ No newline at end of file
diff --git a/uwsgi.ini b/uwsgi.ini
new file mode 100644 (file)
index 0000000..52256df
--- /dev/null
+++ b/uwsgi.ini
@@ -0,0 +1,37 @@
+[uwsgi]
+base-dir = /home/portal/qcg-portal
+
+uid = portal
+gid = portal
+
+cache2 = name=ssl,items=1000,keysize=128,blocksize=4096
+ssl-sessions-use-cache = ssl
+ssl-sessions-timeout = 300
+
+shared-socket = :80
+shared-socket = :443
+
+http-to-https = =0
+https = =1,%(base-dir)/certs/cert.crt,%(base-dir)/certs/cert.key,EECDH+aRSA+AES:EDH+aRSA+AES:kRSA+AES:@STRENGTH
+
+add-header = Strict-Transport-Security: max-age=31536000
+
+workers = 6
+enable-threads = True
+; this do not play well with ssl cache...
+; thunder-lock = True
+
+master = True
+vacuum = True
+umask = 022
+pidfile = /var/run/uwsgi.pid
+logfile-chmod = 644
+daemonize = %(base-dir)/uwsgi.master.log
+stats = %(base-dir)/uwsgi.stats.socket
+
+chdir = %(base-dir)
+virtualenv = /home/portal/venv
+module = plgng.wsgi:application
+env = DJANGO_SETTINGS_MODULE=plgng.settings_prod
+
+static-map = /static=%(base-dir)/server-static