2

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...

my

systemd sap.service is:

[Unit]
Description=Shutdown SAP
Before=shutdown.target reboot.target halt.target

[Service]
ExecStart=/bin/true
ExecStop=/usr/sap/stopsap
RemainAfterExit=true
KillMode=none

[Install]
WantedBy=multi-user.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

Ivo

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? – Evgeny Vereshchagin Oct 9 '15 at 2:45
  • Hi, I'm always start database manually with SAP. – Ivo Jedinečný Oct 9 '15 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. – Evgeny Vereshchagin Oct 9 '15 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... – Ivo Jedinečný Oct 9 '15 at 9:33
  • Try the directive User=. Is /usr/sap/startsap a shell script? can you post it? – Evgeny Vereshchagin Oct 9 '15 at 10:25
2

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 – Ivo Jedinečný Oct 9 '15 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 – Ivo Jedinečný Oct 9 '15 at 8:18
  • And by the way: /etc/systemd/system.conf are all values commented: #TimerSlackNSec= #DefaultTimeoutStartSec=90s #DefaultTimeoutStopSec=90s #DefaultRestartSec=100ms – Ivo Jedinečný Oct 9 '15 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 '15 at 15:02
  • TimeoutStopSec goes under the [Service] heading, not [Unit]. – Tom Hunt Oct 9 '15 at 15:03
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.