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==', 'console_scripts', 'paster')()
  File "/var/www/rhodecode-venv/lib/python2.6/site-packages/PasteScript-", 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

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?




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.

  • 1
    I saw the undefine error with RepositoryError variable. Try to redirect both of stdout and stderr to a log file: /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
  • Thanks. I previously used ../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:54
  • 1
    Post the output of sh -x /etc/init.d/celerydsvcname start and content of /sbin/service?
    – quanta
    Oct 27 '11 at 16:11
  • 1
    You lack of start.
    – quanta
    Oct 27 '11 at 16:19
  • 1
    Change the "shelbang" of your init script to #!/bin/sh -x and show us the output of sh -x /sbin/service paste-script-celeryd start
    – quanta
    Oct 28 '11 at 0:35

I have solved problem with rhodecode - init.d by adding

export HOME=/home/ak

to the init.d script.

  • This is obviously what I did, but it seem like quite a bad thing to do? I guess may be not since it's just an adjustment of the environment where the process is running.
    – mbrownnyc
    Oct 31 '11 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.