init: pre-stop not run when no main process

Bug #252996 reported by Scott James Remnant (Canonical)
36
This bug affects 7 people
Affects Status Importance Assigned to Milestone
upstart
Triaged
Low
Unassigned

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
Revision history for this message
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" ?

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

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
Revision history for this message
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.

Revision history for this message
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;
        default:
            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.

Revision history for this message
Tomer Chachamu (r3m0t) wrote :

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

script
    # we need this section so that pre-stop gets run!
    # https://bugs.launchpad.net/upstart/+bug/252996
    while true
        do sleep 1d
    done
end script

Revision history for this message
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)
information type: Public → Public Security
information type: Public Security → Public
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.