Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An Ansible playbook for daemonising long running django commands using runit
- hosts: django
user: root
- runit_app_dir: /etc/sv
- runit_enabled_dir: /etc/service
- dj_manage_daemons:
- slug: "unique_name_slug_1"
command: "rqworker queue_name_1"
- slug: "unique_name_slug_2"
command: "rqworker queue_name_2"
- name: "install runit"
apt: name=runit
- name: create runit daemons dirs
file: path="{{runit_app_dir}}/{{item.slug}}" state=directory
with_items: dj_manage_daemons
- name: upload runit run scripts for daemons
template: src=templates/runit/django_manage/etc/sv/run
dest="{{runit_app_dir}}/{{item.slug}}/run" mode=0755
with_items: dj_manage_daemons
- name: start the daemon by creating a symlink in /etc/service
file: src="{{runit_app_dir}}/{{item.slug}}" dest="{{runit_enabled_dir}}/{{item.slug}}" state=link
with_items: dj_manage_daemons
exec chpst -u {{user}} {{virtualenv_python}} {{django_base_dir}}/ {{item.command}}

This comment has been minimized.

Copy link
Owner Author

commented Oct 8, 2014

put the file run template file in templates/runit/django_manage/etc/sv/run

I created this in order to daemonise a django redis queue (, but it could be used for any management command that you want to run forever. You could use it as a cron substitute if you wanted to execute something in python every 10 seconds (not easy with cron).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.