#!/bin/bash # CIPRES_ROOT must be in the environment when this script is run. # This script shouldn't use any absolute paths so that it can be run # by end users regardless of where they've installed cipres and other tools. CIPRES_USER=`whoami` CIPRES_HOME=~$CIPRES_USER CIPRES_BIN=${CIPRES_ROOT}/bin HOST=`hostname` if [ "`uname | grep Darwin`" = "Darwin" ]; then PS="ps -U$CIPRES_USER -j -ww" else PS="ps -U$CIPRES_USER -f" fi # Get processes IDs of interest fn_ps() { REGFIXED=`$PS | grep RegistryApp | grep "fixedPort" | grep -v grep | awk '{print $2}'` PROPSVC=`$PS | grep PropertiesApp | grep -v grep | awk '{print $2}'` REGOTHER=`$PS | grep RegistryApp | grep -v "fixedPort" | grep -v grep | awk '{print $2}'` len $REGFIXED ; REGFIXED_COUNT=$? len $PROPSVC ; PROPSVC_COUNT=$? len $REGOTHER ; REGOTHER_COUNT=$? } len() { retval=0 for i in $* do retval=`expr $retval + 1` done return $retval } killall() { for pid in $* do echo killing $pid on $HOST kill $pid done } id $CIPRES_USER > /dev/null 2>&1 if [ $? = 1 ] then echo "no cipres user: $CIPRES_USER" on $HOST exit 1 fi if [ "$CIPRES_ROOT" == "" ] ; then echo "CIPRES_ROOT environment variable must be set to the top of a cipres installation" exit 1 fi if [ $# -gt 1 ] ; then CONFIGFILE="$2" if [ ! -f $CONFIGFILE ]; then echo "$CONFIGFILE must be an existingfile" exit 1 fi else CONFIGFILE="" fi case "$1" in 'start') fn_ps if [ $PROPSVC_COUNT -eq 0 ]; then echo "Starting CIPRES property service on $HOST" python "$CIPRES_ROOT/bin/cipres_daemon" propsvc sleep 5 fi if [ $REGFIXED_COUNT -gt 0 ]; then echo "already running. pid is $REGFIXED" on $HOST else echo "Starting CIPRES Registry on $HOST" python "$CIPRES_ROOT/bin/cipres_daemon" registry fi ;; 'stop') fn_ps killall $REGFIXED $REGOTHER $PROPSVC ;; 'restart') echo "Restarting CIPRES Registry and property service" on $HOST $0 stop sleep 5 $0 start echo "done on $HOST" ;; 'status') fn_ps if [ $REGFIXED_COUNT -gt 0 ] ; then echo "Cipres Registry is Running on $HOST. pids: $REGFIXED" else echo "Main cipres registry is NOT Running on $HOST" fi if [ $REGOTHER_COUNT -gt 0 ] ; then echo "There are extra Cipres Registries Running on $HOST. pids: $REGOTHER" else echo "There are NO extra Cipres Registries Running" on $HOST. fi if [ $PROPSVC_COUNT -gt 0 ] ; then echo "Cipres PropertiesApp is running on $HOST. pids: $PROPSVC" else echo "Cipres PropertiesApp is NOT running on $HOST" fi ;; *) echo "Usage: $0 {start|stop|restart|status} [name_of_script_to_source]" exit 0 esac