0

I am trying to daemonize celery and celerybeat. I have downloaded the celeryd and celeybeat files from github and placed them in /etc/init.d/ (celery and celerybeat) with the corresponding config files under /etc/default/.

My problem is that when I run these two files, celeryd and celerybeat use system python (2.4), and as a result cannot find other installed applications under python 2.7. Python 2.7 is in ~/.bashrc and /.bash_profile files, so I do not have any problems running other applications, except when workers fail to work. When I run python ...../manage.py celery ( with all options) everything works like a charm.

Please let me know how I can force /init.d/function to run python2.7.

I have tried to implement #! /bin/sh python, but it does not work.

fvrghl
  • 3,642
  • 5
  • 28
  • 36
Reza
  • 1
  • 2

1 Answers1

0

scripts in /etc/init.d are usually run as root on system startup. root's ~/.bashrc (that is /root/.bashrc) will look totally different from yours (e.g. /home/reza/.bashrc). your shell will behave slightly differently if you are running it interactively or not.

hence there is no use in trying to run the python interpreter through /bin/sh, it only adds overhead.

what you want is to add a proper shebang that tells the system which interpreter to use for your script.

e.g.

#!/usr/bin/python2.7

will use the python2.7 binary installed in /usr/bin. (so whenever you run /etc/init.d/foo.py the system really runs /usr/bin/python2.7 /etc/init.d/foo.py)

umläute
  • 28,885
  • 9
  • 68
  • 122