0

I am trying to get an init script running that starts nodejs as a daemon. The problem is, that when I executing start-stop-daemon it always returns '0', regardless of what error the nodejs-daemon may return.

I got as far as figuring out that the issue arises when using start-stop-daemon with the --background switch.

With the switch, start-stop-daemon always returns '0', even when the nodejs-daemon fails.

root# start-stop-daemon --start --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --make-pidfile --pidfile $PIDFILE --exec $DAEMON  --background -- $DAEMON_ARGS ; echo ---error: $?
---error: 0

Note, that the daemon silently failed and is NOT running at this moment!

Without the switch, we can actually see the daemon failing to start.

root# start-stop-daemon --start --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --make-pidfile --pidfile $PIDFILE --exec $DAEMON  -- $DAEMON_ARGS ; echo ---error: $?
ERROR: Unsupported version of Node
Ghost needs Node version ~0.10.0 || ~0.12.0 || ^4.2.0 you are using version 5.10.0

Please see http://support.ghost.org/supported-node-versions/ for more information
---error: 231

Now I am looking to find a solution so I can use the --background switch and having a error code bigger than '0' when it fails to start the nodejs daemon.

  • I am not familiar with nodejs. Can you tell me if the start-stop-daemon is a script or an LSB executable ? You can run file $(which start-stop-daemon) to see what type of file it is, if unsure. – MelBurslan Apr 5 '16 at 21:17
  • "/sbin/start-stop-daemon: ELF 64-bit LSB executable […]". That is used in every init-script on Debian, by the way. – Hurrdurrfurr Apr 5 '16 at 21:21
  • Then why don't you first run this command without the --background switch, send stdout to /dev/null get the error code. If it is zero, the stop it and start it with the --background switch. Yes it is a convoluted way of doing it but obviously this executable is not handling the error condition properly in background mode. Also you can submit a bug report to the developers of this app. – MelBurslan Apr 5 '16 at 21:29
2

This is documented behavior. The foreground process completes after forking the background process. From the man page:

-b, --background
          Typically used with programs that don't detach on their own. This option will force start-stop-daemon to fork before starting the process, and  force
          it  into  the  background.   Warning:  start-stop-daemon  cannot check the exit status if the process fails to execute for any reason. This is a last
          resort, and is only meant for programs that either make no sense forking on their own, or where it's not feasible to add the code for them to do this
          themselves.
0

we found that after a file system issue some of the mongo files ended up being owned by root. For this particular issue it was the journal files. Change all of these back to mongodb:mongodb with chown mongodb:mongodb * in the db/journal directory. Also important to delete the mongod.lock file in the db directory. What was also a little wierd was that removing the --background option in the start_stop_deamon worked but of course you want it to run in the background

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.