Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
6,884

  • OS - SLES 12 SP3

  • DB - HDB2.0

  • SAP - Netweaver 7.53


Autostart = 1 has been the Basis administrator's best friend for years at this point.  Oracle, MSSQL Server, Sybase, etc. have all been quick to startup on boot, so Autostart could run normally and the Database would be waiting with open arms to welcome the dispatchers.

Now, with ABAP on HANA appliances, Autostart =1 just doesn't cut it anymore.  It takes more time for Hana to start its services than it does ABAP, so dispatchers are all dressed up with no where to go!  So how do we get our beloved autostart to work when they both try to start at the same time?  Well, sometimes the answer to advanced problems can be found in the past.  Shell scripting!

I recently was presented with this exact problem.  For development purposes, a colleague asked me to build an S/4 IDES Instance in AWS.  He wrote a small program that would allow him and his fellow developers to start and stop the instance quickly, but they had no easy way to control the application.  They would send the OS for a shutdown and let the application and DB die horribly uncontrolled deaths.  I was tasked with finding a simple and elegant solution so that the application would start on boot and both application and database will be shutdown gracefully on OS shutdown.

Code:
#!/bin/sh
# SAP startup script – sapstart

### BEGIN INIT INFO
# Provides: sapstart
# Required-Start: $ALL
# X-UnitedLinux-Should-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start SAP once Hana is available
### END INIT INFO
. /etc/rc.status
PATH=/sbin:/bin:/usr/sbin:/usr/bin; export PATH

rc_reset
case "$1" in
start)

while [ -z $sapStart ]

do
sapStart=`su -s /bin/csh -l [SID]adm -c "cd /home/[SID]adm;R3trans -d" | grep 0000`
if [ -z "$sapStart" ] ; then
echo "DB Unavailable"
sleep 30
else echo "DB online"
fi
done <<< "$(echo -e "$sapStart")"

echo "Starting SAP"
su -c /usr/sap/[SID]/SYS/exe/uc/linuxx86_64/startsap [SID]adm
esac

# Remember status and be verbose
rc_status -v
case "$1" in
stop)
echo "stopping SAP …"
su -c /usr/sap/[SID]/SYS/exe/uc/linuxx86_64/stopsap [SID]adm
sleep 60
echo "Stopping DB …"
'cd /hana/shared/[hanaSID]/HDB[sysnr]'
sudo -u [hanaSID]adm ./HDB stop
esac

# Remember status and be verbose
rc_status -v
case "$1" in
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

rc_exit

Rubber Duck:

Condition Start:

  • While the variable sapStart is NULL, check the status of R3trans -d and grep for 0000.

  • Set that result as sapStart and check the value.

  • If still NULL, let me know and run the loop again.

  • Once sapStart is not NULL, run the startsap command as user SIDadm


Condition Stop:

  • Tell me we're stopping SAP

  • Run the stopsap command as SIDadm

  • wait 60 seconds to be safe

  • run the HDB stop command as our HANA SIDadm user


The trick is now to configure this as a startup service.  As root, create the file "sapstart" in /etc/rc.d.  populate sapstart with the script above edited for your specific purposes.  Set the permissions to 755 (rwxr-xr-x) and then run the command:
chkconfig sapstart on

This will make sapstart a service and write the correct files to the correct initX.d directories for startup and shutdown runtime.

 
9 Comments
Labels in this area