Having a script where I start/stop various services depending on what I need. For example Apache, BIND, MySQL, PostFix, Memcached, Tomcat, ... and so on.
Depending on status options to script etc. various actions are taken.
For most this works fine: (example with Apache)
if service apache2 status >/dev/null; then # ... do some action fi
For others one have to use other tricks like
However I'm not able to find any good way to check status for
service mongodb status
It has the same "sickness" as MySQL and yield
mongodb stop/waiting and also evaluates to true, even if service is not up and running.
Have looked at
mongostat etc. but not found any option for this.
One way could be to use
ps or perhaps better
netstat and combine either with
grep or the like, but wondering if there is a better (more native/targeted) way to check status. Could also grep for
stop/waiting, but not sure how reliable this is, and guess it could likely break in a future upgrade.