respawn on script and exec

Asked by dyuen on 2010-10-20

Hi,

I have created a working job config file as follow:

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn

# a C program loop infinitely that do nothing
exec /some/program/infiniteLoop.exe

normal exit 0

When I issue command kill 9 [infiniteLoop.exe pid] it is killed and respawn the inifiniteLoop.exe as it should. I then use this as an example config to make my daemon that required to start at a certain directory so I modified the config as follow:

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
expect daemon

script
       cd /path/to/my/daemon/written/in/C/
       sudo -u specificUser ./Daemon.exe --arg1 --arg2
end script

normal exit 0

The config can start and stop the job automatically and manually, but when I issue kill 9 [Daemon.exe pid], the daemon is killed without respawn. Am I doing something wrong? The reason I used script instead of exec is that exec started the process from root directory, is it possible to cd to the directory and then perform exec?

Question information

Language:
English Edit question
Status:
Solved
For:
upstart Edit question
Assignee:
No assignee Edit question
Solved by:
dyuen
Solved:
2010-10-23
Last query:
2010-10-23
Last reply:

This question was reopened

dyuen (daniellyyuen) said : #1

I wasn't sure what causing this problem, but after updated Linux resolved the problem.

dyuen (daniellyyuen) said : #2

I wasn't sure what causing this problem, but after updated Linux resolved the problem.

dyuen (daniellyyuen) said : #3

Found out the reason it worked. It is more weired than the description above, commented out expect daemon stanza will made it work on ubuntu 10.04 X86_64. So I tried to test if it is actually work for daemon, I used the sample daemon code from http://www.enderunix.org/documents/eng/daemon.php

and again it does not work when there is "expect daemon" or "expect fork" in the exampled.conf file, but worked without any of two stanza.

daniel@daniel-laptop:~$ ps -e | grep exampled
 1449 ? 00:00:00 exampled
daniel@daniel-laptop:~$ sudo kill -9 1449
daniel@daniel-laptop:~$ ps -e | grep exampled
 2472 ? 00:00:00 exampled
daniel@daniel-laptop:~$ ps -ef | grep exampled
root 2472 1 0 13:28 ? 00:00:00 /home/daniel/test/exampled
daniel 2518 1358 0 13:32 pts/0 00:00:00 grep --color=auto exampled

Since the ppid is 1, it is worked as a daemon, but why wouldn't it take "expect daemon" stanza? Will later version of Upstart have this feature? Or did I do something wrong?

here is the exampled.conf file :

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

#respawn
#expect daemon
#expect fork
respawn

pre-start script
        echo "startin example" >> /tmp/upstart.log 2>&1
end script

# cd /home/daniel/test
#script
        exec /home/daniel/test/exampled
#end script

normal exit 0

dyuen (daniellyyuen) said : #4

Found the reason, it was because the daemon only fork once; therefore, expect fork instead of expect daemon