On Red Hat 7.4, in init.d, I have file sapabi, which is installed by calling
- chkconfig --add sapabi
This result in entries like /etc/rc3.d/
- S10network
- S90sapinit
- S91sapabi
Example entry in /etc/rc6.d/
- K90network
- K09sapabi
- K10sapinit
When I execute the file as user root with command
- ./sapabi start
- service sapabi start
- service sapabi stop
everything works fine and the remote SAP Diagnostics Agent is started or stopped by sapcontrol as intended.
However, when I enter the 'reboot' command :
- during shutdown nothing is executed at all, not even the 'stop' argument
- during startup, start is passed as an argument and the start() functions are called. Unfortunately, the 'eval' sapcontrol command isn't executed like when I call the ./sapabi start command. Instead, the log file returns the 'help' of sapcontrol :
NAME sapcontrol (Version: 753, patch 200, changelist 1844229)
SYNOPSIS sapcontrol [-prot ] [-trace ] [-debug] ...
- Why isn't eval executed properly during startup in the same manner like when the script is launched directly?
- Why isn't the service stopped during shutdown?
- Am I missing something in Required-Start or Required-Stop?
- I'm not too sure about the correct use of ' or " in the eval statement
Many thanks for the help
#!/bin/sh
#
# /etc/init.d/sapabi
#
# chkconfig: 345 91 09
# description: Start / stop SAP
#
### BEGIN INIT INFO
# Provides: sapabi
# Required-Start: $network $syslog $local_fs $named $remote_fs $time
# X-UnitedLinux-Should-Start:
# Required-Stop: $network $syslog $local_fs $named $remote_fs $time
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start the sap system
# Description: Start the sap system
### END INIT INFO
PGM_PATH=$0
ARG1=$1
ARG2=$2
# Remote Diagnostics Agent configuration
#
# DA_R : If set to 1, remote diagnostics services will be started.
#
DA_R=1
DA_R_OS_USER="daaadm"
DA_R_OS_USER_PASSWORD="xxxxxx"
DA_R_INSTANCE_NR="98"
DA_R_START_CMD="StartSystem"
DA_R_STOP_CMD="StopSystem"
DA_R_HOST="xxx.xxx.xxx"
log=/var/log/sapabi.log
function ping_server()
{
target=$1
ping -c1 -w3 ${target} &>/dev/null && return 1 || return 0
}
function start_service()
{
serviceName=$1
localSidAdm=$2
serviceHost=$3
serviceUser=$4
servicePassword=$5
serviceInstance=$6
serviceStartCmd=$7
processName=$8
waitTime=$9
ping_server $serviceHost;
if [ $? -eq 1 ];
then
echo "in ping start_service $serviceName" >> $log
eval ' su -s /bin/csh -l "$localSidAdm" -c "sapcontrol -nr "$serviceInstance" -host "$serviceHost" -user "$serviceUser" "$servicePassword" -function "$serviceStartCmd""' >> $log
test=""
startTime=$(date +%s)
currentTime=$(date +%s)
while [[ "${test}" != *"GREEN"* && ($((currentTime - startTime)) -lt $waitTime) ]];
do
test=`su -s /bin/csh -l "$localSidAdm" -c 'sapcontrol -nr '"$serviceInstance"' -host '"$serviceHost"' -user '"$serviceUser"' '"$servicePassword"' -function GetProcessList | grep '"$processName"''`
# Do not print the trailing newline character
echo -n "."
sleep 1
currentTime=$(date +%s)
done
echo ""
echo "$serviceName - time $((currentTime - startTime)) seconds - ${test}" >> $log
else
echo "Error : ${serviceName} host ${serviceHost} not available"
do_exit ${ERR_unknown_host}
fi
unset serviceName
unset localSidAdm
unset serviceHost
unset serviceUser
unset servicePassword
unset serviceInstance
unset serviceStartCmd
unset processName
unset waitTime
}
start() {
#start the remote Diagnostics Agent
if [ "$DA_R" == 1 ];
then
echo "Starting the remote Diagnostics Agent"
start_service "Remote Diagnostics Agent" $LOCAL_SIDADM $DA_R_HOST $DA_R_OS_USER $DA_R_OS_USER_PASSWORD $DA_R_INSTANCE_NR $DA_R_START_CMD "jstart" "2700"
fi
}
... similar stop functions ...
case "${ARG1}" in
start )
start
;;
stop )
stop
;;
status )
status
;;
restart )
stop
start
;;
* )
echo "Usage: ${PGM_PATH} {start|stop|status|restart}"
do_exit
;;
esac;