Example Engine.sh Script
The following is an example of an engine.sh script.
#!/bin/sh # Copyright (c) 2008-2017 Cloud Software Group, Inc. All Rights Reserved. # The following variables control various aspects of the Silver Fabric Engine's # startup behavior; uncomment to override values that are picked up from the # environment. # Whether or not to allow the Engine to create core files on a crash; enable # with care, as these can rapidly consume filesystem resources # DS_ALLOWCORE= # The path to the root directory of the JRE to be used by the Engine # DS_ENGINE_JAVA_HOME= # The target hardware platform; typically the output of 'uname -m' # DS_TARGET_PLATFORM= # Determines whether or not both standard input and standard output are # detached for native Service code; this flag can be used to work around a # buggy freopen implementation in Red Hat 8.0. # DSNODETACH= # Whether or not to run the periodic thread sweeper that kills orphaned # processes in the engined process group. # DS_ORPHAN_SWEEP_DISABLE= # End of variable overrides... if [ "z$DS_ENGINE_JAVA_HOME" = "z" ] then DS_ENGINE_JAVA_HOME=./jre fi if [ "z$DS_ORPHAN_SWEEP_DISABLE" = "z" ] then DS_ORPHAN_SWEEP_DISABLE=true fi export DS_ORPHAN_SWEEP_DISABLE if [ "z$DS_TARGET_PLATFORM" = "z" ] then DS_TARGET_PLATFORM=`uname -m` fi jreSYSTYPE=`uname -s` jreCPUNAME=$DS_TARGET_PLATFORM jreSYSTEM="" jreARCH="" if [ "$jreSYSTYPE" = "Linux" ]; then jreSYSTEM=linux if [ "$jreCPUNAME" = "s390" ]; then jreARCH=s390 elif [ "$jreCPUNAME" = "ppc64" ]; then jreARCH=ppc64 elif [ "$jreCPUNAME" = "x86_64" ]; then jreARCH=amd64 else jreARCH=i386 fi UNZIP_TOOL=gunzip elif [ "$jreSYSTYPE" = "SunOS" ]; then jreSYSTEM=solaris if [ "$jreCPUNAME" = "i86pc" ]; then if [ "z$SOLX86_32" != "z" ]; then jreARCH=i386 else jreARCH=amd64 fi else jreARCH=sparc fi UNZIP_TOOL=gunzip elif [ "$jreSYSTYPE" = "HP-UX" ]; then jreSYSTEM=hpux if [ "$jreCPUNAME" = "ia64" ]; then jreARCH=hpux64 else jreARCH=hpux32 fi UNZIP_TOOL=gunzip elif [ "$jreSYSTYPE" = "AIX" ]; then jreSYSTEM=aix jreARCH=ppc UNZIP_TOOL=gunzip fi export UNZIP_TOOL DSJREFILE=jre.$jreSYSTEM-$jreARCH export DSJREFILE JAVA_HOME=$DS_ENGINE_JAVA_HOME export JAVA_HOME unset CLASSPATH export CLASSPATH EXITCODE=0 # get the system architecture case $DS_TARGET_PLATFORM in x86_64) ARCH=amd64 PLATFORM=linux64 HNAMECMD=`hostname` #MACADDRCMD=`/sbin/ifconfig -a | grep HWaddr | awk 'NR==1 {gsub(":",""); print $5}'` MACADDRCMD=`/sbin/ifconfig -a | grep ether | awk 'NR==1 {gsub(":",""); print $2}'` DS_USE_SNAT_IP_ADDRESS=`/sbin/ifconfig eth0 | grep inet | grep -v inet6 | awk '{print $2}'` export DS_USE_SNAT_IP_ADDRESS ;; i86pc) if [ "z$SOLX86_32" != "z" ]; then ARCH=i386 PLATFORM=solarisX86_32 else ARCH=amd64 PLATFORM=solarisX86 fi HNAMECMD=`hostname | sed 's/\..*$//'` IPCMD=`/sbin/ifconfig -a | grep inet | grep -v "127.0.0.1" | awk 'NR == 1 {print $2}'` MACADDRCMD=`netstat -np | grep "[ \t]$IPCMD[ \t\.]" | nawk 'NR==1 {gsub(":",""); print $5}'` ;; *86*) ARCH=i386 if [ -e /etc/redhat-release ]; then REDHATRELEASE=`cat /etc/redhat-release | awk '{print $5}' | cut -f1 -d'.'` if [ "$REDHATRELEASE" = "8" ]; then export DSNODETACH=defined fi else REDHATRELEASE=7 fi # KERNELVER=`uname -r | head -c 3` # if [ $KERNELVER = "2.4" ]; then # PLATFORM=linux-glibc22 # else PLATFORM=linux # fi HNAMECMD=`hostname -s` MACADDRCMD=`/sbin/ifconfig -a | grep HWaddr | awk 'NR==1 {gsub(":",""); print $5}'` export J2SE_PREEMPTCLOSE=1 ;; sun*) ARCH=sparc PLATFORM=solaris HNAMECMD=`hostname | sed 's/\..*$//'` IPCMD=`/sbin/ifconfig -a | grep inet | grep -v "127.0.0.1" | awk 'NR == 1 {print $2}'` MACADDRCMD=`netstat -np | grep "[ \t]$IPCMD[ \t\.]" | nawk 'NR==1 {gsub(":",""); print $5}'` if [ `uname -r | awk -F. '{ print $2 }'` -gt 9 ]; then if [ ! `zonename` = "global" ]; then # if solaris 10 or higher and not the global zone, append zoneid to the macaddr MACADDRCMD=$MACADDRCMD`zoneadm list -p | awk -F: '{ print $1 }'` fi fi ;; ia64) OSTYPE=`uname -s` if [ $OSTYPE = "Linux" ]; then ARCH=amd64 PLATFORM=linux64 HNAMECMD=`hostname -s` MACADDRCMD=`/sbin/ifconfig -a | grep HWaddr | awk 'NR==1 {gsub(":",""); print $5}'` elif [ $OSTYPE = "HP-UX" ]; then ARCH=hpux64 PLATFORM=hpux64 HNAMECMD=`hostname | sed 's/\..*$//'` MACADDRCMD=`/usr/sbin/lanscan -a | awk 'NR==1 {print substr($0,3)}'` else echo 'This is an unsupported platform' exit 9 fi ;; s390) ARCH=s390 PLATFORM=zlinux HNAMECMD=`hostname -s` LHNAME=`hostname` MACADDRCMD=`install/bin/guidder $LHNAME` ;; ppc64) ARCH=ppc PLATFORM=plinux HNAMECMD=`hostname -s` LHNAME=`hostname` MACADDRCMD=`/sbin/ifconfig -a | grep HWaddr | awk 'NR==1 {gsub(":",""); print $5}'` ;; AIX) ARCH=ppc PLATFORM=aix HNAMECMD=`hostname | sed 's/\..*$//'` IPCMD=`/etc/ifconfig -a | grep inet | grep -v "127.0.0.1" | awk 'NR == 1 {print $2}'` MACADDRCMD=`/bin/entstat en0|grep "Hardware Address"|awk 'NR==1 {gsub(":",""); print $3}'` ;; *) OSTYPE=`uname -s` if [ $OSTYPE = "AIX" ]; then ARCH=ppc PLATFORM=aix HNAMECMD=`hostname | sed 's/\..*$//'` IPCMD=`/etc/ifconfig -a | grep inet | grep -v "127.0.0.1" | awk 'NR == 1 {print $2}'` MACADDRCMD=`/bin/entstat en0|grep "Hardware Address"|awk 'NR==1 {gsub(":",""); print $3}'` else echo 'This is an unsupported platform' exit 9 fi ;; esac if [ "z$MACADDRCMD" = "z" ] then echo 'Unable to determine the MAC address of this machine, please check your host/network configuration' exit 9 fi CURRDIR=`pwd` PATH=$CURRDIR/bin:$CURRDIR/resources/$PLATFORM/bin:/bin:/usr/bin;export PATH # shell function for pulling properties file values if [ "z$DATFILE" = "z" ] then DATFILE=intranet.dat fi parseProperty() { propname=$1 if [ -z "$2" ]; then propfile=$DATFILE else propfile=$2 fi currprop=`sed -n -e "s/^$propname=\([^; ]*\).*\$/\1/p" $propfile` } # check for upgrade sync JLIB=$JAVA_HOME/lib/$ARCH if [ "$PLATFORM" = "zlinux" -o "$PLATFORM" = "plinux" ]; then LD_LIBRARY_PATH="lib:$JAVA_HOME/bin:$JAVA_HOME/bin/classic:$LD_LIBRARY_PATH" #elif [ "$PLATFORM" = "linux" -o "$PLATFORM" = "linux-glibc22" ]; then elif [ "$PLATFORM" = "linux" ]; then LD_LIBRARY_PATH="lib:$JAVA_HOME/lib/ext:$JLIB/server:$JLIB:$JLIB/native_threads:$LD_LIBRARY_PATH" elif [ "$PLATFORM" = "hpux64" ]; then JLIB=$JAVA_HOME/lib/IA64W LD_LIBRARY_PATH="lib:$JAVA_HOME/lib/ext:$JLIB/server:$JLIB:$JLIB/native_threads:$LD_LIBRARY_PATH" elif [ "$PLATFORM" = "hpux" ]; then JLIB=$JAVA_HOME/lib/IA64N LD_LIBRARY_PATH="lib:$JAVA_HOME/lib/ext:$JLIB/server:$JLIB:$JLIB/native_threads:$LD_LIBRARY_PATH" elif [ "$PLATFORM" = "aix" ]; then LIBPATH="lib:$JAVA_HOME/lib/ppc:$JAVA_HOME/lib/ppc/j9vm:$LIBPATH" export LIBPATH else LD_LIBRARY_PATH="lib:$JAVA_HOME/lib/ext:$JLIB/server:$JLIB:$JLIB/native_threads:$LD_LIBRARY_PATH" fi export LD_LIBRARY_PATH # process options for run-time profile dir and local config file shift `expr $OPTIND - 1` if [ ! -f "$DATFILE" ]; then echo "No settings file found." echo "please run configure.sh" exit 2 fi parseProperty server SERVER=$currprop ; export SERVER parseProperty protocol protocol=$currprop if [ "Z$protocol" = "Z" ]; then protocol="http"; fi; PROTOCOL=$protocol; export PROTOCOL parseProperty jre jreLocation=$currprop if [ "Z$jreLocation" = "Z" ]; then jreLocation="remote"; fi; JRELOCATION=$jreLocation; export JRELOCATION # accomodation for 1.5 jvm if [ "$PLATFORM" = "linux64" -a "$jreLocation" = "remote" ]; then # preload libzip.so on linux64 when 1.5 jre since our use of libz.so conflicts with it. if [ "`jre/bin/java -version 2>&1 | grep version | cut -d ' ' -f 3 | cut -d '.' -f 2`" = "5" ]; then # java -version returns "1.5..." or "1.6...." so if the second field is 5 then we are 1.5 jvm. LD_PRELOAD=$LD_PRELOAD:$JLIB/libzip.so export LD_PRELOAD fi fi parseProperty profilesdir DSProfilesDir=$currprop ; export DSProfilesDir hname=$HNAMECMD ; export hname DISTRO_FILE=$DSProfilesDir/$hname/distro.$HNAMECMD ; export DISTRO_FILE if [ ! -f "$DISTRO_FILE" ]; then mkdir -p $DSProfilesDir/$hname echo "default" > $DISTRO_FILE fi CONFIGNAME=`cat $DISTRO_FILE 2>/dev/null`; export CONFIGNAME macaddr=$MACADDRCMD ; export macaddr USERNAME=$hname ENGINEBOOT_URL=$PROTOCOL://$SERVER/livecluster/engineUpdate/shared/DSEngineBoot.jar; export ENGINEBOOT_URL PID_FILE=$DSProfilesDir/$hname/pid.$hname ; export PID_FILE # this should never, ever happen if [ -z "$CONFIGNAME" ]; then CONFIGNAME=default fi # don't produce core files unless specfied - fills up the filesystem if [ ! -n "$DS_ALLOWCORE" ]; then ulimit -c 0 fi # create log dir for this machine if [ ! -d $DSProfilesDir/$hname/logs ]; then mkdir -p $DSProfilesDir/$hname/logs fi # shell function for config fetching fetchconfig() { PIDFILES=`find $DSProfilesDir/$hname -name "pid.*"` if [ -n "$1" -a "$1" != "`cat $DISTRO_FILE`" ]; then if [ -n "$PIDFILES" ]; then echo "Another Engine is running from this install image using the" echo "configuration $CONFIGNAME" echo "This Engine must be run under the same configuration or the" echo "other one must be halted" exit 3 fi CONFIGNAME=$1 export CONFIGNAME fi if [ ! -f $DSProfilesDir/$hname/x4088.$CONFIGNAME ]; then echo "Fetching configuration from $PROTOCOL://$SERVER" ./bin/installer doUrlToFile "$PROTOCOL://$SERVER/livecluster/public_html/register/register.jsp?config=$CONFIGNAME&platform=$PLATFORM®ister=$USERNAME®Request=config" $DSProfilesDir/$hname/x4088.$CONFIGNAME fi if [ "`cat $DSProfilesDir/$hname/x4088.$CONFIGNAME`" = "" ]; then echo "ERROR: configuration $CONFIGNAME could not be found on the server" echo "Please specify a different configuration" rm $DSProfilesDir/$hname/x4088.$CONFIGNAME exit 4 fi cp $DSProfilesDir/$hname/x4088.$CONFIGNAME $DSProfilesDir/$hname/x4088 echo $CONFIGNAME > $DISTRO_FILE if [ ! -f $DSProfilesDir/$hname/y3031 ]; then echo "Fetching profile from $SERVER" ./bin/installer doUrlToFile "$PROTOCOL://$SERVER/livecluster/public_html/register/register.jsp?config=$CONFIGNAME&platform=$PLATFORM®ister=$USERNAME®Request=profile" $DSProfilesDir/$hname/y3031 fi } case "$1" in start) if [ -f $PID_FILE ]; then if kill -0 `cat $PID_FILE` 2>/dev/null ; then echo "Engine is already running; will not start a new Engine" exit 5 else echo "Engine previously suffered an ungraceful death; so starting new Engine" rm -f $PID_FILE fi fi fetchconfig $2 echo "Using configuration $CONFIGNAME" echo "Starting Engine" ./bin/engine $PID_FILE > $DSProfilesDir/$hname/logs/engine.out 2>&1 EXITCODE=$? ;; startfg) fetchconfig $2 echo "Using configuration $CONFIGNAME" echo "Starting Engine" ./bin/engine EXITCODE=$? ;; strace) fetchconfig $2 echo "Using configuration $CONFIGNAME" echo "Starting Engine" strace ./bin/engine ;; stop) if [ -f $PID_FILE ] then PID=`cat $PID_FILE` if kill $PID 2>/dev/null ; then echo "Stopping Engine" else echo "Engine has already exited" echo "see $DSProfilesDir/$hname/logs/engined.log for details" fi rm -rf $PID_FILE else echo "Don't know of any running Engines" >&2 EXITCODE=8 fi ;; *) echo "Usage: $0 [start [profile|default]|stop|startfg]" >&2 echo " start starts Engine." >&2 echo " stop stops Engine" >&2 echo " startfg starts Engine in foreground mode, for debugging" >&2 echo " You can pass the name of an Engine profile, or 'default'," >&2 echo " to start with a specific profile, or the default." >&2 EXITCODE=7 ;; esac exit $EXITCODE
Copyright © Cloud Software Group, Inc. All rights reserved.