#!/bin/bash # # init.d script for swiftiply and generate a PIDfile for monit monitoring # put something like this into your crontab: # * * * * * root /etc/init.d/swiftiply pid # update the pidfile # function generatepid(){ current_pid=`pgrep -f 'swiftiply -c /etc/swiftiply/swiftconf.yaml'` pidfile_pid=`cat /var/run/swiftiply.pid` if [[ $current_pid = '' ]]; then rm /var/run/swiftiply.pid elif [[ $pidfile_pid != $current_pid ]]; then echo $current_pid > /var/run/swiftiply.pid fi } case "$1" in start) echo -n "Starting swiftiply:" swiftiply -c /etc/swiftiply/swiftconf.yaml generatepid echo ;; stop) echo -n "Stopping swiftiply:" killall -9 swiftiply generatepid echo ;; restart) $0 stop $0 start ;; pid) generatepid ;; *) echo "usage: $0 [start|stop|restart|pid]" esac exit 0