#!/bin/bash myapp=PodBlog myapp_path=/opt/web/proxy/podblog/script/podblog_fastcgi.pl port2Apache=10080 pidfile=/tmp/${myapp}.prod.pid function start { echo -n "Starting $myapp " ${myapp_path} -l 127.0.0.1:$port2Apache -p ${pidfile} -d -n 5 echo " OK." } function stop { echo -n "Waiting for existing connections to finish..." while [[ `netstat | grep $port2Apache | grep ESTABLISHED` ]]; do sleep 1 echo -n "." done echo " OK." echo -n "Terminating existing instance..." if [[ -r $pidfile ]]; then kill `cat $pidfile` 2 > /dev/null; while [[ -r $pidfile ]]; do echo -n "." sleep 1 rm $pidfile 2> /dev/null done fi echo " OK." } case $1 in 'start' ) start;; 'stop' ) stop;; 'restart' ) stop start;; esac