#!/bin/bash OS_NAME=`uname -s` PWD=`pwd` REAL_PATH=$PWD/`dirname "$0"` SCRIPT_NAME=`basename "$0"` source "$REAL_PATH/bashlib_positional" if [ $OS_NAME == "Linux" ] then export LD_LIBRARY_PATH="$REAL_PATH/../libs:$REAL_PATH/../bin:$LD_LIBRARY_PATH" EXECUTABLE_EXT="run" DAEMONIZE="$REAL_PATH/daemonize_linux" elif [ $OS_NAME == "Darwin" ] then EXECUTABLE_EXT="run" DAEMONIZE="$REAL_PATH/daemonize_osx" fi GDS_EXECUTABLE="$REAL_PATH/../bin/osteam-GeneralDirectoryServer.$EXECUTABLE_EXT" CSDS_EXECUTABLE="$REAL_PATH/../bin/osteam-ContentServerDirectoryServer.$EXECUTABLE_EXT" AS_EXECUTABLE="$REAL_PATH/../bin/osteam-AuthenticationServer.$EXECUTABLE_EXT" CSC_EXECUTABLE="$REAL_PATH/../bin/osteam-ConfigurationServerClient.$EXECUTABLE_EXT" CSPUBLIC_EXECUTABLE="$REAL_PATH/../bin/osteam-ContentServerPublic.$EXECUTABLE_EXT" CSCLIENT_EXECUTABLE="$REAL_PATH/../bin/osteam-ContentServerClient.$EXECUTABLE_EXT" CM_EXECUTABLE="$REAL_PATH/../bin/osteam-ClientManager.$EXECUTABLE_EXT" PID_PATH="$REAL_PATH/../pids" LOG_PATH="$REAL_PATH/../logs" BIN_PATH="$REAL_PATH/../bin" function StopAllServices { StopService gds StopService csc StopService as StopService csds StopService cspublic StopService cm } function StartAllServices { StartService gds sleep 1 StartService csc StartService as StartService csds StartService cspublic StartService cm } function RestartAllServices { StopAllServices StartAllServices } function StartService { if [ ! -f "$PID_PATH/$1.pid" ] then case $1 in all) StartAllServices ;; gds) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$GDS_EXECUTABLE" ;; csds) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$CSDS_EXECUTABLE" "--gds=$GDS_IPADDRPORT" ;; as) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$AS_EXECUTABLE" "--gds=$GDS_IPADDRPORT" ;; csc) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$CSC_EXECUTABLE" "--gds=$GDS_IPADDRPORT" ;; cspublic) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$CSPUBLIC_EXECUTABLE" "--csds=$CSDS_IPADDRPORT" ;; csclient) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$CSCLIENT_EXECUTABLE" "--csds=$CSDS_IPADDRPORT" ;; cm) "$DAEMONIZE" -c "$BIN_PATH/" -o "$LOG_PATH/$1.log" -e "$LOG_PATH/$1.log" -p "$PID_PATH/$1.pid" "$CM_EXECUTABLE" ;; *) ;; esac if [ $? == 0 ] then echo "Done." else echo "Failed." StopService $1 fi else echo "Already started." fi } function StopService { case $1 in all) StopAllServices ;; *) if [ -f "$PID_PATH/$1.pid" ] then PID_TO_KILL=`cat "$PID_PATH/$1.pid"` PS_RET=`ps p $PID_TO_KILL | wc -l` # PID_IN_PS=`ps ax | grep -v grep | grep $PID_TO_KILL | cut -d ' ' -f1` if [ $PS_RET -eq 2 ] then kill -15 `cat "$PID_PATH/$1.pid"` fi rm "$PID_PATH/$1.pid" echo "Done." else echo "Nothing to stop." fi ;; esac } function RestartService { case $1 in all) RestartAllServices ;; *) StopService $1 StartService $1 ;; esac } function DoActions { ParameterName=`GetParameterName $1` ParameterValue=`GetParameterValue $1` case $ParameterName in start) StartService $ParameterValue exit ;; stop) StopService $ParameterValue exit ;; restart) RestartService $ParameterValue exit ;; *) UnknownParameter $ParameterName exit ;; esac } function DoOptions { ParameterName=`GetParameterName $1` ParameterValue=`GetParameterValue $1` case $ParameterName in gds) GDS_IPADDRPORT=$ParameterValue ;; csds) CSDS_IPADDRPORT=$ParameterValue ;; ip) BINDIP=$ParameterValue ;; *) UnknownParameter $ParameterName exit ;; esac } ParseParameters DoActions DoOptions $*