diff --git a/docs/App-config-file.html b/docs/App-config-file.html new file mode 100644 index 0000000..8c0bd6e --- /dev/null +++ b/docs/App-config-file.html @@ -0,0 +1,46 @@ + + + + + +
+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) SUROKDISCOVERYGROUP environment variable 3) Marathon API
+ 3. ports - list. Name of opened port. In marathon of course. Optional.
+* confname. Unique app config name.
+* template. Jinja2 template location.
+* dest. Destination config path.
+* reloadcmd. Command to execute if generated config is changed.
build debian package
+
+cd build
+./build.sh build_package
+
+A deb-package will be placed in build/out
build surok base docker image(based on Ubuntu Xenial)
+
+cd build
+./build.sh surok_image
+
build surok base Alpine image
+
+cd build
+./build.sh alpine
+
build surok base CentOS image
+
+cd build
+./build.sh centos
+
ENTRYPOINT is: cd /opt/surok && pytho3 surok.py -c /etc/surok/conf/surok.json
Default location is /etc/surok/conf/surok.json
+ +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.
+* lockdir. Directory where surok writes temporary configs after resolving.
+* waittime. Sleep time in main loop.
+* container. Not implemented.
+* memcached section. Memcached support. Disabled by default.
Surok using Jinja2 for templates. Jinja2 documentation
+ +
+{
+ "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"
+ }
+}
+
nginx config +``` +upstream matrix-http { + hash $remoteaddr; +{% for server in my['services']['matrix']['http'] %} + server {{server['name']}}:{{server['port']}} maxfails=3; +{% endfor %} +}
+ +upstream riot-http { + hash $remoteaddr; +{% for server in my['services']['riot'] %} + server {{server['name']}}:{{server['port']}} maxfails=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;
+}
+
+
+} +```
+ +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 %}
+
Write supervisord.conf. Example: +```ini +[unixhttpserver] +file=/tmp/supervisor.sock
+ +[supervisord] +logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) +logfilemaxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) +logfilebackups=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.rpcinterfacefactory = supervisor.rpcinterface:makemain_rpcinterface
+ +[program:surok] +command=/usr/bin/python3 /opt/surok/surok.py -c /etc/surok/conf/surok.json
+ +[program:myservice] +command=/app/myservice -conf /app/conf/my_service.conf +user=www-data +startsecs=2 +```
+ +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"
+
+
+} +```
+ +```dockerfile +...
+ +RUN easy_install supervisor +ADD supervisord.conf /etc
+ +ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf +```
+ + + diff --git a/docs/Use-Surok-with-supervisord.md b/docs/Use-Surok-with-supervisord.md index 2b7ca3b..e218e82 100644 --- a/docs/Use-Surok-with-supervisord.md +++ b/docs/Use-Surok-with-supervisord.md @@ -1,5 +1,16 @@ # Use Surok with supervisord + +**Table of Contents** + +- [Use Surok with supervisord](#use-surok-with-supervisord) + - [supervisord.conf](#supervisordconf) + - [surok service conf](#surok-service-conf) + - [install supervisord in you container and set it as entrypoint](#install-supervisord-in-you-container-and-set-it-as-entrypoint) + + + + ## supervisord.conf Write supervisord.conf. Example: ```ini @@ -57,4 +68,4 @@ RUN easy_install supervisor ADD supervisord.conf /etc ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf -``` \ No newline at end of file +``` diff --git a/docs/index.html b/docs/index.html index 280d6ba..e4b59f5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -28,17 +28,17 @@