SAP HANA Under The Hood – SAPInit and SAPStartSrv
SAPInit and SAPStartSrv
In this Under the Hood blog series we explore SAP HANA technical topics that go beyond the documentation but may help to familiarise ourselves with the technology.
The objective is to provide some insights on particular SAP HANA topics. Like a mechanic, look under the hood and take apart a piece to examine its functioning.
Learned something new? Post a comment, share on social media, and/or give a like. Thanks!
When Tesla revolutionised the concept of how an electrical vehicle should look like they did not reinvent the wheel. Similarly, although SAP HANA revolutionised the relational database with HTAP (Hybrid transactional/analytical processing), merging OLTP with OLAP, not everything on the platform was developed from scratch. One example is the mechanism how the SAP HANA database is initialised on the Linux operating system with SAPInit and SAPStartSrv. This is exactly the same as SAP NetWeaver processes are booted.
So how does this work?
The Start and Stop with sapinit tutorial video shows the SAPInit/SAPServices configuration and how automatic startup of an SAP HANA system is configured. This video was recorded for the Getting Started with SAP HANA on the Google Cloud Platform series but the implementation of SAPInit is the same on all platform, cloud or on-premise.
Most of you will be familiar with Services configuration on Microsoft Windows computers.
Below a screen capture of the SAPHostControl service running under the sapadm local user account. The actual program that runs the service is the executable sapstartsrv.exe. Specific parameters for this service come from a configuration file or, as it is called here, a profile (pf=).
The service implementation for SAP HANA on Linux is quite similar.
Below a screen capture from the Services Manager on SUSE Linux Enterprise Server (SLES). The service is named sapinit and the program (executable) that it runs is called sapstartsrv.
To access the Services Manager on SLES, run the command yast services-manager.
As a rule, the graphical X-Windows environment will not have been enabled on SAP HANA systems so Services Manager will look more like the old MS-DOS screen below. Look grandpa, function keys!
You navigate with the arrow keys instead of the mouse but for the rest, it works the same way.
You can [Enable/Disable] and [Start/Stop] the service.
Disabling the service not only prevents the SAP HANA system to startup automatically when Linux starts but also prevents it to startup at all.
Apart from using Yet Another Setup Tool, you can also directly interface with the services manager using the systemctl command.
In the past, you would work with chkconfig to interface with the system startup and services manager but this has now been replaced with systemctl.
It is a big topic, systemctl and systemd. For those interested in a kinder, gentle introduction, SUSE has published a whitepaper:
With systemctl, you can enable the service and also start it up.
So how does this work?
On Windows, the service implementation would require us to open the registry and get lost in keys and hives but on Linux, fortunately, there is no such thing as a registry; all we have are files.
The systemctl status sapinit command shows us the file concerned: /etc/init.d/sapinit.
The command to start the service is listed: ExecStart=/etc/init.d/sapinit start as is the result of running this command by systemd: status=0/SUCCESS)
The Show Details command in Services Manager outputs the same information.
System initialization works with control groups (CGroup) to manage related services – similar to service dependencies on Windows – and here we can see that sapinit also starts up two SAP Host Agent executables: saphostexec and saposcol (with parameters from the host profile).
The output (log file /var/log/messages) inform us that for saphostexec, a session is opened for user sapadm and for sapinit, one for user hxeadm.
The message Impromptu CCC initialization can be ignored. The SAP Note to see, in fact, is not 1266393 but 2130426 – HDBStart: Impromptu CCC initialization by ‘rscpCInit’.
Description: Start the sapstartsrv
SAPInit is not a program or executable but an executable script file.
Those familiar with SAP Basis Administration will certainly recognize the start/stop implementation of SAP HANA as it is exactly the same as for SAP Netweaver systems, going back to 2005. In fact, when we take a look at the script file /etc/init.d/sapinit, the copyright notice (c) is 1995-2005, long before SAP HANA was released to customer (RTC).
SAPInit is a generic UNIX script with specific code lines for AIX, HP-UX and z/OS, amongst others whereas SAP HANA, of course, only runs on Linux.
At the end of the script, we find the main functions: start, stop, status and restart.
If you want to trace any of the actions, just add trace to the command: sapinit start trace.
In the sapinit file, several functions are defined to support the main functions.
One of the these support functions is read_sapservices which reads the content of yet another file: /usr/sap/sapservices.
Just like SAPInit, SAPServices is also an executable script file.
For SAP HANA, it contains a single line that defines the LD_LIBRARY_PATH environment variable (similar to DLLs on Windows) for the sapstartsrv command.
If you would like to be the Services Manager on a Linux system for a day, you can very well stop and start SAP HANA systems manually using the sapinit command.
To manually start an SAP HANA system, enter, as the root superuser, the command:
This will start the host agent first [saphostexec -start pf=<host_profile>] and next the contents of the sapservices script file will be executed.
We get the same Impromptu CCC initialization output as we saw earlier with systemctl status sapinit (see above).
Here we can see how the start function is implemented in SAPInit, first running saphostexec and then calling function read_sapservices, the contents to be executed in a for loop.
Tracing the sapinit start process, just prints the contents of the sapservices file to the console.
The prompt is returned in a matter of seconds, so it is good to realize that sapinit status informs us about the status of the sapstartsrv process (up, down), not whether the whole SAP HANA system is already up and running.
Below a recording of the output from the top command when SAP HANA, express edition (server + applications) is starting up on a Google Cloud Platform VM. If you practice mindfulness, this may be a good exercise as it takes about 8 minutes for all the processes, services, and applications to be up and running.
We first see the SAP Start Service process starting up the SAP HANA daemon process which, in turn, starts up the other SAP HANA database and support processes (nameserver, indexserver,compileserver, etc.). This takes about 30 seconds. Then, the XSA infrastructure comes up (hdbxs*** processes) and, after some delay, all the java and node runtimes for the different applications hosted by XSA are starting.
If you try to access any of the XSA applications before that time, you are likely to receive an HTTP 503 Service Not Available message.
If you would like to know the current status of sapinit, you can run command
For this status check, sapinit calls the command saphostexec -status first and then proceeds to verify that the sapstartsrv processes listed in sapservices are actually running using the generic UNIX/Linux ps command with some looping, grepping and tailing.
Note that both SAPStartSrv processes have as parent process (PPID) init process (1) and are started as a service, or in Linux speak, as a daemon (-D).
The SAP Host Agent always runs as the sapadm user and only requires a profile (pf=) to get going.
The SAPStartSrv for SAP HANA also specifies a profile (HXE_HDB90_hxehost) and additionally the user to run the process (-u hxeadm). The system I am using here, run SAP HANA, express edition with system ID (SID) HXE, instance number 90, and computer name hxehost.
License to kill
To stop the SAPStartSrv processes enter:
The host agent is stopped first [saphostexec -stop] and politely responds that the process has stopped.
The sapstartsrv for HANA is less informative. All we know is that after some time there is “No process running”.
The reason is – and now we maybe start to understand why we can only run the sapinit command as the superuser root and our prompt is displayed in red, as in alert! warning! stop! blood! – that we have in fact executed the command to kill the SAPStartSrv process.
There are several ways how you can kill (stop, end, terminate) a process on a Linux system and some are nastier than others.
The sapinit stop command performs a kill -2 or kill SIGINT operation, which is relatively harmless and typically triggered with the Ctrl+C combination on the keyboard.
On the contrary, kill -9 or kill -KILL is brutal, lethal and to be avoided at all costs. It just pulls the plug and terminates the process without mercy. Not a good idea for an in-memory database.
Schematically, the process looks like this: with services manager [OS Boot] calling sapinit, reading sapservices, starting sapstartsrv, starting sapstart, starting HDB daemon, starting HDB processes.
We can also show this with the command
ps fx -o ppid,pid,args --sort=ppid
Process sapstartsrv has parent process id (1) or init, the initialisation process. The same is true for the sapstart process.
SAPStart, in turn, starts the SAP HANA watchdog process, HDB daemon, which then starts the other HDB processes.
We also see the different Java runtime processes hosting different Java and Node.js applications.
You may have noticed from the flow graph illustration above that sapstartsrv allows for web service communication. This is, in fact, how you can stop and start an SAP HANA system using a client like the SAP HANA studio, for example.
All you need to do, is to make sure that the TCP port is open between your client and the sapstartsrv process [5xx13 for HTTP and 5xx14 for HTTPS, where xx is the instance number, 90 for SAP HANA, express edition], and provide operating system credentials for the <SID>adm user; hxeadm, with SID=HXE for SAP HANA, express edition.
Below an illustration from the SAP Netweaver documentation where we can see both sapstartsrv for the host agent and sapstartsrv for the SAP instance (in our case SAP HANA).
On an SAP Netweaver system, the agents provide web services that can be used by the browser-based SAP Management Console (Java applet) and the Microsoft Management Console Snap-In (sapmmc.msc).
The browser-based implementation is not available for SAP HANA systems.
However, if you disable HTTP authentication, you can still connect the SAP Management Console on a Windows client to an SAP HANA system instance.
Access points to the sapstartsrv process are listed.
We can start, stop and restart the SAP HANA instance but also, for example, view the startup profile: the PF=<profile_name> we have seen above on several occasions.
The profile lists the SAPSYSTEMNAME, SAPSYSTEM, INSTANCE_NAME and SAPLOCALHOST but none of these parameters are intended to be modified.
The one exception is the parameter Autostart. This parameter controls whether starting the service will also startup the SAP instance.
Consider, for example, a server with two or more SAP HANA installations, different releases or different use cases (training, test), started by an administrator when needed but not all automatically and at the same time when the operating system starts.
Autostart=1 starts the instance when the service starts.
For more information, see:
- SAP Start Service – SAP NetWeaver 7.5
- Infrastructure of the SAP NetWeaver Management Agents – SAP NetWeaver 7.5
- SAP HANA Platform – SAP Help Portal
- Managing Services with YaST – SUSE Doc: Administration Guide
- System Start and Target Managment – SUSE Doc: Administration Guide
- Important Linux Commands – SUSE Doc: Administration Guide
- systemd in SUSE Linux Enterprise 12
Share and Connect
Questions? Please post as comment.
Useful? Give us a like and share on social media.
If you would like to receive updates, connect with me on
|Over the years, for the SAP HANA Academy, SAP’s Partner Innovation Lab, and à titre personnel, I have written a little over 300 posts here for the SAP Community. Some articles only reached a few readers. Others attracted quite a few more.For your reading pleasure and convenience, here is a curated list of posts which somehow managed to pass the 10k-view mile stone and, as sign of current interest, still tickle the counters each month.|