2

I am maintaining an Upstart script (version 0.6.5) and in the pre-start script, there's a test to terminate the service if a precondition is not met:

pre-start script
  if [ ! -f $REQUIRED_FILE ]; then
    echo "$REQUIRED_FILE does not exit" >> $LOG_FILE
    stop 
    exit 1
  fi
end script

According to the csh/tcsh reference documentation, stop [jobIDs]:

suspend[s] the current background jobs or the background jobs specified by jobIDs; this is the complement of Ctrl-Z or suspend.

I don't see any use for stop here, especially in the pre-start section wherein the service has not started yet (i.e. by the exec stanza).

Am I missing something here? Or is stop here redundant and unnecessary?

Behrang
  • 289
  • 2
  • 3
  • 10

1 Answers1

1

Using stop inside of a job is equivalent to calling sudo stop <job-name>. This would be used if you wanted to disable the respawn-ing of a job.

The upstart documentation on the pre-start stanza has an example that explains this usage:

http://upstart.ubuntu.com/cookbook/#pre-start

Another possibility is to cancel the start of the job for some reason. One good reason is that it's clear from the system configuration that a service is not needed:

pre-start script
  if ! grep -q 'parent=foo' /etc/bar.conf ; then
    stop ; exit 0
  fi
end script
grimetime
  • 143
  • 6