Hello and welcome to the SAP HANA Academy.
The topic of this video tutorial series is Getting Started with SAP HANA on the Google
Cloud Platform and in this video, I will show you how HANA is started at system boot and
stopped at power off with sapinit.
Hi, I am Denys van Kempen.
In the last couple of videos, we looked at how you can start and stop an SAP HANA system.
We have seen how you can use graphical tools like the SAP HANA cockpit and HANA studio,
and we have also looked at the HDB script and the sapcontrol utility.
In this last video on the start/stop topic, I will explain how sapinit works.
If you are less familiar with Linux system administration and have no experience with
SAP Basis administration this may be a bit of an advanced topic.
However, the objective here is just to show you how it works, how sapinit is implemented.
Just like with sapcontrol we talked about in the previous video, sapinit is common to
all SAP systems, so it is not specific to SAP HANA in particular.
Works the same on an SAP Netweaver ABAP application server, for example.
OK.
I am connected here to the Google Cloud Platform Console and have started the SAP HANA express
edition VM we created with Cloud Launcher.
I am connected with SSH and done the substitute user to hxeadm.
Now, I will assume that you have watched, or at least scanned, the previous videos on
the start/stop topic, so if I am using terminology or perform some action that is completely
new to you, you might want to review them.
We have seen that our SAP HANA express edition system HXE starts automatically when we start
the VM and - well, we have not seen but at least we may hope - that our system is also
properly stopped when we stop the VM using the stop button here in the console.
So, how does this work?
Well, on UNIX and Linux systems, and SUSE Enterprise Server is no exception, there is
program called systemd which is started at boot time by a process named init with number 1.
We have discussed this in the video about HDB when we walked the process tree.
The d in systemd stands for daemon, the equivalent of a Windows services.
You can query the configuration of systemd on the command line with chkconfig or, more
appropriately on the latest SUSE Linux systems, with systemctl.
You will need root privileges to work with these utilities but you can easily make mistakes
as root with potentially disastrous consequences - it is no coincidence that Google has coloured
the prompt in red for us - so let’s use yast (yet another system tool) the equivalent
of, say, the Windows Control Panel or System Preferences on the Mac.
The module is called Services Manager, so with yast services-manager we can open it directly.
The runtime level Graphical Interface should be selected, this is level 5, the default.
With the [Tab] key you can navigate between the frames (shift-tab to go backwards) and
then use the arrow keys to go up or down.
Navigation is a bit easier in the graphical version of yast where we can use the mouse,
here we have to arrow all the way down, until we find sapinit: Enabled and Active.
With 3 tabs (or alt+D) we get the details and we can see that sapinit will start sapstartsrv
through /etc/init.d/sapinit which is the startup script or program.
We can also see that the control group for the service also includes the saphostexec(uter)
and sapo(perating)s(ystem)coll(ector), two executables that just like sapstartsrv are part of the
SAP host agent installed on any SAP system.
We also see a selection of the log file /var/log/messages
with the familiar, by now, “Impromptu CCC” message.
You can Start/Stop sapinit or Enable/Disable it.
Disabling means that the sapstartsrv program will not start as a background service.
It does not mean that HANA will be stopped if it is currently running or that you can
no longer start HANA if it is stopped.
It just means that the next time you start Linux, HANA will not start automatically.
Start/Stop sapinit will actually stop sapstartsrv and with it the whole HANA system.
Maybe as a reminder - if we look at the process tree,
we can see that sapstartsrv is the parent of all the HDB processes.
Stop sapstartsrv and you stop everything.
Let’s take a look at sapinit with cat.
Copyright 1995-2005, it is pretty old (or mature, I guess, I should say).
If we go all they way to the end, we can see that it takes the following arguments: start,
stop, status and restart.
It is a bit similar to the HDB script that calls sapcontrol, although sapinit works completely different.
Sapcontrol worked with the instance number and functions (web service calls)
but if we scroll up a bit to the start section of sapinit, we can see that it loops through the output
of read_sapservices and if we scroll up a bit more, we can see that this in fact concerns
a file /usr/sap/sapservices
so, let’s take a look at sapservices.
(q for quit)
Here we have it. We see a single command, in fact,
setting the environment variable LD_LIBRARY_PATH
(Windowswould use the registry to point to the DLL’s; same thing here)
and then here we have sapstartsrv
with a profile, a -D upper case and a -u hxeadm.
-u is the user name that will run the process.
and if we run sapstartsrv with a -h, help,
we can see that the -D will run the program as a daemon, as a service,
and that pf= points to the start profile.
Before we check out the start profile, let’s first recap what we have seen so far.
When our Linux system starts, systemd, the services manager, will first start sapinit;
sapinit then reads, or I should say, executes, line for line, whatever is in the sapservices file.
For our SAP HANA express edition system, there is only a single entry
and this will run sapstartsrv with the start profile HXE_HDB90_hxehost, as the user hxeadm, as service.
If we quickly switch for an HDB info, we can see that here.
Systemd started by init, that’s process number 1
Then we have sapstartsrv started as user hxeadm which, as a service, starts the sapstart process
both using the same start profile.
With the information from the profile, the generic sapstart process than starts the HANA
HDB daemon process which in turn will start all the other hdb / HANA processes.
OK.
Quick look at the profile used by sapstartsrv.
Looks a bit complex but, again, it is pretty much the same for any other SAP system:
Basis administrators will recognize it.
We can see the system name, the SID, HXE;
the server or host name, hxehost; the system number, 90
Typically, there is no need to modify the startup profile.
HANA system parameters, in fact, are located elsewhere.
If we briefly switch to studio, for example, we have the Configuration tab with a whole
list of system parameter files; they all have the INI extension.
There is one for each HANA service.
You will recognise nameserver, indexserver, compileserver and so on -
or at least, you should by now and if not, you might want to take a look at the video about cockpit and studio.
These are all the system parameter files and you can use the SQL interface
- ALTER SYSTEM ALTER CONFIGURATION -
to modify them (or have studio or HANA cockpit do this for you using your mouse, same thing).
Now, there is one parameter we cannot change using SQL, cockpit or studio, and that is
this one here, in the profile: Autostart.
1 means yes or true, 0 means no.
This parameter controls whether the instance should start when sapstartsrv starts.
When you install HANA - here we have the screen - you can select to
Restart system after machine reboot.
This will set Autostart to 1, otherwise, and that’s the default, it will remain at 0, no.
Now, to be frank, it is not so much about restart and reboot, in fact, it simply configures
if this HANA instance should start with the machine, the computer, the server, or not.
So, if you do not want HANA to start automatically, you have two options.
You can either set Autostart=0 in the startup profile for HXE_HDB90 hxehost, or you can
disable sapinit on the server using yast (or systemctl on the command line).
Keep in mind, that sapinit, sapstartsrv and sapcontrol have been designed to manage entire
SAP system landscapes.
You may have a system running on multiple servers, a distributed system in SAP terminology,
and you may have multiple systems running on a single server, or both.
Some instances running on one host and other instances running on another.
So you need to be able to disable auto startup on a single server for all instances, say
for server maintenance (hardware or operating system) or just disable the startup of a single
instance, say for an software upgrade.
That’s why we have both.
OK.
That’s it for startup.
What about shutdown?
You may have noticed that when you select Stop for the HANA VM, you are immediately
disconnected from your shell.
So, you cannot really monitor what goes on.
What we can do, however, is simulate what happens to the HANA instance, when we stop
the VM.
I have opened three SSH’s sessions: one to stop the service,
one to monitor the HANA instance, and one to view system messages.
For this we can do a tail -f on /var/log/messages.
This will just show us whatever gets written to the system log file in real-time.
To monitor, we will do the top -u hxeadm (we have already seen this) and in the third shell
we will run our commands.
The command to interact with systemd is system control, systemctl.
I can run, for example, the systemctl command with status sapinit.service
This will give us the same output we just saw in yast.
When the system receives a power off signal (this is what will happen when we click stop
for the VM in the cloud console) systemd will proceed to stop all the installed services
and this includes sapinit.
The command is systemctl stop sapinit.service Goes pretty quick.
Much quicker, in fact, then with sapcontrol function Stop for a soft stop or even when
compared with sapcontrol function Shutdown for a hard stop (we saw this in the previous
video) In a moment, we will understand why this it
the case.
Start works the same way.
I will fast forward a bit.
We saw that systemd runs sapinit, so this would be the same.
/etc/init.d/sapinit stop The output is not very verbose, you will just
get Stopping…Stopped So, I will add the trace parameter here, to
get some more output: sapinit stop trace
Now we can see that the command that is actually executed is kill SIGINT on the process with
the ID of the sapstartsrv Kill sounds scary, maybe, but on Linux with
a kill -2, a SIGINT, the operating system will gently ask a process to terminate gracefully,
cleaning up all resources (sockets, any child processes, deleting temporary files and so
on) As sapstartsrv is the parent of HDB daemon
which in turn is the parent of the other HANA processes, a kill SIGINT on sapstartsrv will
also stop all other HANA processes properly.
If we substitute user, once again, to hxeadm and run HDB, you can see that one of the options
is kill, kill-sig, to be precise.
Kill -9, SIGKILL, is another story and should definitely never be used in productive systems.
It just pulls the plug.
Linux will not ask sapstartsrv anything but it will just terminate the process.
We may not even get a core dump when the contents of what's in memory are written to disk.
So, that’s how HANA is stopped.
With a SIGINT.
Now, you may not feel that comfortable with all this killing business, so what you always
could do, is, before you stop the VM, just stop HANA first.
Cockpit, studio, the offline cockpit, HDB stop, or sapcontrol with function stop.
You know now how to do this.
In fact, when we stop the VM in cloud console, we get this message: Stop shuts down the instance.
If the shutdown doesn't complete within 2 minutes, the instance is forced to halt.
(in other words, we will try kill -2 first but if this takes to long we will do a kill
-9).
This can lead to file-system corruption.
Well, in case of HANA, it could be even worse.
You have an in-memory database with 100s of users, 1000s of transactions, business data,
and you just pull the plug because you cannot wait 2 minutes?
Not a good idea.
If you value what is stored in HANA, make sure to stop the system properly first with
one of the options we discussed.
Stop VM is not one of them.
In the next video, we will take a look at another command line tool, the SAP HANA interactive
terminal: hdbsql.
You can find more video tutorials on our YouTube channel.
If you would like to be informed about new video tutorials, please subscribe to our channel.
You can connect with us on LinkedIn or follow us on Twitter, as well for updates.
And we also have a page on Facebook and Google+.
If you are watching this video on YouTube, do not hesitate to leave your comments to
the video page and, if you like, give us your vote on his video.
Thank you for watching.