Skip to Content
  • 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.

 

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Isaias Freitas

    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) 
    1. Wesley Tobler Post author

      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

      (0) 

Leave a Reply