-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_worker.sh
executable file
·55 lines (49 loc) · 1.36 KB
/
run_worker.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
EXPECTED_ARGS=2
E_BADARGS=65
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` <deploy target> <projectname> [num workers]"
echo "Run a celery server for the app in /home/newsapps/sites/projectname."
exit $E_BADARGS
fi
TARGET=$1
PROJECT=$2
WORKERS=${3:-'2'}
SITE=${4:-''}
USE_ACCOUNT=www-data
ROOT=/home/newsapps/sites/$PROJECT
VIRTUAL_ENV=/home/newsapps/.virtualenvs/$PROJECT
ERROR_LOG=/home/newsapps/logs/$PROJECT.error.log
WORKER_ERROR_LOG=/home/newsapps/logs/$PROJECT-worker.error.log
SECRETS=/home/newsapps/sites/secrets/${TARGET}_secrets.sh
SENDGRID=/home/newsapps/sites/secrets/sendgrid_secrets.sh
HOSTNAME=${PROJECT}.`hostname`
if [ -f $ROOT/application.py ]
then
CELERY="celery worker --hostname=${HOSTNAME}"
else
if [ -d $ROOT/$PROJECT/settings ]
then
if [ -z "$SITE" ]
then
export DJANGO_SETTINGS_MODULE=$PROJECT.settings.${TARGET}
else
export DJANGO_SETTINGS_MODULE=$PROJECT.settings.${SITE}_${TARGET}
HOSTNAME=${SITE}.${HOSTNAME}
fi
else
export DJANGO_SETTINGS_MODULE=$PROJECT.${TARGET}_settings
fi
CELERY="$ROOT/manage.py celery worker --hostname=${HOSTNAME}"
fi
if [ -f $SECRETS ]
then
. $SECRETS
. $SENDGRID
fi
. $VIRTUAL_ENV/bin/activate
cd $ROOT
exec chpst -u $USE_ACCOUNT $CELERY \
--concurrency=$WORKERS --pool=gevent --logfile=$WORKER_ERROR_LOG \
--events --maxtasksperchild=100