init: pre-stop not run when no main process

Bug #252996 reported by Scott James Remnant (Canonical) on 2008-07-29
This bug affects 7 people
Affects Status Importance Assigned to Milestone

Bug Description

The check for whether to run pre-stop relies on there being a main process defined, which is arguably a bug. We really care about the reason we were stopped.

Changed in upstart:
importance: Undecided → Low
status: New → Confirmed
Changed in upstart:
milestone: none → 0.10
keesj (keesj) wrote :

I don't understand the comments. Overall I agree that pre-stop should only run to "stop" the process.
but what is the relation with the "stop reason" ?

As in pre-stop should be run if the reason for the stop is a manual command or event.

Whereas right now the pre-stop should be run if there is a main process pid ;)

Changed in upstart:
milestone: 0.10 → none
summary: - pre-stop not run when no main process
+ init: pre-stop not run when no main process
Changed in upstart:
status: Confirmed → Triaged
Numérigraphe (numerigraphe) wrote :

If this is not fixed yet, then it's a problem for "state" jobs that have no PID at all (no exec or script stanza).
Lionel Sausin.

Clint Byrum (clint-fewbar) wrote :

Numerigraphe, it still seems to be the case.

Its somewhat confusing in job_next_state why so much trouble is taken to skip to JOB_STOPPING if there is no main process:

    case JOB_RUNNING:
        switch (job->goal) {
        case JOB_STOP:
            if (job->class->process[PROCESS_MAIN]
                && (job->pid[PROCESS_MAIN] > 0)) {
                return JOB_PRE_STOP;
            } else {
                return JOB_STOPPING;
        case JOB_START:
            return JOB_STOPPING;
            nih_assert_not_reached ();

Seems it would be simpler to just go to pre-stop no matter what. I'm sure there's a good reason for this though.

Tomer Chachamu (r3m0t) wrote :

If you are suffering this, you can add this to your job configuration:

    # we need this section so that pre-stop gets run!
    while true
        do sleep 1d
end script

Martin Stjernholm (msub) wrote :

If this is intended behavior, then the man page for init(5) should make it more clear that pre-stop aren't always run.

Timur Irmatov (irmatov) on 2014-06-23
information type: Public → Public Security
information type: Public Security → Public
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers