svc=`systemctl --help &>/dev/null && echo systemctl || (service --help &>/dev/null && echo service)`

if [ $svc = "systemctl" ]
then
  status=`systemctl is-active $1`

  case $status in
  active)   echo 0;;
  inactive) echo 6;;
  unknown)  echo 255;;
  *)        echo "Unrecognized status:'$status'"; exit;;
  esac
else
  status=`service $1 status | awk '{print tolower($0)}' 2>&1`

  case $status in
  *running)           echo 0;;
  *not\ running)      echo 6;;
  *unrecognized\ service) echo 255;;
  *)                      echo "Unrecognized status: '$status'"; exit;;
  esac
fi