I am curious, is there something I need to watch out for when spawning process as background jobs from init scripts using service?
Here is the line that works at terminal, in a bash script/an init script, but will not successfully launch when using chkconfig: service celerydsvcname start
/var/www/rhodecode-venv/bin/paster celeryd /var/www/rhodecode/production.ini --pidfile=/var/run/celeryd.pid -f /var/log/celerydpaster.log -l WARNING -q &
Some interesting troubleshooting I've done:
cd /var/www/rhodecode-venv/bin
/var/www/rhodecode-venv/bin/paster celeryd /var/www/rhodecode/production.ini --pidfile=/var/run/celeryd.pid -f /var/log/celerydpaster.log -l WARNING -q &
sleep 2
ls -l /proc/$(pgrep paste)/cwd
echo Done.
I get the following returned:
Traceback (most recent call last):
File "/var/www/rhodecode-venv/bin/paster", line 8, in <module>
load_entry_point('PasteScript==1.7.4.2', 'console_scripts', 'paster')()
File "/var/www/rhodecode-venv/lib/python2.6/site-packages/PasteScript-1.7.4.2-py2.6.egg/paste/script/command.py", line 103, in run
command = commands[command_name].load()
File "build/bdist.linux-i686/egg/pkg_resources.py", line 1954, in load
File "/var/www/rhodecode-venv/lib/python2.6/site-packages/RhodeCode-1.2.2-py2.6.egg/rhodecode/__init__.py", line 39, in <module>
_rev = get_current_revision(quiet=True)
File "/var/www/rhodecode-venv/lib/python2.6/site-packages/RhodeCode-1.2.2-py2.6.egg/rhodecode/lib/__init__.py", line 403, in get_current_revision
except (ImportError, RepositoryError, VCSError), err:
UnboundLocalError: local variable 'RepositoryError' referenced before assignment
lrwxrwxrwx. 1 root root 0 Oct 27 11:34 /proc/12265/cwd -> /var/www/rhodecode-venv/bin
Done.
The python error is logged because the working directory is incorrect; but it is reported as correct by ls -l /proc/$(pgrep paste)/cwd!
Again, note that /var/www/rhodecode-venv/bin/paster celeryd /var/www/rhodecode/production.ini --pidfile=/var/run/celeryd.pid -f /var/log/celerydpaster.log -l WARNING -q & runs without issue from the terminal and a bash script, or even if I execute the init script from the terminal. It is only when I use service celerydsvcname start that I run into this working directory issue.
It doesn't matter whether or not the process is spawned (via service) in the foreground or background, the issue is persistent.
How is the process context changed when running using service to execute the init script?
Thanks!
Matt
[updated]
The script is referring to the HOME environmental variable for which. service starts the service as env -i PATH="$PATH" TERM="$TERM" "/etc/init.d/celerydsvcname" start, where -i ignores the current environment. This means that I can't expect environmental variables to be present in the environment that's started with service, unless I set them. Lesson learned.
/var/www/rhodecode-venv/bin/paster ... -q > /tmp/paster.log 2>&1 &to see what does it say. – quanta Oct 27 '11 at 15:49../paster ... -q &> logfile.log. But redirected both using your syntax as well and the only thing logged is the above error contents from python. Also note I changed the question a bit to reflect that the fact that I'm spawning the process in the background is irrelevant to the issue. – mbrownnyc Oct 27 '11 at 15:54sh -x /etc/init.d/celerydsvcname startand content of/sbin/service? – quanta Oct 27 '11 at 16:11start. – quanta Oct 27 '11 at 16:19#!/bin/sh -xand show us the output ofsh -x /sbin/service paste-script-celeryd start– quanta Oct 28 '11 at 0:35