[cubicweb/uwsgi] add uwsgi deploiement when configured
authorArthur Lutz <arthur.lutz@logilab.fr>
Tue, 29 Nov 2016 11:30:23 +0100
changeset 86 877e5d35b386
parent 85 3c8fc1103e94
child 87 bf89ca4e5aad
[cubicweb/uwsgi] add uwsgi deploiement when configured
README.rst
cubicweb/instances.sls
cubicweb/uwsgi/init.sls
cubicweb/uwsgi/uwsgi.ini
pillar.example
--- a/README.rst	Tue Oct 11 14:47:31 2016 +0200
+++ b/README.rst	Tue Nov 29 11:30:23 2016 +0100
@@ -9,6 +9,31 @@
     See the full `Salt Formulas installation and usage instructions
     <http://docs.saltstack.com/topics/conventions/formulas.html>`_.
 
+Available states
+================
+
+.. contents::
+    :local:
+
+``cubicweb``
+----------
+
+Installs the cubicweb application
+
+``cubicweb.instances``
+----------------------
+
+Installs cubicweb and configures an application
+
+``cubicweb.apache``
+-------------------
+
+Installs cubicweb with a an apache frontal
+
+``cubicweb.postgres``
+---------------------
+
+Installas cubicweb with an postgres server on the same host
 
 Quick start
 ===========
@@ -16,8 +41,8 @@
 * set your pillars from pillar.example
 * add the cubicweb states to your top.sls:
   - use the ``cubicweb.postgres`` state on the database host
-  - use the ``cubicweb.instances`` state for the host that will run cubicweb applications 
-  - use the ``cubicweb.apache`` state on the web frontend host 
+  - use the ``cubicweb.instances`` state for the host that will run cubicweb applications
+  - use the ``cubicweb.apache`` state on the web frontend host
 * salt 'host' saltutil.sync_all
 * salt 'host' saltutil.refresh_pillar
 * salt 'host' state.highstate
--- a/cubicweb/instances.sls	Tue Oct 11 14:47:31 2016 +0200
+++ b/cubicweb/instances.sls	Tue Nov 29 11:30:23 2016 +0100
@@ -1,5 +1,13 @@
 include:
   - cubicweb
+{% for vhostname, vhost in pillar['cubicweb_apps'].iteritems() %}
+ {% for name, config in vhost.iteritems() %}
+   {% if 'cwapp_uwsgi_options' in config %}
+  - cubicweb.uwsgi
+   {% endif %}
+ {% endfor %}
+{% endfor %}
+
 
 {% for extrasrc in salt['pillar.get']('extra_sources', ()) %}
 {% if 'https' in  extrasrc %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/uwsgi/init.sls	Tue Nov 29 11:30:23 2016 +0100
@@ -0,0 +1,36 @@
+
+uwsgi install:
+  pkg.installed:
+    - pkgs:
+      - uwsgi
+      - uwsgi-plugin-python
+
+service uwsgi running:
+  service.running:
+    - name: uwsgi
+
+
+{% for vhostname, vhost in pillar['cubicweb_apps'].iteritems() %}
+ {% for name, config in vhost.iteritems() %}
+/etc/uwsgi/apps-available/{{ name }}.ini:
+  file.managed:
+    - source: salt://cubicweb/uwsgi/uwsgi.ini
+    - template: jinja
+    - context:
+       config: config
+       name: config
+    - require:
+      - pkg: uwsgi install
+
+/etc/uwsgi/apps-enabled/{{ name }}.ini:
+  file.symlink:
+    - target: /etc/uwsgi/apps-available/{{ name }}.ini
+    - require:
+      - file: /etc/uwsgi/apps-available/{{ name }}.ini
+    - watch:
+      - service: uwsgi
+  {% endfor %}
+{% endfor %}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/uwsgi/uwsgi.ini	Tue Nov 29 11:30:23 2016 +0100
@@ -0,0 +1,14 @@
+[uwsgi]
+master = true
+http = 0.0.0.0:{{ config.cwapp.port|default('8080', true) }}
+env = CW_INSTANCE={{ name }}
+#env = CW_DEBUG=1
+module = pyramid_cubicweb:wsgi_application()
+processes = {{ config.cwapp_uwsgi_options.workers }}
+threads = {{ config.cwapp_uwsgi_options.workers }}
+plugins = http,python
+auto-procname = true
+lazy-apps = true
+log-master = true
+# disable uwsgi request logging
+disable-logging = true
--- a/pillar.example	Tue Oct 11 14:47:31 2016 +0200
+++ b/pillar.example	Tue Nov 29 11:30:23 2016 +0100
@@ -1,10 +1,10 @@
 ## Apache related configurations
-apache: 
+apache:
   disable_default: False # set to True to disable default apache configuration (000-default)
   modules: # this requires the https://github.com/saltstack-formulas/apache-formula formula
     enabled:
        - rewrite # list of modules to enable
-  vhost_conf: | 
+  vhost_conf: |
     # insert inline configuration
     # lines here, valid for all vhosts
 
@@ -13,24 +13,24 @@
     - fr_FR.UTF-8
     - en_US.UTF-8
   system: en_US.UTF-8
-    
+
 postgresql:
 #  version: 9.4
 #set true to make postresql listen on the network
 #  listen_tcp: False
-#pg_hdba lines to insert 
-#   pg_hba_lines: | 
+#pg_hdba lines to insert
+#   pg_hba_lines: |
 #    host    all             all             10.1.1.3/32            md5
 
-cubicweb_repo: production # set to acceptance if you want more recent versions of cubicweb 
+cubicweb_repo: production # set to acceptance if you want more recent versions of cubicweb
 
 ## you may specify a precise cw version (package version). If set, the
 ## 'cubicweb_repo' option is ignored
 #cubicweb_version: 3.20.5-1
 
 ## You can add extra repository sources
-## when extra_sources is defined and debian_pkgrepos is undefined the "all dependencies are 
-## availble in that extra source" scenario is used, no public cubicweb debian repository 
+## when extra_sources is defined and debian_pkgrepos is undefined the "all dependencies are
+## availble in that extra source" scenario is used, no public cubicweb debian repository
 ## will be configured. Changes pending from https://www.cubicweb.org/ticket/5714468
 #extra_sources:
 #  - deb https://user:password@domain.com/path/dists/ wheezy/
@@ -63,6 +63,9 @@
       cwapp_config_options:
         WEB:
           base-url: http://base_url
+      cwapp_uwsgi_options:
+        workers: 2
+        threads: 8
     demo2:
       database:
         name: cw_demo2