0

I have issues to configure a systemd service for starting and stopping SAP (or any other appliaction). I am new to configuring systemd services and please have mercy asking "stupid" questions.

What I want/plan:

The appliaction in this case SAP is installed on local disks mounted in /local/hana/H01 and /local/hana/H01/DB; these are filesystems, which is mounted by fstab.

There is a script that starts SAP which is located in /local/hana/H01/bin/hana. If you call this script with parameter 'start' it will start SAP or with 'stop' it will terminate SAP. This script will terminate after SAP is started, but SAP processes will remain online.

There is an additional NIC configured for this SAP instance eth0:1; SAP should start after that NIC is available. SAP admins find it convenient to login via ssh to a host to check issues, so if SAP doesn't shut down they want to connect via ssh to check; sshd should not terminate before SAP/Appliaction is down.

/local/hana/H01/bin/hana (or any other appliaction script) will start commands with timeout script to prevent a lock.

I used to use the init.d framework and used runlevel 4 to start my appliactions late in the boot process.

I have created a service configuration, wich I re-used from an existing service, so I don't understand all the options and dependencies yet. Do I need these runlevel?.target dependencies? It was in the sample file.

[Unit]
Description=System Resources for SAP HANA H01
Requires=local-fs.target
After=local-fs.target
Before=runlevel2.target
Before=runlevel3.target
Before=runlevel4.target
Before=runlevel5.target
Before=shutdown.target
Requires=network.target
After=network-online.target
After=network.service
After=sshd.service
After=local-fs.target
Conflicts=shutdown.target reboot.target

[Service] Type=forking Restart=no StandardOutput=syslog StandardError=syslog+console TimeoutSec=0 IgnoreSIGPIPE=no KillMode=process RemainAfterExit=yes ExecStart=/local/hana/H01/bin/hana start ExecStop=/local/hana/H01/bin/hana stop

[Install] WantedBy=multi-user.target

Did I miss anything? too much? Any suggestions on what I should add or drop?

Thanks Fran

U. Windl
  • 478
Franz
  • 3

2 Answers2

1

To summarize comments:

Keep it simple!

[Unit]
Description=System Resources for SAP HANA H01
Requisite=network-online.target
After=network-online.target

[Service] Type=forking Restart=no ExecStart=/local/hana/H01/bin/hana start ExecStop=/local/hana/H01/bin/hana stop

[Install] WantedBy=multi-user.target

Should do as a start, and iterate from there as needed. More examples: the man pages

Updated 2024-03-19 - edited to add Requisite, reasons being noted here on SF

shearn89
  • 3,610
0

After almost one year of trying and faults I finally found out why my processes die before my shutdown scripts:

So this is how I start the DB and HANA. Please note the different options -u and -l to runuser!

root# cat /local/hana/H01/bin/hana
#!/bin/bash
# simplified version of the start/stop script

runuser -u h01db /local/hana/H01/bin/hanadb.sh start runuser -l h01hana /local/hana/H01/bin/hanaapp.sh start

In my test scenario I see my dummy processes (I use /usr/bin/yes <parameter>) are running - perfect!

root# ps -elf | grep yes | grep -v grep
h01db   66925      1 95 13:12 ?        00:00:01 /usr/bin/yes dbstart
h01hana 66948      1 93 13:12 ?        00:00:01 /usr/bin/yes appstart

But there is a huge difference regarding the slice the process is running in:

root# systemd-cgls
|-1 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
|-user.slice
| |-user-3001.slice
| | `-session-c15.scope
| |   `-66948 /usr/bin/yes appstart
----- uninteresting stuff -----
`-system.slice
  |-myapp.service
  | `-66925 /usr/bin/yes dbstart
  |-node_exporter.service
----- more uninteresting stuff -----
  • The process in system.slice will be stopped by the ExecStop= command
  • The process in user.slice will be killed by systemd itself!

More information: see manpage of runuser and systemd-cgls

U. Windl
  • 478
Franz
  • 3