1

I running mongodb instance from bash scripts and I need to show user-friendly message if mogngo will crash during startup for some reason.

so I have that sort of code

eval 'mongod --dbpath=$ABS_MONGO_DATA_PATH &' || printf "something bad happened"

but with that sort of notation error handler never called. But if I remove & sing, then after mongo initialization further script do not running because of mongod process waiting for a signals

How could I resolve that issue?

silent_coder
  • 6,222
  • 14
  • 47
  • 91
  • Looks very similar to [this](http://stackoverflow.com/questions/1570262/shell-get-exit-code-of-background-process) – John C May 16 '14 at 00:16

1 Answers1

1

You don't need eval for this:

{ mongod --dbpath="$ABS_MONGO_DATA_PATH" ||
   printf "something bad happened"; } &

Instead of just running mongod in the background, run the entire command list in the background.

chepner
  • 497,756
  • 71
  • 530
  • 681