Skip to content

Instantly share code, notes, and snippets.

@macghriogair
Created August 31, 2018 12:46
Show Gist options
  • Save macghriogair/838f7243de657e13f8df416134ca1885 to your computer and use it in GitHub Desktop.
Save macghriogair/838f7243de657e13f8df416134ca1885 to your computer and use it in GitHub Desktop.
[Supervisord Config Generator] #supervisord
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Patrick Mac Gregor
# @Date: 2018-05-24
# @Last Modified by: Patrick Mac Gregor
# @Last Modified time: 2018-05-24
import sys
from jinja2 import Template
from inspect import cleandoc
from pydash.strings import kebab_case
def get_template():
"""Returns the template"""
template = """# auto-generated file. any changes will be overidden
{% for program in programs %}
[program:index-{{ program.name }}]
user=www-data
command=php -d memory_limit=256M /var/www/sites/dav-drugbase/project/bin/console drugbase:re-index -c {{ program.type }} --no-debug
numprocs=1
numprocs_start=1
autostart=false
autorestart=unexpected
exitcodes=0
stderr_logfile=/var/log/supervisor/index-{{ program.name }}.err.log
stdout_logfile=/var/log/supervisor/index-{{ program.name }}.out.log
{% endfor %}
"""
return Template(cleandoc(template))
if __name__ == '__main__':
"""Autogenerates my supervisord conf for indexer programs."""
# Each type will have its own program
types = sys.argv[1].split(',')
programs = []
for item in types:
programs.append({
'name': kebab_case(item),
'type': item
})
tpl = get_template()
# stream template to file directly
tpl.stream(programs=programs).dump('indexers.conf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment