Created
October 8, 2014 12:37
-
-
Save mbylstra/2835b46f4b44de4359c0 to your computer and use it in GitHub Desktop.
An Ansible playbook for daemonising long running django manage.py commands using runit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: django | |
user: root | |
vars: | |
- 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" | |
tasks: | |
- 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec chpst -u {{user}} {{virtualenv_python}} {{django_base_dir}}/manage.py {{item.command}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put the file
run
template file intemplates/runit/django_manage/etc/sv/run
I created this in order to daemonise a django redis queue (https://github.com/ui/django-rq), 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).