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: 
7,924

  • 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
Isaías
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello Wesley,

Nice script 🙂

Just two comments:

  1. The startpsap and stopsap scripts are deprecated (SAP KBA 1763593 - S-user required);

  2. There is a binary file delivered with the SAP kernel that is called "sapstart", so you might want to change the name of your script just for clarify purposes 😉


 

Regards,

Isaías

 
0 Kudos
Isaias, thank you for your comment!

It would be easy to switch out the startsap/stop sap for their sapcontrol equivalents.  I'm just old school like that and will continue to use start/stopsap until it's fully deprecated and unavailable 🙂

As far as calling the script itself "sapstart," it does live in /etc/rc.d so that's far enough away from the kernel when scripts at that level are run as 'root' and not SIDadm.  Again, it's an arbitrary name and you can call it "mySuperAwesomeStartupScript" if you wanted to! Just make sure you also then run 'chkconfig mySuperAwesomeStartupScript on' to enable it as a service! 🙂

Thanks,

--Wess
matus_petrek2
Explorer
0 Kudos
On SUSE 15, stopscript is not called before shutdown of the server. Perhaps there is some change from SLES12 to SLES15? Startscript is called and SAP system is started, but it's not shutted down with server's restart. Any idea?

Thanks!
rbothra27
Discoverer
0 Kudos
Hi Wesley,

Thank you for the post. I tried to adapt the script according to my environment and when I try to run the script. it gives the below error.

./sapstart: line 51: syntax error: unexpected end of file

Br

Rakesh K
0 Kudos
Are you using something like Notepad ++?  Save the file as a shell script and look for anything that would show that a line has been terminated incorrectly.
weissf
Discoverer
0 Kudos
Do you have something similar for a Java system?
0 Kudos
As far as I can think of it, as long as your Java system returns a 0 for R3trans -d, it should still work.
mdretkiewicz
Discoverer
Hello I have manage to solve this problem by modifying <SID>_D00_<hostname>

I did change:

#Execute_03 = immediate $(DIR_CT_RUN)/startdb

for

Execute_03 = local /bin/sleep 90

This has delayed start of application server long enough to HDB automatically start

(using Autostart =1  )
christoph03
Explorer

Hello,

I know, this thread is very old, however this blog is the best I found searching for "Autostart ABAP when HANA is available"

 

Used the fix from Michal: Execute_03 = local /bin/sleep 90.
This was working fine until the db took longer than 90 sec. to start.

Didn't want to wait more than 1,5 min, so I created a tiny waitfordb Script
(picked from all your infos above, thanks)

 

Script waitfordb:

```

#!/bin/bash
# wait until HANA is Available

# cause - startdb is deprecated
# see SAP NOTE 1763593 - Starting and stopping SAP system instances - startsap/stopsap are deprecated

# copy script to /bin/waitfordb
# add to SAP INSTANCE Profile
# comment startdb
# #Execute_04 = immediate $(DIR_CT_RUN)/startdb
# add
# Execute_04 = local /bin/waitfordb

while [ -z "$sapStart" ]
do
sapStart=`R3trans -d | grep 0000`
if [ -z "$sapStart" ] ; then
echo "DB unavailable"
sleep 15
else echo "DB online"
fi
done <<< "$(echo -e "$sapStart")"

```
add the script to /bin/waitfordb and grant execution (chmod +x /bin/waitfordb)

 

Hope this helps.

 

Best regards

Christoph

Labels in this area