title: Celery as a service with Django
body: <p>I'm trying to use Celery in my Django project. and as usual, I googled stuff, read few SOF questions regarding the same, few blogs, and of course official docs.</p>
  
  <p>but its very confusing when it comes to run celery as a service in django. I didn't find any source for this.</p>
  
  <p>A simple django project with one App. in this App folder there is a file <code>tasks.py</code>  where all my tasks are(for now its a single task).</p>
  
  <p><strong>tasks.py</strong></p>
  
  <pre><code>from celery.task.schedules import crontab  
  from celery.decorators import periodic_task 
  
  @periodic_task(run_every=crontab(minute="*/45"))
  def mytask():
      #some stuff to do
      ...
      # return a value
  </code></pre>
  
  <p>and these are my settings configurations</p>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  import djcelery
  
  djcelery.setup_loader()
  
  BROKER_URL = "amqp://user:user@localhost:5672/vhost"
  CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
  CELERY_BEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
  </code></pre>
  
  <p><code>'djcelery'</code> added to INSTALLED_APS</p>
  
  <p>Now If I want to run Celery worker I have to use this command in screen/tmux</p>
  
  <p><code>python manage.py celeryd --verbosity=2 --loglevel=DEBUG -B</code> </p>
  
  <p>or </p>
  
  <p><code>python manage.py celeryd --verbosity=2 --loglevel=DEBUG &amp;</code></p>
  
  <p>I want to know if its possible to run it is as a service like we run nginx, uwsgi, mysql, etc. I dont want to run in daemon mode. How can I do this?</p>
  
  <p>The main this I just want to do <code>sudo service celery restart/reload/stop/start</code> like</p>
  
  <p>PS: As I said, I had read few SOF threads, and many of them are saying that dont use <code>crontab</code>. then what should I use? Is this a security concern?</p>