#!/bin/bash # # Namaste launch script -- launches the brokers via nohup as background (daemon) processes # # usage: $0 >/dev/null # # Note that this bash script should be called from the php script: startBrokers.php # # although it will work fine if called by itself - the launch script reads the configuration file # and launches the number of broker instances specified therein. # # HISTORY: # -------- # 06-12-17 mks original coding # if [ $(id -u) = "0" ]; then echo "$0 cannot be run as root" exit 1 fi SCRIPT=$(readlink -f $0) SCRIPTPATH=$(dirname ${SCRIPT}) BASEPATH=$(dirname ${SCRIPTPATH}) #echo "0: basepath: ${BASEPATH}" TDIR="${BASEPATH}/brokers" PDIR="${BASEPATH}/pids/" if [ $# -eq 0 ] then for file in ${TDIR}/*.php do echo ${file} [ -f ${file} -a -s ${file} ] && nohup php -f ${file} 2>&1 & done else # if arguments are passed, loop through each assuming the formats 'brokerFileName' or 'brokerFileName:n' # where 'n' is the number of instances of that broker to run # # example: 'dwBroker:5' would start 5 instances of the delayed-write broker for arg in "$@" do IFS=':' read -ra splitArg <<< "${arg}" # get number of processes for this broker numProcesses=1 splitsize="${#splitArg[@]}" if [ ${splitsize} -eq 2 ] then numProcesses=0; processLocation=${splitArg[1]} elif [ ${splitsize} -eq 3 ] then numProcesses=${splitArg[2]} processLocation=${splitArg[1]} fi # start processes broker=${splitArg[0]} file=${TDIR}/${broker}.php c=1 if [ $numProcesses -eq 0 ]; then if [ -f ${file} -a -s ${file} ]; then nohup php -f ${file} ${processLocation} 2>&1 & pid=$! #echo "1: nohup php -f ${file} ${processLocation}" #echo "1: ${PDIR}${broker}.${c} has PID: ${pid}" echo ${pid} > "${PDIR}${broker}.${processLocation}" c=$((c+1)) fi else # echo "Starting ${file} ${numProcesses} times..." for (( i=0; i<${numProcesses}; i++ )); do if [ -f ${file} -a -s ${file} ]; then nohup php -f ${file} ${processLocation} 2>&1 & pid=$! #echo "2: nohup php -f ${file} ${processLocation}" #echo "2: ${PDIR}${broker}.${c} has PID: ${pid}" echo ${pid} > "${PDIR}${broker}.${processLocation}.${c}" c=$((c+1)) else echo "${file} was not found" fi done fi done fi