Source

woocode / sa-auto / sh / sendmail / sendmail.sh

#!/bin/sh

CWD=$(dirname $(which $0))
PIDFILE=$CWD/sendmail.pid

start() {
    echo "Starting mail sender"
    nohup python $CWD/sendmail.py 2>&1 > $CWD/send.log &
    PID=$!
    echo "[+] Started daemon pid: $PID"
    echo $PID > $PIDFILE
}

stop() {
    echo "Stopping mail sender"
    if [ -f $PIDFILE ]; then
        PID=$(cat $PIDFILE)
        echo "Got PID $PID"
        kill $PID
    else
        echo "No such pid file $PIDFILE"
    fi
}

case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "$0 start|stop"
        exit 1
        ;;
esac