Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using Upstart 1.5 in Ubuntu 12.04 to manage a process created by some user but needs to be managed as system job as starting on boot, respawning if it fails and we been able to start/stop it at any desired time so, I create it's .conf file in /etc/init and is as follows :

description "Start face services recognition and monitors it"
version "1.0"
start on runlevel[5]
stop on runlevel[06]
respawn
expect fork
normal exit 0 TERM STOP
script
exec sh -c /home/verstand/facefeatures
end script
post-stop script
if [ ! $EXIT_STATUS && ! $EXIT_SIGNAL ]
then
exec sudo -u $USER "/sbin/shutdown -r now"  
fi
end script

The signals here are intented to reboot the system in an emergency case where Upstart fails to respawn the process.

Now, the problem is when we start the process it runs fine, with sudo initctl start facefeatures but when we try to stop it, it hangs and we need to use Ctl+C to return tty control. Even more, if we try to start it again or restart it, Upstart reports it's already running: start/running facefeatures but, if we use initctl list Upstart reports as if the process was killed: stop/killed facefeatures

Also, if we reboot the first time it runs the process normally but if we reboot a second time it does it no more...

What is the problem of my conf file? What is the correct way of doing this?

share|improve this question
    
First, you should also post your script. Second, sudo -u $USER is going to return root, so you can just call shtudown without the sudo. –  bodhi.zazen May 31 '13 at 18:13
    
Which script I should also post? facefeatures is not a script, it's a complete c program. –  Kronos May 31 '13 at 18:31
    
from where ? did you write it ? is it working properly ? –  bodhi.zazen May 31 '13 at 18:34
    
Yes, it works properly alone and no, I didn't wrote it, my boss did. –  Kronos May 31 '13 at 18:36
add comment

1 Answer

If facefeatures is not a script, then I believe its a problem of upstart not knowing what process to watch. Do start it with exec and not with script stanza:

description "Start face services recognition and monitors it"
version "1.0"
start on runlevel[5]
stop on runlevel[06]
normal exit 0 TERM STOP
expect fork
respawn
exec /home/verstand/facefeatures
post-stop script
    if [ ! $EXIT_STATUS && ! $EXIT_SIGNAL ]
    then
        exec sudo -u $USER "/sbin/shutdown -r now"  
    fi
end script

When stopping the service your programm will receive a TERM, if it does no react on that signal it will get killed after five seconds.

share|improve this answer
    
You may want to add some information about 'expect fork' which you removed. If facefeatures forks and detaches, it may still be needed. –  SpamapS May 31 '13 at 22:52
    
Yeah, tombert's point is a doubt arising...why removing the respawn and expect fork stanzas? I was reading a post in a blog I fail to remember to use expect daemon instead of expect fork –  Kronos Jun 1 '13 at 5:08
    
I removed expect fork because Kronos said that facefeatures is a self written program. So I assumed the simplest case that this program does not daemonize. But I will change my comment, you might be right that I simplified too much. –  tombert Jun 1 '13 at 16:25
    
No no, it's not a reclaim, I'm just trying to understand Upstart. facefeatures does not daemonize itself but I need it to, so it can be run in the background. So expect fork waits the process it monitors to fork itself? So what does expect daemon does? –  Kronos Jun 1 '13 at 23:03
    
expect fork monitors the process if it forks (see man page) a child process. The PID of the child process then is the main process for upstart to watch. If this PID dies then upstart respawns your program. Generally there is no need that facefeatures daemonizes itself when running from upstart because it will automatically run in background. For more details on upstart you might want to have a look here upstart.ubuntu.com/cookbook/#expect. –  tombert Jun 2 '13 at 7:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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