wiki to docs

This commit is contained in:
Denis Zheleztsov 2017-01-12 12:43:30 +03:00
parent 922d670edd
commit 5c0d06586a
5 changed files with 235 additions and 0 deletions

28
docs/App-config-file.md Normal file
View File

@ -0,0 +1,28 @@
conf.d/myapp.json
```
{
"services": [
{
"name": "myapp",
"group": "backend.production",
"ports": ["proxy", "api"]
},
{
"name": "nginx",
"group": "frontend.production"
}
],
"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"
}
```
* **services**. List of hashes with required services for app.
1. _name_ - string. App name in Marathon.
2. _group_ - string. App group in Marathon. Optional. Discovery policy: 1) config 2) SUROK_DISCOVERY_GROUP environment variable 3) Marathon API
3. _ports_ - list. Name of opened port. In marathon of course. Optional.
* **conf_name**. Unique app config name.
* **template**. Jinja2 template location.
* **dest**. Destination config path.
* **reload_cmd**. Command to execute if generated config is changed.

10
docs/Home.md Normal file
View File

@ -0,0 +1,10 @@
- **Surok**
- **Configs**
- [Main config file](https://github.com/Difrex/surok/wiki/Main-config-file)
- [App config file](https://github.com/Difrex/surok/wiki/App-config-file)
- [Templates](https://github.com/Difrex/surok/wiki/Templates)
- **Usage**
- [Use Surok with supervisord](https://github.com/Difrex/surok/wiki/Use-Surok-with-supervisord)
- **Authors**
* Denis Zheleztsov <difrex.punk@gmail.com>
* Denis Ryabyy <vv1r0x@gmail.com>

32
docs/Main-config-file.md Normal file
View File

@ -0,0 +1,32 @@
conf/surok.json
```
{
"marathon": {
"force": true,
"host": "http://marathon.mesos:8080",
"enabled": false
},
"confd": "/etc/surok/conf.d",
"domain": "marathon.mesos",
"wait_time": 20,
"lock_dir": "/var/tmp",
"loglevel": "info",
"container": false,
"memcached": {
"enabled": false,
"discovery": {
"enabled": false,
"service": "memcached",
"group": "system"
},
"hosts": ["localhost:11211"]
}
}
```
* **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.

105
docs/Templates.md Normal file
View File

@ -0,0 +1,105 @@
# Templates
Surok using Jinja2 for templates. [Jinja2 documentation](http://jinja.pocoo.org/docs/dev/)
## my dictionary in templates
```
{
"services": {
"nginx": [
{
"name": "nginx.testing-kl92-s0.marathon.mesos.",
"port": "31200",
"ip": ["10.10.10.1"]
},
{
"name": "nginx.testing-kl123-s1.marathon.mesos.",
"port": "32230",
"ip": ["10.10.10.2"]
}
],
"emailsender": [
{
"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"]
}
],
"service-with-defined-ports": {
"web": [
{
"name": "f.q.d.n",
"port": 12341
}
],
"rpc": [
{
"name": "f.q.d.n",
"port": 12342
}
]
}
},
"env": {
"HOME": "/var/lib/nginx"
}
}
```
## Real template example
nginx config
```
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;
}
}
```
## Checks in template
_my['env']_ is a python os.environ class. Look bellow:
```
{% if my['env'].get('DB_HOST') %}
host = '{{my['env']['DB_HOST']}}'
{% else %}
host = 'localhost'
{% endif %}
```

View File

@ -0,0 +1,60 @@
# Use Surok with supervisord
## supervisord.conf
Write supervisord.conf. Example:
```ini
[unix_http_server]
file=/tmp/supervisor.sock
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:surok]
command=/usr/bin/python3 /opt/surok/surok.py -c /etc/surok/conf/surok.json
[program:my_service]
command=/app/my_service -conf /app/conf/my_service.conf
user=www-data
startsecs=2
```
## surok service conf
Write /etc/surok/conf.d/my_service.json config like that
```json
{
"services": [
{
"name": "my-service",
"group": "production.web"
}
],
"conf_name": "my_service",
"template": "/etc/surok/templates/my-service.jj2",
"dest": "/app/conf/my_service.conf",
"reload_cmd": "/usr/bin/supervisorctl restart my_service"
}
```
## install supervisord in you container and set it as entrypoint
```dockerfile
...
# Install supervisord and provide config
RUN easy_install supervisor
ADD supervisord.conf /etc
ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf
```