How to find out if a service is running with bash script

  • 0
I wrote a simple bash script which checks for a service or process whether is running or not and does specific actions (reload, send E-Mail) if there is no such process running.
I have tried the script on Ubuntu server but it should work for all Linux distributions as well as Unix (e.g Mac OS X, FreeBSD etc).
Here is the script:
#!/bin/bash
SERVICE='listener.py'
if [ "$(ps ax|grep -v grep|grep $SERVICE)" ] ; then
  echo "Running"
  exit 0
else
  echo "Not Running"
  /usr/bin/python  /var/www/listener.py &
  exit 0
fi