# This shell script takes care of starting and stopping # the Pen load balancer # PID_FILE=run.pid OUT=run.out # resolve all links readlink() { file="$1" while [ -h "$file" ] ; do link="`\ls -ld "$file" | tail -1 | sed 's/.* -> //'`" # resolve relative links - in bash we could use the simpler: #[[ "$link" != /* && "$file" == */* ]] && file="${file%/*}/$link" || file="$link" case "$link" in /*) file="$link" ;; *) case "$file" in */*) file="`echo ${file} | sed 's/[^/]*$//'`$link" ;; *) file="$link" ;; esac ;; esac done echo "$file" } is_running() { [ -r "$PID_FILE" ] && pid=`cat $PID_FILE` [ -n "$pid" -a -r "/proc/$pid" ] && return 0 || return 1 } start() { rm -f "$OUT" pen 80 luna1:80 sol3:80 "$@" > $OUT sleep 1 ps -ef | grep pen | cat -n | grep " 1" | awk '{print $3}' > $PID_FILE echo "Server started." echo " See $OUT for startup message (normally there are none)." echo " See $PID_FILE for PID. `cat $PID_FILE`" } stop() { if is_running ; then : ; else echo "Server not running" return fi kill $pid while [ -r "/proc/$pid" ] ; do sleep 1 ; done rm -f $PID_FILE echo "Server stopped" } ME="`readlink "$0"`" cd "`dirname \"$ME\"`" case "$1" in start) if is_running ; then echo "Server already running, pid $pid" exit 1 fi shift start "$@" ;; stop) stop ;; restart) shift stop start "$@" ;; status) if is_running ; then echo "Server running, pid $pid" else echo "Server not running" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 ;; esac