#!/bin/bash # CONFIGURED BY ANSIBLE prog=sshguard function start { [[ -f /var/run/$prog.pid ]] && status && exit 1 echo starting $prog daemon # nohup is required for remote command to work # only prints errors - no log rotation required exec nohup $prog > /var/log/$prog.log 2>&1 & } function status { if [[ -e /var/run/$prog.pid ]]; then echo $prog is running as pid `cat /var/run/$prog.pid` else echo $prog is stopped fi } function stop { echo stopping $prog daemon killall $prog rm -f /var/run/$prog.pid } case $1 in start) start ;; status) status ;; stop) stop ;; restart) stop; start ;; *) echo "usage $0 start|status|stop|restart"; exit 1 ;; esac