From 53f446e219fc5e24c7497fcfacc529426859a49b Mon Sep 17 00:00:00 2001 From: Denis Zheleztsov Date: Tue, 7 Feb 2017 12:41:43 +0300 Subject: [PATCH] Docs update --- docs/App-config-file.md | 19 ++--- docs/Main-config-file.md | 67 ++++++++++++--- docs/Templates.md | 179 +++++++++++++++++++++++++++++++-------- 3 files changed, 208 insertions(+), 57 deletions(-) diff --git a/docs/App-config-file.md b/docs/App-config-file.md index 5156e5a..34963d6 100644 --- a/docs/App-config-file.md +++ b/docs/App-config-file.md @@ -5,19 +5,16 @@ conf.d/myapp.json { "services": [ { - "name": "myapp", - "group": "backend.production", - "ports": ["proxy", "api"] - }, - { - "name": "nginx", - "group": "frontend.production" + "name": "kioskservice", + "group": "production.romania", + "ports": ["web", "socket"] } ], - "conf_name": "myapp_backend_production", - "template": "/etc/surok/templates/myapp.jj2", - "dest": "/etc/myapp/myapp.cfg", - "reload_cmd": "killall -9 myapp; /usr/local/bin/myapp -config /etc/myapp/myapp.cfg" + "conf_name": "kiosk", + "template": "/etc/surok/templates/kiosk.jj2", + "dest": "/etc/nginx/sites-available/kioskservice.conf", + "reload_cmd": "/sbin/nginx -t && /bin/systemctl reload nginx", + "run_cmd": ["/usr/bin/node", "-c", "config.json"] } ``` * **services**. List of hashes with required services for app. diff --git a/docs/Main-config-file.md b/docs/Main-config-file.md index db2efd6..60f33ab 100644 --- a/docs/Main-config-file.md +++ b/docs/Main-config-file.md @@ -1,10 +1,10 @@ -# Surok main config file +# Surok main config file (0.8.x) -Default location is /etc/surok/conf/surok.json +Default location is **/etc/surok/conf/surok.json** -conf/surok.json ``` { + "version": "0.8" "marathon": { "enabled": false, "restart": false, @@ -24,7 +24,6 @@ conf/surok.json "wait_time": 20, "lock_dir": "/var/tmp", "loglevel": "info", - "container": false, "memcached": { "enabled": false, "discovery": { @@ -36,10 +35,56 @@ conf/surok.json } } ``` -* **marathon section**. Restarting app over marathon api if config changed. Disabled by default. -* **confd**. Directory where located configs apps. -* **domain**. Domain served by mesos-dns. -* **lock_dir**. Directory where surok writes temporary configs after resolving. -* **wait_time**. Sleep time in main loop. -* **container**. Not implemented. -* **memcached section**. Memcached support. Disabled by default. + +## Config file options +* **version** - *string. Optional. "0.7" by default.* +Config files and templates version. Accept "0.7" or "0.8". + * "0.7" - config files <= 0.7.х version + * "0.8" - >= 0.8.x config files version + +##### 0.8 version +* **marathon**, **mesos**, **consul**, **memcached** - *dict/hash. Optional. '{"enable":false}'. by default* +Surok working with folowing systems. If system is disabled parameters will be ignored. + * **enable** - *boolean. Optional. false by default* + Enable/disable system for usage. + + Specific variables: + * For Marathon API "marathon" + * **force** - *boolean. Optional. true by default* + Force restart container over API. + * **restart** - *boolean. Optional. false by default* + Enable/disable restarting container + * **host** - *string. Optional. "http://marathon.mesos:8080" by default* + Marathon address. + * For Consul "consul" + * **domain** - *string. Required.* + Consul private domain + * For mesos-dns "mesos" + * **domain** - *string. Optional. "marathon.mesos" by default* + mesos-dns private domain + * For Memcached "memcached" + * **hosts** - memcached hosts + * **discovery** + * **enabled** - boolean. Enable/disable disovery memcached service + * **service** - string. memcached app name + * **group** - string. memcached app group +* **default_discovery** - *string. Optional. "mesos_dns" by default* + Accept values: + * "mesos_dns" - mesos-dns + * "marathon_api"- Marathon API + * "consul_dns" - Consul +* **confd** - *strig. Required.* + Path to directory with app config files. +* **wait_time** - *int. Required.* + Time in seconds how much Surok waits before starting to re-do the requests for service discovery +* **lock_dir** - *string. Required.* + Path to directory where Surok write lock-files. +* **loglevel** - *string. Optional. "info" by default* + Logleve. Accept values: "debug", "info", "warning", "error" + +##### < 0.8 versions + +* **marathon** + * **enabled** - boolean. Enable/disable container restart. Renamed to "restart" in 0.8 version. +* **domain** - string. mesos-dns private domain. Moved to "mesos" hashtable in 0.8 version. + Discovery over mesos-dns enabled all times. diff --git a/docs/Templates.md b/docs/Templates.md index 50ea7d5..90d2431 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -5,8 +5,11 @@ - [Templates](#templates) - [my dictionary in templates](#my-dictionary-in-templates) - - [Real template example](#real-template-example) - - [Checks in template](#checks-in-template) + - [0.8 version](#08-version) + - [Real template example](#real-template-example) + - [Checks in template](#checks-in-template) + - [0.7 version](#07-version) + - [Real template example](#real-template-example) @@ -15,55 +18,74 @@ Surok using Jinja2 for templates. [Jinja2 documentation](http://jinja.pocoo.org/ ## my dictionary in templates +### 0.8 version + ``` { "services": { - "nginx": [ + "asterisk": [ { - "name": "nginx.testing-kl92-s0.marathon.mesos.", - "port": "31200", - "ip": ["10.10.10.1"] + "name": "nginx.testing-kl92-s0.marathon.mesos.", + "ip": [ + "10.0.0.1", + "11.0.0.1" + ], + "tcp": { + "rpc":31200, + "web":31201, + "sip":32000 + }, + "udp": { + "sip":31201 + } }, { - "name": "nginx.testing-kl123-s1.marathon.mesos.", - "port": "32230", - "ip": ["10.10.10.2"] + "name": "nginx.testing-kl123-s1.marathon.mesos.", + "ip": [ + "10.0.0.2", + "11.0.0.2" + ], + "tcp": { + "rpc":31210, + "web":31211, + "sip":32010 + }, + "udp": { + "sip":31211 + } } ], - "emailsender": [ + "email": [ { - "name": "emailsender.testing-kl92-s0.marathon.mesos.", - "port": "31201", - "ip": ["10.10.10.1"] - }, - { - "name": "emailsender.testing-kl123-s1.marathon.mesos.", - "port": "32232", - "ip": ["10.10.10.1"] + "name": "nginx.testing-kl92-s0.marathon.mesos.", + "ip": [ + "10.0.0.1" + ], + "tcp": { + "smtp":31200, + "pop":31201 + } } ], - "service-with-defined-ports": { - "web": [ - { - "name": "f.q.d.n", - "port": 12341 - } - ], - "rpc": [ - { - "name": "f.q.d.n", - "port": 12342 - } - ] - } - }, + "anyport": [ + { + "name": "nginx.testing-kl92-s0.marathon.mesos.", + "ip": [ + "10.0.0.1" + ], + "tcp": [ + 31200, + 31201 + ] + } + ] "env": { "HOME": "/var/lib/nginx" } } ``` -## Real template example +#### Real template example nginx config ``` @@ -104,7 +126,7 @@ server { } ``` -## Checks in template +#### Checks in template _my['env']_ is a python os.environ class. Look bellow: ``` @@ -114,3 +136,90 @@ host = '{{my['env']['DB_HOST']}}' host = 'localhost' {% endif %} ``` + +### 0.7 version + +my dictionary in template +``` +{ + "services": { + "nginx": [ + { + "name": "nginx.testing-kl92-s0.marathon.mesos.", + "port": "31200" + }, + { + "name": "nginx.testing-kl123-s1.marathon.mesos.", + "port": "32230" + } + ], + "emailsender": [ + { + "name": "emailsender.testing-kl92-s0.marathon.mesos.", + "port": "31201" + }, + { + "name": "emailsender.testing-kl123-s1.marathon.mesos.", + "port": "32232" + } + ], + "service-with-defined-ports": { + "name-of-port0": [ + { + "name": "f.q.d.n", + "port": 12341 + } + ], + "name-of-port2": [ + { + "name": "f.q.d.n", + "port": 12342 + } + ] + } + }, + "env": { + "HOME": "/var/lib/nginx" + } +} +``` + +#### Real template example + +``` +upstream matrix-http { + hash $remote_addr; +{% for server in my['services']['matrix']['http'] %} + server {{server['name']}}:{{server['port']}} max_fails=3; +{% endfor %} +} + +upstream riot-http { + hash $remote_addr; +{% for server in my['services']['riot'] %} + server {{server['name']}}:{{server['port']}} max_fails=3; +{% endfor %} +} + +server { + listen 10.15.56.157:80; + server_name matrix.example.com; + + client_max_body_size 10m; + + location / { + proxy_pass http://riot-http; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /_matrix/ { + proxy_pass http://matrix-http; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + +} +```