z9z3vw
Last Updated: February 25, 2016
·
842
· itaqua

Start/Stop/status cycle for vert.x program (or any other PID controlled one)

This is an small Shell script to control any program that can be stopped by killing it's Process.

#!/bin/sh
SERVICEPID="service.pid"
case $1 in
  "start")
    if [ ! -f $SERVICEPID ]; then
      EXPR="vertx runmod com.m4s~dingus-ws~1.0.0 &> log/system.out  &"
      eval $EXPR
      pid=$!
      echo $pid > $SERVICEPID
      echo "Service Started with PID: $pid"
    else
      echo "$SERVICEPID Exist!, Check if the program is not running already."
    fi
    ;;
  "stop")
    if [ -f $SERVICEPID ]; then
      pid=$(<"$SERVICEPID")
      kill -9 $pid
      rm -f $SERVICEPID
      echo "Servicewith PID: $pid. Stoped "
    else
      echo "$SERVICEPID DON'T Exist!, Check if the program is not halted already."
    fi
    ;;
  "status")
    if [ ! -f $SERVICEPID ]; then
      echo "$SERVICEPID DON'T Exist!, Check if the program is not halted already."
    else
      pid=$(<"$SERVICEPID")
      ps $pid
    fi
    ;;
  *)
    echo "please use:"
    echo "       start | stop | status"
    ;;
esac