Missing Documentation for Celery as a Daemon

(0 comments)

Celery is really easy to set up on a development machine, but what is harder is running the workers reliably in production. the documentation expects you to understand linux services, or rc.d, and with little explanation presents a 200+ line init.d script. My needs are pretty modest. I have one task that creates a bunch of PDF files with reportlab and attaches them to an email. The only people who use this facility are a set of 4 staff members who work in the same office, and use the interface of the web application.

What I need is to deploy celery so I could get this task to run asynchronously, and not cause the page to time out. I don't need to worry about jobs being lost on the redis queue if a worker crashed, because the task logged its action, and an icon changed to indicate that the task had been successful.

What I have started with is a basic /etc/init.d script that does just this. I will append this post with more sophisticated versions as I learn more, but the script at the end causes celery to restart if killed. To visualise what happens now at the command line:

This is my /etc/init.d/celeryd script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# chkconfig: 2345 20 80

# Source function library.
#. /etc/init.d/functions

start() {
    # code to start app comes here 
    set -e
    cd /my/webapplication/
    sudo -u non-root-user /my/webapplication/bin/celery -A myapp worker &
}

stop() {
    # code to stop app comes here 
    pkill -f celery"$"
}

case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here 
       # example: status program_name
       ps auxww | grep celery | grep -v grep | grep -v status
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0
Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional