A server has nginx falling over frequently and needs to have a sude service nginx restart executed.
A suggestion has been the following bash script:
service nginx status | grep 'active (running)' > /dev/null 2>&1
if [ $? != 0 ]
then
sudo service nginx restart > /dev/null
fi
Being thoroughly unversed in bash, there are two propositions that are opaque to me and require clarification:
> /dev/null 2>&1
and
[ $? != 0 ]
Because the response to service nginx status returns a clear statement:
Active: failed (Result ... and thus I would intuitively devise the if statement to focus on failed ...