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

3
  • You don't need all the Before lines. Just put After=network-online.target. You also don't need the Conflicts. This is overly complicated! There are examples here
    – shearn89
    Commented Feb 21, 2022 at 8:41
  • Thank you! Anything to say about the [Service] block?
    – Franz
    Commented Feb 22, 2022 at 15:00
  • Keep it simple! :D Go with Type, Restart, ExecStart/Stop, and add things as required. I think most of your values there are defaults (e.g. syslog).
    – shearn89
    Commented Feb 22, 2022 at 15:02

2 Answers 2

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

4
  • 1
    I know I am very late but thank you very much for your answer. Yes, KISS (keep it stupid simple) is the very best way. This is more or less the configuration I have worked out with RedHat Support. I did not use the After= configuration.
    – Franz
    Commented Feb 22, 2023 at 12:02
  • You're welcome!
    – shearn89
    Commented Feb 22, 2023 at 17:16
  • I wonder: Isn't there any special environment needed, and is the database actually run as root? Maybe see also serverfault.com/q/1156528/407952
    – U. Windl
    Commented Mar 20 at 8:50
  • For SAP, maybe, but the title does mention 'or any other application' and my answer was intended to be generic as a starting point. The main point was that OP had a very overcomplicated script when the above would be a much better template to work from.
    – shearn89
    Commented Mar 20 at 16:56
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

2
  • That's part of why sudo/su/runuser usage is somewhat frowned upon in systemd, when it already has a working User= option built in for that purpose. But even more than that, if the application consists of two services (i.e. two primary processes, like your "db" and "app"), it's really preferred to have two .service units for it as well – each with its own User= and each having its startup and shutdown properly ordered against the rest. Commented Feb 22, 2023 at 19:05
  • as long as it's my script I can split this into two scripts starting DB and APP; if I get a script from the vendor it's not in my hands. eg. startsap script
    – Franz
    Commented Feb 23, 2023 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .