diff --git a/README.md b/README.md index ee0a60965..ccc3decc2 100644 --- a/README.md +++ b/README.md @@ -140,12 +140,20 @@ with the broker and backend being RabbitMQ. Both RabitMQ and Celery need to be run as services and set up properly, as described in [Celery](http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html#broker-rabbitmq). On Debian-based machines RabitMQ may be installed as a service directly from repositories. -To run celery worker use following command: +To run celery worker as a script please use the following command: ``` celery -A celery_worker.celery worker ``` +For deployment it should be started as a service. +A major part of configuration will be performed by `setup.sh` automatically but one need to amend configuration file (`celeryd`) so all paths are absolute and correct. +To start the service use `init.d` script: + +``` +/etc/init.d/celeryd {start|stop|restart|status} +``` + ### Serving #### Serving with Werkzeug diff --git a/celeryd b/celeryd new file mode 100644 index 000000000..8852ffaea --- /dev/null +++ b/celeryd @@ -0,0 +1,27 @@ +#CELERYD_LOG_LEVEL="DEBUG" + +# Increase if needed +CELERYD_NODES=1 + +# Please modify following line to use absolute path to celery executable +CELERY_BIN="~/virtual_environment/bin/celery" + +# App instance to use +CELERY_APP="celery_worker.celery" + +# Please modify following line to use absolute path to website directory +CELERYD_CHDIR="~/ActiveDriverDB/website" + +# Extra command-line arguments to the worker +CELERYD_OPTS="--time-limit=5000 --concurrency=8" + +# %n will be replaced with the first part of the node name +CELERYD_LOG_FILE="/var/log/celery/%n%I.log" +CELERYD_PID_FILE="/var/run/celery/%n.pid" + +# Workers should run as an unprivileged user +CELERYD_USER="celery" +CELERYD_GROUP="celery" + +# If enabled pid and log directories will be created if missing +CELERY_CREATE_DIRS=1 \ No newline at end of file diff --git a/setup.sh b/setup.sh index 433849aab..403298861 100644 --- a/setup.sh +++ b/setup.sh @@ -47,4 +47,16 @@ sudo apt-get install rabbitmq-server mkdir -p celery cd celery ssh-keygen -t rsa -f worker.key -N 'Password for testing only' -cd .. \ No newline at end of file +cd .. + +# create celery user +sudo groupadd celery +sudo useradd -g celery celery + +cd website +echo "Please modify /etc/default/celeryd script to provide absolute paths to celery executable and website dir" +sudo cp celeryd /etc/default/celeryd +cd .. + +wget https://raw.githubusercontent.com/celery/celery/3.1/extra/generic-init.d/celeryd +sudo mv celeryd /etc/init.d/celeryd \ No newline at end of file