root / init_scripts / celeryd @ d0777394
History | View | Annotate | Download (3.7 kB)
1 | 8f17dc8f | Leonidas Poulopoulos | #!/bin/sh -e |
---|---|---|---|
2 | 8f17dc8f | Leonidas Poulopoulos | # ============================================ |
3 | 8f17dc8f | Leonidas Poulopoulos | # celeryd - Starts the Celery worker daemon. |
4 | 8f17dc8f | Leonidas Poulopoulos | # ============================================ |
5 | 8f17dc8f | Leonidas Poulopoulos | # |
6 | 8f17dc8f | Leonidas Poulopoulos | # :Usage: /etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status} |
7 | 8f17dc8f | Leonidas Poulopoulos | # :Configuration file: /etc/default/celeryd |
8 | 8f17dc8f | Leonidas Poulopoulos | # |
9 | 8f17dc8f | Leonidas Poulopoulos | # See http://docs.celeryq.org/en/latest/cookbook/daemonizing.html#init-script-celeryd |
10 | 8f17dc8f | Leonidas Poulopoulos | |
11 | 8f17dc8f | Leonidas Poulopoulos | |
12 | 8f17dc8f | Leonidas Poulopoulos | ### BEGIN INIT INFO |
13 | 8f17dc8f | Leonidas Poulopoulos | # Provides: celeryd |
14 | 8f17dc8f | Leonidas Poulopoulos | # Required-Start: $network $local_fs $remote_fs |
15 | 8f17dc8f | Leonidas Poulopoulos | # Required-Stop: $network $local_fs $remote_fs |
16 | 8f17dc8f | Leonidas Poulopoulos | # Default-Start: 2 3 4 5 |
17 | 8f17dc8f | Leonidas Poulopoulos | # Default-Stop: 0 1 6 |
18 | 8f17dc8f | Leonidas Poulopoulos | # Short-Description: celery task worker daemon |
19 | 8f17dc8f | Leonidas Poulopoulos | ### END INIT INFO |
20 | 8f17dc8f | Leonidas Poulopoulos | |
21 | 8f17dc8f | Leonidas Poulopoulos | #set -e |
22 | 8f17dc8f | Leonidas Poulopoulos | |
23 | 8f17dc8f | Leonidas Poulopoulos | DEFAULT_PID_FILE="/var/run/celeryd@%n.pid" |
24 | 8f17dc8f | Leonidas Poulopoulos | DEFAULT_LOG_FILE="/var/log/celeryd@%n.log" |
25 | 8f17dc8f | Leonidas Poulopoulos | DEFAULT_LOG_LEVEL="INFO" |
26 | 8f17dc8f | Leonidas Poulopoulos | DEFAULT_NODES="celery" |
27 | 8f17dc8f | Leonidas Poulopoulos | DEFAULT_CELERYD="-m celery.bin.celeryd_detach" |
28 | 8f17dc8f | Leonidas Poulopoulos | |
29 | 8f17dc8f | Leonidas Poulopoulos | # /etc/init.d/celeryd: start and stop the celery task worker daemon. |
30 | 8f17dc8f | Leonidas Poulopoulos | |
31 | 8f17dc8f | Leonidas Poulopoulos | CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/celeryd"} |
32 | 8f17dc8f | Leonidas Poulopoulos | |
33 | 8f17dc8f | Leonidas Poulopoulos | test -f "$CELERY_DEFAULTS" && . "$CELERY_DEFAULTS" |
34 | 8f17dc8f | Leonidas Poulopoulos | if [ -f "/etc/default/celeryd" ]; then |
35 | 8f17dc8f | Leonidas Poulopoulos | . /etc/default/celeryd |
36 | 8f17dc8f | Leonidas Poulopoulos | fi |
37 | 8f17dc8f | Leonidas Poulopoulos | |
38 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_PID_FILE=${CELERYD_PID_FILE:-${CELERYD_PIDFILE:-$DEFAULT_PID_FILE}} |
39 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_LOG_FILE=${CELERYD_LOG_FILE:-${CELERYD_LOGFILE:-$DEFAULT_LOG_FILE}} |
40 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}} |
41 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_MULTI=${CELERYD_MULTI:-"celeryd-multi"} |
42 | 8f17dc8f | Leonidas Poulopoulos | CELERYD=${CELERYD:-$DEFAULT_CELERYD} |
43 | 8f17dc8f | Leonidas Poulopoulos | CELERYCTL=${CELERYCTL:="celeryctl"} |
44 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_NODES=${CELERYD_NODES:-$DEFAULT_NODES} |
45 | 8f17dc8f | Leonidas Poulopoulos | |
46 | 8f17dc8f | Leonidas Poulopoulos | export CELERY_LOADER |
47 | 8f17dc8f | Leonidas Poulopoulos | |
48 | 8f17dc8f | Leonidas Poulopoulos | if [ -n "$2" ]; then |
49 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_OPTS="$CELERYD_OPTS $2" |
50 | 8f17dc8f | Leonidas Poulopoulos | fi |
51 | 8f17dc8f | Leonidas Poulopoulos | |
52 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_LOG_DIR=`dirname $CELERYD_LOG_FILE` |
53 | 8f17dc8f | Leonidas Poulopoulos | CELERYD_PID_DIR=`dirname $CELERYD_PID_FILE` |
54 | 8f17dc8f | Leonidas Poulopoulos | if [ ! -d "$CELERYD_LOG_DIR" ]; then |
55 | 8f17dc8f | Leonidas Poulopoulos | mkdir -p $CELERYD_LOG_DIR |
56 | 8f17dc8f | Leonidas Poulopoulos | fi |
57 | 8f17dc8f | Leonidas Poulopoulos | if [ ! -d "$CELERYD_PID_DIR" ]; then |
58 | 8f17dc8f | Leonidas Poulopoulos | mkdir -p $CELERYD_PID_DIR |
59 | 8f17dc8f | Leonidas Poulopoulos | fi |
60 | 8f17dc8f | Leonidas Poulopoulos | |
61 | 8f17dc8f | Leonidas Poulopoulos | # Extra start-stop-daemon options, like user/group. |
62 | 8f17dc8f | Leonidas Poulopoulos | if [ -n "$CELERYD_USER" ]; then |
63 | 8f17dc8f | Leonidas Poulopoulos | DAEMON_OPTS="$DAEMON_OPTS --uid=$CELERYD_USER" |
64 | 8f17dc8f | Leonidas Poulopoulos | chown "$CELERYD_USER" $CELERYD_LOG_DIR $CELERYD_PID_DIR |
65 | 8f17dc8f | Leonidas Poulopoulos | fi |
66 | 8f17dc8f | Leonidas Poulopoulos | if [ -n "$CELERYD_GROUP" ]; then |
67 | 8f17dc8f | Leonidas Poulopoulos | DAEMON_OPTS="$DAEMON_OPTS --gid=$CELERYD_GROUP" |
68 | 8f17dc8f | Leonidas Poulopoulos | chgrp "$CELERYD_GROUP" $CELERYD_LOG_DIR $CELERYD_PID_DIR |
69 | 8f17dc8f | Leonidas Poulopoulos | fi |
70 | 8f17dc8f | Leonidas Poulopoulos | |
71 | 8f17dc8f | Leonidas Poulopoulos | if [ -n "$CELERYD_CHDIR" ]; then |
72 | 8f17dc8f | Leonidas Poulopoulos | DAEMON_OPTS="$DAEMON_OPTS --workdir=\"$CELERYD_CHDIR\"" |
73 | 8f17dc8f | Leonidas Poulopoulos | fi |
74 | 8f17dc8f | Leonidas Poulopoulos | |
75 | 8f17dc8f | Leonidas Poulopoulos | |
76 | 8f17dc8f | Leonidas Poulopoulos | check_dev_null() { |
77 | 8f17dc8f | Leonidas Poulopoulos | if [ ! -c /dev/null ]; then |
78 | 8f17dc8f | Leonidas Poulopoulos | echo "/dev/null is not a character device!" |
79 | 8f17dc8f | Leonidas Poulopoulos | exit 1 |
80 | 8f17dc8f | Leonidas Poulopoulos | fi |
81 | 8f17dc8f | Leonidas Poulopoulos | } |
82 | 8f17dc8f | Leonidas Poulopoulos | |
83 | 8f17dc8f | Leonidas Poulopoulos | |
84 | 8f17dc8f | Leonidas Poulopoulos | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" |
85 | 8f17dc8f | Leonidas Poulopoulos | |
86 | 8f17dc8f | Leonidas Poulopoulos | |
87 | 8f17dc8f | Leonidas Poulopoulos | stop_workers () { |
88 | 8f17dc8f | Leonidas Poulopoulos | $CELERYD_MULTI stop $CELERYD_NODES --pidfile="$CELERYD_PID_FILE" |
89 | 8f17dc8f | Leonidas Poulopoulos | } |
90 | 8f17dc8f | Leonidas Poulopoulos | |
91 | 8f17dc8f | Leonidas Poulopoulos | |
92 | 8f17dc8f | Leonidas Poulopoulos | start_workers () { |
93 | 8f17dc8f | Leonidas Poulopoulos | $CELERYD_MULTI start $CELERYD_NODES $DAEMON_OPTS \ |
94 | 8f17dc8f | Leonidas Poulopoulos | --pidfile="$CELERYD_PID_FILE" \ |
95 | 8f17dc8f | Leonidas Poulopoulos | --logfile="$CELERYD_LOG_FILE" \ |
96 | 8f17dc8f | Leonidas Poulopoulos | --loglevel="$CELERYD_LOG_LEVEL" \ |
97 | 8f17dc8f | Leonidas Poulopoulos | --cmd="$CELERYD" \ |
98 | 8f17dc8f | Leonidas Poulopoulos | $CELERYD_OPTS |
99 | 8f17dc8f | Leonidas Poulopoulos | } |
100 | 8f17dc8f | Leonidas Poulopoulos | |
101 | 8f17dc8f | Leonidas Poulopoulos | |
102 | 8f17dc8f | Leonidas Poulopoulos | restart_workers () { |
103 | 8f17dc8f | Leonidas Poulopoulos | $CELERYD_MULTI restart $CELERYD_NODES $DAEMON_OPTS \ |
104 | 8f17dc8f | Leonidas Poulopoulos | --pidfile="$CELERYD_PID_FILE" \ |
105 | 8f17dc8f | Leonidas Poulopoulos | --logfile="$CELERYD_LOG_FILE" \ |
106 | 8f17dc8f | Leonidas Poulopoulos | --loglevel="$CELERYD_LOG_LEVEL" \ |
107 | 8f17dc8f | Leonidas Poulopoulos | --cmd="$CELERYD" \ |
108 | 8f17dc8f | Leonidas Poulopoulos | $CELERYD_OPTS |
109 | 8f17dc8f | Leonidas Poulopoulos | } |
110 | 8f17dc8f | Leonidas Poulopoulos | |
111 | 8f17dc8f | Leonidas Poulopoulos | |
112 | 8f17dc8f | Leonidas Poulopoulos | |
113 | 8f17dc8f | Leonidas Poulopoulos | case "$1" in |
114 | 8f17dc8f | Leonidas Poulopoulos | start) |
115 | 8f17dc8f | Leonidas Poulopoulos | check_dev_null |
116 | 8f17dc8f | Leonidas Poulopoulos | start_workers |
117 | 8f17dc8f | Leonidas Poulopoulos | ;; |
118 | 8f17dc8f | Leonidas Poulopoulos | |
119 | 8f17dc8f | Leonidas Poulopoulos | stop) |
120 | 8f17dc8f | Leonidas Poulopoulos | check_dev_null |
121 | 8f17dc8f | Leonidas Poulopoulos | stop_workers |
122 | 8f17dc8f | Leonidas Poulopoulos | ;; |
123 | 8f17dc8f | Leonidas Poulopoulos | |
124 | 8f17dc8f | Leonidas Poulopoulos | reload|force-reload) |
125 | 8f17dc8f | Leonidas Poulopoulos | echo "Use restart" |
126 | 8f17dc8f | Leonidas Poulopoulos | ;; |
127 | 8f17dc8f | Leonidas Poulopoulos | |
128 | 8f17dc8f | Leonidas Poulopoulos | status) |
129 | 8f17dc8f | Leonidas Poulopoulos | $CELERYCTL status $CELERYCTL_OPTS |
130 | 8f17dc8f | Leonidas Poulopoulos | ;; |
131 | 8f17dc8f | Leonidas Poulopoulos | |
132 | 8f17dc8f | Leonidas Poulopoulos | restart) |
133 | 8f17dc8f | Leonidas Poulopoulos | check_dev_null |
134 | 8f17dc8f | Leonidas Poulopoulos | restart_workers |
135 | 8f17dc8f | Leonidas Poulopoulos | ;; |
136 | 8f17dc8f | Leonidas Poulopoulos | |
137 | 8f17dc8f | Leonidas Poulopoulos | try-restart) |
138 | 8f17dc8f | Leonidas Poulopoulos | check_dev_null |
139 | 8f17dc8f | Leonidas Poulopoulos | restart_workers |
140 | 8f17dc8f | Leonidas Poulopoulos | ;; |
141 | 8f17dc8f | Leonidas Poulopoulos | |
142 | 8f17dc8f | Leonidas Poulopoulos | *) |
143 | 8f17dc8f | Leonidas Poulopoulos | echo "Usage: /etc/init.d/celeryd {start|stop|restart|try-restart|kill}" |
144 | 8f17dc8f | Leonidas Poulopoulos | exit 1 |
145 | 8f17dc8f | Leonidas Poulopoulos | ;; |
146 | 8f17dc8f | Leonidas Poulopoulos | esac |
147 | 8f17dc8f | Leonidas Poulopoulos | |
148 | 8f17dc8f | Leonidas Poulopoulos | exit 0 |