I'm trying to found solution how run script before shutdown/reboot is initiated in RedHat7. I need to correctly shutdown SAP database when I'm shuting down or rebooting server.

Script for SAP shutdown take 3-4minutes, but shutdown of system is very quick -it mean that RedHat kill all proceses imediatly...


systemd sap.service is:

Description=Shutdown SAP
Before=shutdown.target reboot.target halt.target



As I see in shutdown log - database wasnt shutted down correctly:

Checking ADA Database
setTrace: false
J2EE Database is not available

Can you help me?

Thank you


Edit 21.10.2015:

I moved to next step - it is working better, but still not correctly:

[Unit] Description=SAP sluzba After=network.target sshd.target Wants=network.target sshd.service [Service] Type=simple RemainAfterExit=true Environment="SAPSYSTEMNAME=RH7" "HOST=cz-brn1-rh7" "HOME=/home/rh7adm" "PATH=/sapdb/clients/RH7/bin:/sapdb/programs/bin:/usr/lib64/qt-.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/sap/RH7/SYS/exe/uc/linuxx86_64:/usr/sap/RH7/SYS/exe/run:/home/rh7adm:." "DIR_LIBRARY=/usr/sap/RH7/SYS/exe/run" "LD_LIBRARY_PATH=/usr/sap/RH7/SYS/exe/run:/usr/sap/RH7/SYS/exe/uc/linuxx86_64:/sapdb/clients/RH7/lib" "RSEC_SSFS_DATAPATH=/usr/sap/RH7/SYS/global/security/rsecssfs/data" "RSEC_SSFS_KEYPATH=/usr/sap/RH7/SYS/global/security/rsecssfs/key" KillMode=none SendSIGKILL=no TimeoutSec=5min TimeoutStopSec=5min User=rh7adm Group=sapsys ExecStart=/usr/sap/startsap ExecStop=/usr/sap/stopsap
[Install] WantedBy=graphical.target

Here is stopsap script:

#!/bin/bash date >> /usr/sap/stopsap.log; /usr/sap/RH7/SYS/exe/uc/linuxx86_64/stopsap >> /usr/sap/stopsap.log 2>&1; whoami >> /usr/sap/stopsap.log;

J2EE Database is running See logfile /home/rh7adm/JdbcCon.log stopping the SAP instance J28 Shutdown-Log is written to /home/rh7adm/stopsap_J28.log /usr/sap/RH7/J28/exe/sapcontrol -prot NI_HTTP -nr 28 -function Stop Instance on host cz-brn1-rh7 stopped Waiting for cleanup of resources..................................................................................................................................................

and here it stuck for that 5 minutes.. Shutdown script never finish:(

Can I trace how gone shutting down of my sap. service?

Thank you..

  • hm, ExecStart=/bin/true. How do you start your database? Oct 9, 2015 at 2:45
  • Hi, I'm always start database manually with SAP. Oct 9, 2015 at 7:47
  • Why do you start it manually? Is SAP a doubleforking process? You can set ExecStart=cmd-to-start and remove Before=. Unless DefaultDependencies= is set to false, service units will implicitly have dependencies of type Requires= and After= on basic.target as well as dependencies of type Conflicts= and Before= on shutdown.target. These ensure that normal service units pull in basic system initialization, and are terminated cleanly prior to system shutdown. Oct 9, 2015 at 8:16
  • I tried, it without Before and with ExecStart=/usr/sap/startsap but without success. su[715]: (to rh7adm) root on none Oct 09 11:26:19 cz-brn1-rh7 su[715]: pam_systemd(su-l:session): Failed to create session: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. scripts for startsap or stopsap cannot be run as root but as sapadm (in this case rh7adm) also tried with DefaultDependencies=false still without success... Oct 9, 2015 at 9:33
  • Try the directive User=. Is /usr/sap/startsap a shell script? can you post it? Oct 9, 2015 at 10:25

3 Answers 3


Try changing the TimeoutStopSec value in the unit file. The default is set by /etc/systemd/system.conf in the DefaultTimeoutStopSec entry (my system has it as 90s). You can set TimeoutStopSec=0 to disable the timeout entirely (may hang your shutdown if the script doesn't terminate), or pass a larger value that allows the stop script to finish completely.

  • Hello, this not worked for me :( I'm thinking maybe about some dependencies - its looklike database is already killed when my shutdown script trying to shutdown database... reason: igswd_mt killed by SIGABRT time: Fri 09 Oct 2015 09:36:08 AM CEST cmdline: ig.sapRH7_J28 Oct 9, 2015 at 8:17
  • Also I found this (i tried values 250 or 0, still same): sap.service - Shutdown SAPu Loaded: loaded (/usr/lib/systemd/system/sap.service; enabled) Active: active (exited) since Fri 2015-10-09 10:13:16 CEST; 2min 0s ago Main PID: 715 (code=exited, status=0/SUCCESS) CGroup: /system.slice/sap.service Oct 09 10:13:16 cz-brn1-rh7 systemd[1]: Started Shutdown SAPu. Oct 09 10:15:16 cz-brn1-rh7 systemd[1]: [/usr/lib/systemd/system/sap.service:5] Unknown lvalue 'TimeoutStopSec' in section 'Unit Oct 9, 2015 at 8:18
  • And by the way: /etc/systemd/system.conf are all values commented: #TimerSlackNSec= #DefaultTimeoutStartSec=90s #DefaultTimeoutStopSec=90s #DefaultRestartSec=100ms Oct 9, 2015 at 9:41
  • The commented values in /etc/systemd/system.conf denote the defaults. If a value there is commented, then it's probably the one in effect through systemd's compiled-in behavior.
    – Tom Hunt
    Oct 9, 2015 at 15:02
  • TimeoutStopSec goes under the [Service] heading, not [Unit].
    – Tom Hunt
    Oct 9, 2015 at 15:03

Ok problem was in environment:

correct definition of sap.service is:

[Unit] Description=SAP sluzba After=network.target sshd.target Wants=network.target sshd.service [Service] Type=simple RemainAfterExit=true Environment="HOSTNAME=cz-brn1-rh7" "SAPSYSTEMNAME=RH7" "HOST=cz-brn1-rh7" HOME=/home/rh7adm" PATH=/sapdb/clients/RH7/bin:/sapdb/programs/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/sap/RH7/SYS/exe/uc/linuxx86_64:/usr/sap/RH7/SYS/exe/run:/home/rh7adm:." "DIR_LIBRARY=/usr/sap/RH7/SYS/exe/run" "LD_LIBRARY_PATH=/usr/sap/RH7/SYS/exe/run:/usr/sap/RH7/SYS/exe/uc/linuxx86_64:/sapdb/clients/RH7/lib" "RSEC_SSFS_DATAPATH=/usr/sap/RH7/SYS/global/security/rsecssfs/data" "RSEC_SSFS_KEYPATH=/usr/sap/RH7/SYS/global/security/rsecssfs/key" KillMode=none SendSIGKILL=no TimeoutSec=5min TimeoutStopSec=5min User=rh7adm Group=sapsys ExecStart=/usr/sap/startsap ExecStop=/usr/sap/stopsap [Install] WantedBy=graphical.target


I had a similar need for executing a script prior to my Oracle DB's being shutdown and thought I'd share my findings here in case others come upon this same post looking for a resolution....

To me, it appears that Oracle's oracle-ohasd.service never shuts down the database cleanly. But regardless of whether oracle db shutdown cleanly or not, I want my script to execute the DG Switchover and OEM Blackout of this node prior to oracle-ohasd.service being executed. So here's what I did.

I have two services declared.

WDOracle-shutdown.service - This handles executing my pre-shutdown scripts. The key for me to get this to work was adding "Before=WDOracle-shutdown.service" to the oracle provided "oracle-ohsasd.service" and having "After=oracle-ohasd.service" in my WDOracle-shutdown.service. The "Before, Requires, and RequiresMountsFor" were probably also needed in my WDOracle-shutdown.service, but adding the "Before=WDOracle-shutdown.service" in the oracle provided "oracle-ohasd.service" is the final step that I did to get it working.

WDOracle-db.service - Is the service that removes my OEM blackouts after the server and databases start back up. It also checks the lifecycle status in OEM and will adjust it according to whether the DB_ROLE is Primary or Physical Standby.

Here are my settings for the 3 services involved.

cat /usr/lib/systemd/system/WDOracle-shutdown.service

Description=Oracle Blackout Creation
Before=shutdown.target reboot.target halt.target
Requires=network-online.target network.target multi-user.target oracle-ohasd.service
RequiresMountsFor=/opt/apps/oem /opt/apps/oracle /opt/apps/grid

ExecStop=/opt/apps/oracle/scripts/WDOracle-db.sh stop


cat /etc/systemd/system/WDOracle-db.service

Description=WD Oracle Non-Prod DB service
After=network-online.target remote-fs.target autofs.service oracle-ohasd.service

ExecStart=/opt/apps/oracle/scripts/WDOracle-db.sh start


cat /etc/systemd/system/oracle-ohasd.service

Description=Oracle High Availability Services
After=network-online.target remote-fs.target autofs.service
Wants=network-online.target remote-fs.target

ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
ExecStop=/etc/init.d/init.ohasd stop >/dev/null 2>&1 </dev/null



WantedBy=multi-user.target graphical.target

You must log in to answer this question.

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