2

I'm making a simple upstart daemon.

Following the Upstart documentation[1] I make the conf script:

description "Super Daemon" 
author "Bastian Baltasar Bux"

start on started dbus
stop on runlevel [06]

expect fork
exec /usr/bin/my-daemon

The script /usr/bin/my-daemon is a bash that call a python. The python script log information in a /var/log file. On that python script, I only make a fork. But when I check the forks like says in the Upstart doc [2], the method says that I do twice forks.

With that all, the start job is executed correctly, but the pid showed with the upstart my-daemon status isn't the same that is in the log file. The error appears when I try to stop doing status my-daemon stop. That command doesn't end, I must to finish with Crtl-C.

I tried to change the expect fork to expect daemon but service stop doesn't ends neither.

When could be the problem?

[1] http://upstart.ubuntu.com/cookbook

[2] http://upstart.ubuntu.com/cookbook/#id158

4
  • How about sudo stop my-daemon? Jun 11, 2013 at 5:46
  • Doesn't work, neither with initctl stipo my-daemon
    – ssoto
    Jun 11, 2013 at 7:34
  • 1
    Any useful info in /var/log/upstart/my-daemon.log? Why do you need a bash script to call Python script? Jun 11, 2013 at 9:36
  • @schkovich thank for you question. Changing the line exec /usr/bin/my-daemon to exec python $MY_SCRIPT_PATH solve the issue. I think the problem is in the bash scritp that doesn't fork any time.
    – ssoto
    Jun 11, 2013 at 15:36

1 Answer 1

6

I noticed you have already fixed the issue by fixing the exec line. For future readers, let's summarize the issue and the fix.

Issue: Running a forking python from a bash script from Upstart job does not get tracked correctly.

Problem: expect fork or expect daemon does not fix the issue.

Solution: Fix the script. Options:

  • Switch from exec /usr/bin/my-bash-wrapper to directly calling python exec python /path/to/script (as demonstrated in comments above)

  • Fix the bash script. Having a bash script with example contents of

#!/bin/bash

python /path/to/script

has the issue of python getting executed separately from bash with a new process id. Thus it is ignored by Upstart as it is just a command parented by the Bash script. Adding expect daemon does not help as it is ignored in the first place.

Using bash script is possible the same way you fixed it in the Upstart script. Prefixing python call with exec makes the python run with same PID as the bash, which is tracked by Upstart. Then expect fork catches the fork() in the Python script, and Upstart is happily tracking the right process.

So, using a bash wrapper of:

#!/bin/bash

exec python /path/to/script

does the same thing.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .