1

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.

brandeded
  • 1,845
  • 8
  • 32
  • 50
  • 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. – brandeded Oct 27 '11 at 15:54
  • To note: it's not a python error. The global variable is established when the code is called within the proper virtualenv, which is clearly the case from any of the working methods I've noted: from terminal/CLI, from another bash script, even running the init script itself. **Only when using `service` does paste fail with this error.** – brandeded Oct 27 '11 at 15:59
  • 1
    Post the output of `sh -x /etc/init.d/celerydsvcname start` and content of `/sbin/service`? – quanta Oct 27 '11 at 16:11
  • Thanks for following up quanta... see: http://pastebin.com/z5riDngR Note that I can run the `/etc/init.d/celerydsvcname` within bash without a problem, it launches: http://pastebin.com/uhvbmvkx – brandeded Oct 27 '11 at 16:18
  • 1
    You lack of `start`. – quanta Oct 27 '11 at 16:19
  • Sorry done: http://pastebin.com/uhvbmvkx – brandeded Oct 27 '11 at 16:23
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/1666/discussion-between-mbrownnyc-and-quanta) if you'd like... – brandeded Oct 27 '11 at 16:23
  • 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 00:35

1 Answers1

0

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

export HOME=/home/ak

to the init.d script.

splattne
  • 28,508
  • 20
  • 98
  • 148
akks
  • 9
  • 2
  • 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. – brandeded Oct 31 '11 at 12:45