#!/bin/bash

### BEGIN INIT INFO
# Provides:          warsaw
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Warsaw Service
# Description:       Warsaw Service
#  Developed by GAS Tecnologia<info@gastecnologia.com.br>
#  Copyright 2015 GAS Tecnologia
### END INIT INFO

systemctl_wrapper() {
  hash systemctl > /dev/null 2>&1 || return 2
  systemctl $1 warsaw.service
  return 0
}

case "$1" in
    start)
        systemctl_wrapper start || warsaw start
        ;;
    stop)
        systemctl_wrapper stop || warsaw stop
        ;;
    restart)
        if ! systemctl_wrapper restart; then
          warsaw stop
          warsaw start
        fi
        ;;
    *)
        exit 1
        ;;
esac
exit 0
