File monasca-thresh-wrapper of Package openstack-monasca-thresh

#!/bin/sh

# Fujitsu LIMITED 2017

# /usr/bin wrapper for running thresh topology start/stop/status.
# start&stop are used from systemd service files as, respectively, ExecStart and ExecStop
# status is add-on

case "$1" in
    start)
      $0 status
      if [ $? -ne 0 ]; then
        sudo -EHu __THRESH_USER__ storm jar __THRESH_DIR__/thresh.jar monasca.thresh.ThresholdingEngine __THRESH_CONFIG_DIR__/thresh.yaml __THRESH_TOPOLOGY__
        exit $?
      else
        echo "monasca-thresh is already running"
        exit 0
      fi
    ;;
    stop)
      # On system shutdown storm is being shutdown also and this will hang so skip shutting down thresh in that case
      if [ -e '/sbin/runlevel' ]; then  # upstart/sysV case
        if [ $(runlevel | cut -d\  -f 2) == 0 ]; then
          exit 0
        fi
      else  # systemd case
        systemctl list-units --type=target | grep shutdown.target
        if [ $? -eq 0 ]; then
          exit 0
        fi
      fi
      sudo -EHu __THRESH_USER__ storm kill __THRESH_TOPOLOGY__
      # The above command returns but actually takes awhile loop watching status
      while true; do
        sudo -EHu __THRESH_USER__ storm list | grep __THRESH_TOPOLOGY__
        if [ $? -ne 0 ]; then break; fi
        sleep 1
      done
    ;;
    status)
      sudo -EHu __THRESH_USER__ storm list | grep __THRESH_TOPOLOGY__
    ;;
esac
openSUSE Build Service is sponsored by