I've been working around with Python & Django Framework for a while with Ubuntu 16.01. Since I used Django with Q system (Celery) and some others Enhancement Apps. When I try to run all the apps each time, I need to run development server "{python manage.py runserver}", then running Celery Worker "{celery -A filename worker -l info}". Each time I working, it takes me minutes to enter the directory and start it up. I surf around and come up with the idea of setup it as service. Example, service name: "pyd". I just need to run "{sudo pyd start}" -> then Django Development Server and Celery will start, and if I run "{sudo pyd stop}" -> then Django & Celery will stop.
I try to search around, and things start to confuse me between "Upstart" and "Systemd".
Could any one suggest, me how to make both Django and Celery as Service run in Ubuntu ? between "Upstart" & "Systemd" which one is better ??
Source code to indicate sample is appreciated.
Thank
You can use Upstart to do this.
Post installation, go to the directory
/etc/init/
. Create a filexyz.conf
and add the lines:If you are using a virtualenv, add the following lines before the above:
Now, you can start Django Dev Server and Celery as a service by issuing the commands,
sudo start xyz
, stop it by issuingsudo stop xyz
and check status of your service by issuingsudo status xyz
.xyz.conf
will log into/var/log/upstart/xyz.log
. You can view logs with the following command:sudo tail -f /var/log/upstart/xyz.log
.You can setup celery as daemon service, follow the below steps
Step 1: celery init script
Copy this script file in the directory /etc/init.d/celeryd (celeryd will be the service name, you can name it anything)
The instruction to set this up is given in the above source.
Step 2: Setting up celery configuration
Now configure celery configuration in this file /etc/default/celeryd, this example will give you a generic configuration file.
Now you can run celery as service with following commands
or any other service commands.