Linux service unit sample

/etc/rc.d service shell script consul

На примере сервиса consul

#!/bin/bash

case "$1" in
start)
   /urs/bin/consul &
   echo $!>/var/run/consul.pid
   ;;
stop)
   kill `cat /var/run/consul.pid`
   rm /var/run/consul.pid
   ;;
restart)
   $0 stop
   $0 start
   ;;
status)
   if [ -e /var/run/consul.pid ]; then
      echo Consul is running, pid=`cat /var/run/consul.pid`
   else
      echo Consul is not running now!
      exit 1
   fi
   ;;
*)
   echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0