I have a init script which is poorly designed because it does not conform to the Linux Standard Base Specifications
The following should have an exit code of 0 if running, and 3 if not running
service foo status; echo $?
However because of the way the script is designed, it always returns a 0. I can not fix the script without a significant rewrite (because service foo restart is dependent on service foo status).
How could you work around the issue so that service foo status
returns a 0 if running, and a 3 if not running?
What I have so far:
root@foo:/vagrant# service foo start
root@foo:/vagrant# /etc/init.d/foo status | /bin/grep "up and running"|wc -l
1
root@foo:/vagrant# /etc/init.d/foo status | /bin/grep "up and running"|wc -l;echo $?
0 # <looks good so far
root@foo:/vagrant# service foo stop
root@foo:/vagrant# /etc/init.d/foo status | /bin/grep "up and running"|wc -l
0
root@foo:/vagrant# /etc/init.d/foo status | /bin/grep "up and running"|wc -l;echo $?
0 # <I need this to be a 3, not a 0