Skip to Content

Autostart ABAP when HANA is Available

  • 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.


# SAP startup script – sapstart

# 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
. /etc/rc.status
PATH=/sbin:/bin:/usr/sbin:/usr/bin; export PATH

case "$1" in
while [ -z $sapStart ]
                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"
        done <<< "$(echo -e "$sapStart")"
echo "Starting SAP"
su -c /usr/sap/[SID]/SYS/exe/uc/linuxx86_64/startsap [SID]adm

# Remember status and be verbose
rc_status -v
case "$1" in 
        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

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


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.


You must be Logged on to comment or reply to a post.
  • 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 😉





    • 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! 🙂



  • 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?


  • 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


    Rakesh K

    • 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.