echocat/puppet-mongodb — pull request #22 by parkan (2013-11-19 22:13:21+00:00)
Title: Reuse mongod lockfile as pidfile. Fixes "change from stopped to running failed" after initial install

The module uses both mongodb's builtin pidfile writing mechanism (--pidfilepath) and start-stop-daemon's --make-pidfile, in addition to the pid already written to the mongo lockfile. This appears to result in an incorrect pid written to the pidfile during initial install (i.e. `puppet agent --test ...`)

This results in the following error (process is already running but we don't see it in `status` due to wrong pid, can't `start` again because lockfile exists):

```
Debug: /Stage[main]/Mongodb/File[/etc/init.d/mongodb]: The container Class[Mongodb] will propagate my refresh event
Debug: Class[Mongodb::Install]: The container Stage[main] will propagate my refresh event
Notice: /Stage[main]//Node[n10]/Mongodb::Mongod[test]/File[/etc/init.d/mongod_test]/ensure: defined content as '{md5}3cad35a4e47bcafa3c1d75f5f0fa1c87'
Debug: /Stage[main]//Node[n10]/Mongodb::Mongod[test]/File[/etc/init.d/mongod_test]: The container Mongodb::Mongod[test] will propagate my refresh event
Notice: /Stage[main]//Node[n10]/Mongodb::Mongod[test]/File[/etc/mongod_test.conf]/ensure: defined content as '{md5}e2ba8d5bfa72cb080deb1c40523b33f7'
Debug: /Stage[main]//Node[n10]/Mongodb::Mongod[test]/File[/etc/mongod_test.conf]: The container Mongodb::Mongod[test] will propagate my refresh event
Debug: Service[mongod_test](provider=upstart): Could not find mongod_test.conf in /etc/init
Debug: Service[mongod_test](provider=upstart): Could not find mongod_test.conf in /etc/init.d
Debug: Service[mongod_test](provider=upstart): Could not find mongod_test in /etc/init
Debug: Executing '/etc/init.d/mongod_test status'
Debug: Executing '/etc/init.d/mongod_test start'
Error: Could not start Service[mongod_test]: Execution of '/etc/init.d/mongod_test start' returned 1:
Error: /Stage[main]//Node[n10]/Mongodb::Mongod[test]/Service[mongod_test]/ensure: change from stopped to running failed: Could not start Service[mongod_test]: Execution of '/etc/init.d/mongod_craw ler_2 start' returned 1:
...
Debug: Class[Mongodb::Logrotate]: The container Stage[main] will propagate my refresh event
Notice: /Stage[main]/Mongodb/Anchor[mongodb::end]: Dependency Service[mongod_test] has failures: true
Warning: /Stage[main]/Mongodb/Anchor[mongodb::end]: Skipping because of failed dependencies
```

start/status/stop also will not work until the created process is killed manually

This doesn't seem to happen 100% of the time, but it did happen on a majority of my machines, both with preexisting mongo installs and fresh.

Instead, we can just reuse the lockfile, which contains the pid, and avoid creating one with start-stop-daemon. This appears to resolve the issue.