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?


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
    sleep 1
  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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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