Bug 737629

Summary: service mongod stop succeeds, but reports a failed service
Product: [Fedora] Fedora Reporter: Chris Lalancette <clalance>
Component: mongodbAssignee: Nathaniel McCallum <nathaniel>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 16CC: clalance, fschwarz, mschmidt, nathaniel
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-02-14 02:06:16 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Chris Lalancette 2011-09-12 18:41:27 UTC
Description of problem:
On a systemd enabled system, "service mongod stop" successfully kills the mongod service.  However, the normal situation for mongod is to exit with a code of 12 when it receives a signal.  This confuses systemd, so that a further "system mongod status" reports the status as failed rather than dead.  This is somewhat odd behavior on the part of mongod, but changing it would be an API break for mongod, so I don't know how much support there would be in upstream mongodb to change this.  I'm hoping there is a way to get systemd to take exit code 12 as "normal", and report it dead.

Comment 1 Chris Lalancette 2011-09-12 18:42:42 UTC
Michal, do you have any insight into the above?  Thanks.

Comment 2 Michal Schmidt 2011-09-13 14:08:29 UTC
(In reply to comment #0)
> Description of problem:
> On a systemd enabled system, "service mongod stop" successfully kills the
> mongod service.  However, the normal situation for mongod is to exit with a
> code of 12 when it receives a signal.

Is this documented somewhere? I found this description of the ways to stop mongod, but there's no mention of the exit code:
http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-Stoppingmongod

> This confuses systemd, so that a further
> "system mongod status" reports the status as failed rather than dead.

Yes, systemd expects the usual UNIX behaviour where EXIT_SUCCESS is 0 and
a non-zero code means a failure/error.

> This is somewhat odd behavior on the part of mongod, but changing it would
> be an API break for mongod

With SysVinit the exit codes of daemons were always lost, because init simply threw them away.
Are there really any users depending on the fact that mongod's clean exit code
is 12?

> so I don't know how much support there would be in upstream mongodb
> to change this.

Please ask them to consider changing it.

> I'm hoping there is a way to get systemd to take exit
> code 12 as "normal", and report it dead.

I don't think there is. systemd can be convinced to ignore failures from the commands it executes, but this does not apply to the exit codes of the forked daemons.
If you believe it is necessary to have a way to specify in a unit file some exit codes as "normal", please file an RFE against systemd.

Comment 3 Chris Lalancette 2011-09-13 14:31:18 UTC
(In reply to comment #2)
> (In reply to comment #0)
> > Description of problem:
> > On a systemd enabled system, "service mongod stop" successfully kills the
> > mongod service.  However, the normal situation for mongod is to exit with a
> > code of 12 when it receives a signal.
> 
> Is this documented somewhere? I found this description of the ways to stop
> mongod, but there's no mention of the exit code:
> http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-Stoppingmongod

I didn't find any documentation about it either.  I noticed it while starting and stopping mongod, and then I looked in the code at pch.h:

        EXIT_KILL = 12 ,

And indeed, the signal handler thread in mongod (db/db.cpp) uses EXIT_KILL when it receives SIGHUP, SIGINT, or SIGTERM.

> 
> > This confuses systemd, so that a further
> > "system mongod status" reports the status as failed rather than dead.
> 
> Yes, systemd expects the usual UNIX behaviour where EXIT_SUCCESS is 0 and
> a non-zero code means a failure/error.
> 
> > This is somewhat odd behavior on the part of mongod, but changing it would
> > be an API break for mongod
> 
> With SysVinit the exit codes of daemons were always lost, because init simply
> threw them away.
> Are there really any users depending on the fact that mongod's clean exit code
> is 12?
> 
> > so I don't know how much support there would be in upstream mongodb
> > to change this.
> 
> Please ask them to consider changing it.

I'll ask upstream and see if they will support this.

> 
> > I'm hoping there is a way to get systemd to take exit
> > code 12 as "normal", and report it dead.
> 
> I don't think there is. systemd can be convinced to ignore failures from the
> commands it executes, but this does not apply to the exit codes of the forked
> daemons.
> If you believe it is necessary to have a way to specify in a unit file some
> exit codes as "normal", please file an RFE against systemd.

OK, if I can't convince upstream to change the exit code, I'll open an RFE.

Thanks for the input.

Comment 4 Fedora Admin XMLRPC Client 2012-02-03 18:49:36 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 5 Nathaniel McCallum 2012-02-03 20:54:52 UTC
Upstream bug: https://jira.mongodb.org/browse/SERVER-4872

Comment 6 Fedora End Of Life 2013-02-14 02:06:21 UTC
Fedora 16 changed to end-of-life (EOL) status on 2013-02-12. Fedora 16 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.