Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7254

Mongo init.d scripts not working on ubuntu

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.0.7, 2.4.5
    • Fix Version/s: None
    • Component/s: Packaging
    • Labels:
      None
    • Environment:
      ubuntu 11.10
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      Linux

      Description

      Hi,

      I installed mongodb20-10gen and it installs fine and starts the service but the problem I am seeing is after it is installed the init.d/mongodb service script seems some what broken. The status script returns a fail even though the service is running. After investigating it seems something is storing the wrong pid in the pidfile causing the status to not work correctly. This also breaks the "stop" command. Updating the pidfile with the correct pid after doing a "ps aux" fixes things but this is not an ideal solution. It may be because something is being forked that the pid is being stored at the wrong time. Let me know if you need any other information. Please investigate.

      Thanks,
      Jay

        Issue Links

          Activity

          Hide
          bchecketts Brandon Checketts added a comment -

          This is what I have that is working. It has been a while since I installed these (package is mongodb-10gen v2.4.3)

          init file (/etc/init.d/mongod_data_d)
          http://pastebin.com/pqSsqvTF

          Config File: (/etc/mongod_data_d.conf)
          http://pastebin.com/7di4SVmC

          Show
          bchecketts Brandon Checketts added a comment - This is what I have that is working. It has been a while since I installed these (package is mongodb-10gen v2.4.3) init file (/etc/init.d/mongod_data_d) http://pastebin.com/pqSsqvTF Config File: (/etc/mongod_data_d.conf) http://pastebin.com/7di4SVmC
          Hide
          ernie.hershey Ernie Hershey added a comment -

          Brandon Checketts, Daniel Taschik, bg - do you need fork=true for some reason? Our Debian init script and Ubuntu upstart configurations assume that the mongod daemon will not be forking when started by them.

          In Upstart -
          "If you do not specify the expect stanza, Upstart will track the life cycle of the first PID that it executes in the exec or script stanzas. "
          http://upstart.ubuntu.com/cookbook/#expect

          In Debian with sysvinit, we pass --background and --make-pidfile to start-stop-daemon in the init script, indicating that it should manage the pid file and expect the child program (mongod) not to fork on its own.
          http://www.unix.com/man-page/Linux/8/start-stop-daemon/

          Show
          ernie.hershey Ernie Hershey added a comment - Brandon Checketts , Daniel Taschik , bg - do you need fork=true for some reason? Our Debian init script and Ubuntu upstart configurations assume that the mongod daemon will not be forking when started by them. In Upstart - "If you do not specify the expect stanza, Upstart will track the life cycle of the first PID that it executes in the exec or script stanzas. " http://upstart.ubuntu.com/cookbook/#expect In Debian with sysvinit, we pass --background and --make-pidfile to start-stop-daemon in the init script, indicating that it should manage the pid file and expect the child program (mongod) not to fork on its own. http://www.unix.com/man-page/Linux/8/start-stop-daemon/
          Hide
          sosh bg added a comment -

          @Ernie Hershey - The docs make this sound like the default setting:

          <quote>
          fork is true, which enables a daemon mode for mongod, which detaches (i.e. “forks”) the MongoDB from the current session and allows you to run the database as a conventional server.
          </quote>

          Show
          sosh bg added a comment - @Ernie Hershey - The docs make this sound like the default setting: <quote> fork is true, which enables a daemon mode for mongod, which detaches (i.e. “forks”) the MongoDB from the current session and allows you to run the database as a conventional server. </quote>
          Hide
          bchecketts Brandon Checketts added a comment -

          The actual code for it is in mongo/src/mongo/db/initialize_server_global_state.cpp (https://github.com/mongodb/mongo/blob/5ea897e30b45447d55289e33f636da3017b1e8db/src/mongo/db/initialize_server_global_state.cpp)

          The forkServer() function begins at line #92 and actually forks twice. Which I think is why Upstart is unable to track the PID to the eventual child process since you mentioned that upstart only tracks the first PID respawned.

          Somebody familiar with the actual mongo code would need to explain why it needs to fork twice. After the first fork it calls setsid() and chdir, and after the second fork it assigns stdin, stdout, and stderr to /dev/null.

          Show
          bchecketts Brandon Checketts added a comment - The actual code for it is in mongo/src/mongo/db/initialize_server_global_state.cpp ( https://github.com/mongodb/mongo/blob/5ea897e30b45447d55289e33f636da3017b1e8db/src/mongo/db/initialize_server_global_state.cpp ) The forkServer() function begins at line #92 and actually forks twice. Which I think is why Upstart is unable to track the PID to the eventual child process since you mentioned that upstart only tracks the first PID respawned. Somebody familiar with the actual mongo code would need to explain why it needs to fork twice. After the first fork it calls setsid() and chdir , and after the second fork it assigns stdin, stdout, and stderr to /dev/null.
          Hide
          ernie.hershey Ernie Hershey added a comment -

          Thanks! The default is fork=false. We should make that more clear in the docs. I opened DOCS-2869 to address that.

          If you require fork=true in upstart, "expect daemon" will work.

          In debian or with sysvinit, using a configuration like Brandon posted should work, in which mongod forks and creates its own pidfile instead of start-stop-daemon creating the pidfile.

          The init script and configuration in our .deb packages will also work, in which mongod doesn't fork itself and start-stop-daemon is able to track the pidfile itself.

          Show
          ernie.hershey Ernie Hershey added a comment - Thanks! The default is fork=false. We should make that more clear in the docs. I opened DOCS-2869 to address that. If you require fork=true in upstart, "expect daemon" will work. In debian or with sysvinit, using a configuration like Brandon posted should work, in which mongod forks and creates its own pidfile instead of start-stop-daemon creating the pidfile. The init script and configuration in our .deb packages will also work, in which mongod doesn't fork itself and start-stop-daemon is able to track the pidfile itself.

            People

            • Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: