Skip to Content

Start/Stop SAP with systemd script - Linux 7 (RHEL7)

Hi,

I'm trying to create a systemd service script on RHEL7 to shutdown/startup the SAP app automatically if the server gets rebooted. I saw already some forums that talk about it, but didn't find a solution that works for my script.

Below, is the systemd service script that I'm using and it works for the startup of the SAP app, but not for the shutdown... As soon as I try to reboot the server, all the services are killed immediately without running the "ExecStop" command on the script.


Could you give me some light on how to solve this issue?

[Unit]
Description=SAP.service
After=local-fs.target network.target network-online.target

[Service]
Type=simple
RemainAfterExit=true
Environment="SID1=SID" "DAA=DAA"
KillMode=none
SendSIGKILL=no
ExecStart=/usr/bin/python /usr/sap/scripts/SAPstart.py
ExecStop=/usr/bin/python /usr/sap/scripts/SAPstop.py
TimeoutSec=60

[Install]
WantedBy=multi-user.target


Thanks in advance,

Carlos

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Sep 28, 2018 at 02:26 PM

    Any ideas?

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 28, 2018 at 02:55 PM

    Check your service with systemctl command, also check if the service enable.

    # systemctl <your service> stop

    I called stopsap on "ExecStop" after calling <sid>adm user environment and it worked for me.

    Check the below answer as well as

    https://answers.sap.com/questions/68268/systemd-configuration-for-startingstopping-sap.html?childToView=199140#answer-199140

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 28, 2018 at 03:43 PM

    Hi Prasanta,

    Thanks for your answer. I just verified the service and it is enabled.

    In my case I can't use just the "stopsap" command because I need to start/stop other things in the server, reason why I have a custom script for it.

    I just saw that when rebooting the server with the command "sudo systemctl reboot", the "ExecStop" on my service is called, but it is not able to shutdown the application completely because the "sudo systemctl reboot" kills all the services/process immediately. It seems that it is not taking in consideration the "Timeout" parameters that I'm putting on the service below.

    This is how I have my service now. If you have any new ideas, please let me know. Thank you!!

    [Unit]
    Description=SAP.service
    After=local-fs.target network.target network-online.target
    
    [Service]
    Type=simple
    RemainAfterExit=true
    Environment="SID1=SID" "DAA=DAA"
    KillMode=none
    SendSIGKILL=no
    TimeoutSec=2min
    TimeoutStopSec=2min
    ExecStart=/usr/bin/python /usr/sap/scripts/SAPstart.py
    ExecStop=/usr/bin/python /usr/sap/scripts/SAPstop.py
    
    [Install]
    WantedBy=multi-user.target
    
    
    

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 02, 2018 at 02:37 PM

    Hi Carlos

    1. Sleep written on stopsap, not sure how you stopping SAP. If you are calling it internally (i.e. execute stopsap and inside SAPstart.py) sysmd may not wait and marked service as down and proceed with restart.

    2. systmectl should start the SAP e.g. you started SAP using command startsap and you trying to stop using systemctl it may fail as the service status inactive. Service should be completed and active status before you try with systemctl <service> stop. Please check the below link for more details

    ExecStop=

    If possible use separate service to stop the other things.

    Let me know if it worked for you !

    Thanks & Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Please note that it works correctly if I test it with the following commands:

      systemctl stop SAP.service

      systemctl start SAP.service

      systemctl restart SAP.service

      The issue only occurs when I reboot the server with the "systemctl reboot" command.

  • Feb 07 at 01:43 PM

    Hi Carlos,

    facing the same problem !!

    Did you overcome ? if yes then how

    Thanks

    Moti

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 08 at 08:07 PM

    Hi Moti,

    Not yet . I'm still having issues to shutdown SAP with systemd. I tried already different things, but no luck. If you find a solution, please let me know. I will do the same if I figure it out how to solve it.

    Thanks,

    Carlos

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20 at 09:03 AM

    Hi Carlos,

    We are still straggling with this issue .

    I opened an incident with SAP here is their reply

    "with system, the sapinit script (and processes started by it) are placed in user slice. Normally system allows only a 90 seconds for these processes to stop before killing them.

    SUSE provides a workaround for such situation: https://www.suse.com/de-de/support/kb/doc/?id=7022671

    The KBA is described in the context of HA cluster, but it can be applied in the same way for standalone systems as well. I recommend you to try it first in a test environment"

    We have implemented the SUSE KBA but still the stopsap (sapinit stop) is not triggered at reboot

    You can try and see, maybe you will have sucess. Please report if you did

    Thanks

    Moti

    Add comment
    10|10000 characters needed characters exceeded