Score:0

systemd service definition for SAP (or any other application) start

bj flag

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

cn flag
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](https://www.freedesktop.org/software/systemd/man/systemd.service.html)
Franz avatar
bj flag
Thank you! Anything to say about the [Service] block?
cn flag
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).
Franz avatar
bj flag
Great! Thanks a lot!
Score:0
cn flag

To summarize comments:

Keep it simple!

[Unit]
Description=System Resources for SAP HANA H01
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

Franz avatar
bj flag
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.
cn flag
You're welcome!
Score:0
bj flag

After almost one year of trying and faults I fianaly 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 dummy environment I see my dummy (I use /usr/bin/yes ) processes 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 between in which slice the process is running:

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

Hope this helps! :-)

user1686 avatar
fr flag
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.
Franz avatar
bj flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.