Commit 28452e2b authored by Leo Pound Singer's avatar Leo Pound Singer
Browse files

WIP: Start, stop, and supervise gwcelery with monit

This is an alternative to !343.
parent 72bd5204
Pipeline #51910 passed with stages
in 1 minute and 55 seconds
{% set LOG_DIR %}{{XDG_CONFIG_HOME}}/log/gwcelery{% endset -%}
{% set RUN_DIR %}{{XDG_RUNTIME_DIR}}/gwcelery{% endset -%}
{% set STATE_DIR %}{{XDG_CONFIG_HOME}}/gwcelery{% endset -%}
check directory log-dir path "{{LOG_DIR}}"
start program = "/bin/mkdir -p {{LOG_DIR}}"
check directory run-dir path "{{RUN_DIR}}"
start program = "/bin/mkdir -p {{RUN_DIR}}"
check directory state-dir path "{{STATE_DIR}}"
start program = "/bin/mkdir -p {{STATE_DIR}}"
{%- macro PIDFILE_PROCESS(name) %}
{% set PIDFILE %}{{RUN_DIR}}/name.pid{% endset %}
check process {{name}} with pidfile "{{PIDFILE}}"
stop program = "/bin/sh -c 'kill $(cat {{PIDFILE}})'"
{{caller(PIDFILE)}}
{%- endmacro -%}
{%- macro ENV() %}
/usr/bin/env CELERY_BROKER_URL=redis+socket://{{RUN_DIR}}/redis.sock
{%- endmacro -%}
{% call(PIDFILE) PIDFILE_PROCESS('redis') %}
depends on log-dir, run-dir
start program = "
/usr/bin/env
redis-server
--daemonize yes
--pidfile {{PIDFILE}}
--unixsocket {{RUN_DIR}}/redis.sock
--unixsocketperm 700
--client-output-buffer-limit normal 0 0 0
--client-output-buffer-limit replica 256mb 64mb 60
--client-output-buffer-limit pubsub 256mb 64mb 60
--logfile {{LOG_DIR}}/redis.log
--port 0"
{% endcall %}
{% call(PIDFILE) PIDFILE_PROCESS('beat') %}
depends on log-dir, run-dir, state-dir, redis
start program = "
{{ENV()}}
gwcelery beat
--detach
--pidfile {{PIDFILE}}
--logfile {{LOG_DIR}}/beat.log
--loglevel ERROR
--schedule {{STATE_DIR}}/beat"
{% endcall %}
{% call(PIDFILE) PIDFILE_PROCESS('flask') %}
depends on log-dir, run-dir, redis
start program = "
/usr/sbin/daemonize
-v -a -e {{LOG_DIR}}/flask.log
-p {{PIDFILE}}
{{ENV()}}
gwcelery flask run --with-threads --host 0.0.0.0"
{% endcall %}
{% call(PIDFILE) PIDFILE_PROCESS('flower') %}
depends on log-dir, run-dir, redis
start program = "
/usr/sbin/daemonize
-v -a -e {{LOG_DIR}}/flower.log
-p {{PIDFILE}}
{{ENV()}}
gwcelery flower"
{% endcall %}
{%- macro WORKER(queue, args='') %}
check process {{queue}} with pidfile "{{RUN_DIR}}/{{queue}}.pid"
depends on log-dir, run-dir, redis
start program = "
{{ENV()}}
gwcelery multi start
{{queue}} {{args}}
--loglevel=info --queues=%n --hostname=%n
--logfile={{LOG_DIR}}/%n.log
--pidfile={{RUN_DIR}}/%n.pid"
restart program = "
{{ENV()}}
gwcelery multi restart
{{queue}} {{args}}
--loglevel=info --queues=%n --hostname=%n
--logfile={{LOG_DIR}}/%n.log
--pidfile={{RUN_DIR}}/%n.pid"
stop program = "
{{ENV()}}
gwcelery multi stopwait {{queue}} --pidfile={{RUN}}/%n.pid"
{%- endmacro %}
{{WORKER('celery')}}
{{WORKER('exttrig', '--concurrency=1')}}
{{WORKER('openmp', '--concurrency=1')}}
{{WORKER('superevent', '--concurrency=1')}}
{{WORKER('voevent', '--pool=solo')}}
set daemon 5
set httpd unixsocket {{RUN_DIR}}/monit.sock allow localhost
set log {{LOG_DIR}}/monit.log
"""Create a monitrc file for running GWCelery under the current user
account."""
import os
from celery.bin.base import Command
from ..jinja import env
class MonitrcCommand(Command):
"""Check Celery status for monitoring with Nagios."""
def run(self, **kwargs):
print(env.get_template('monitrc.jinja2').render(**os.environ))
......@@ -48,6 +48,7 @@ python_requires = >=3.6, <3.7
celery.commands =
condor = gwcelery.tools.condor:CondorCommand
flask = gwcelery.tools.flask:FlaskCommand
monitrc = gwcelery.tools.monitrc:MonitrcCommand
nagios = gwcelery.tools.nagios:NagiosCommand
console_scripts =
gwcelery = gwcelery:app.start
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment