Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a daemon in /opt/xyz/bin/xyz. Unfortunately it cannot fork itself into background and will not be able to do so within the next half year. My problem is the following: Entering

service xyz start

just returns

xyz start/running, process 23484

Always, even when it immediately exits with exit code 1. My config is this:

$ cat /etc/init/xyz.conf
description "XYZ"

start on started networking
stop on shutdown

exec /opt/xyz/bin/xyz

The rest works fine. Upstart recognizes when the process is already started, stopping works fine too.

Any suggestions?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You need a post-start stanza which will query the service as to whether or not it is providing whatever service it is expected to be running. So something like

post-start script
  for try in 1 2 3 4 5 ; do
    if xyzadmin --ping ; then
      exit 0
    fi
    sleep 1
  done
  logger -t xyz-upstart -p daemon.err "failed to start within $try seconds, aborting"
  exit 1
end script

When adding the ability to daemonize your service, if at all possible, make sure that it does not fork until it is ready to handle requests, then 'expect fork' will delay the 'started' condition properly, otherwise you will still need this post-start.

share|improve this answer
    
Great trick, thank you! –  user694971 Jan 17 '12 at 9:18
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.