LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   systemctl kill pgm to fast (https://www.linuxquestions.org/questions/linux-general-1/systemctl-kill-pgm-to-fast-4175736383/)

cormanstnl 04-24-2024 10:04 AM

systemctl kill pgm to fast
 
Hi,

I have a java pgm running on a server.
I made a bash script for start the java and an other to stop the programme.

And a call these scripts from a systemd script.

Code:

[Unit]
Description=PONTBASCULEDP
After=mysqld.service

[Service]
Type=oneshot
ExecStart=/opt/middleware/pontbasculedp/start_robot_pontbasculedp.sh
ExecStop=/opt/middleware/pontbasculedp/stop_robot_pontbasculedp.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

The command for ending the program consist to put a value "STOP" on a table and a thread check if the "STOP" is set and if yes, end thread and exist the application.

But when the call of stop_robot_pontbasculedp.sh is executed by systemd, I see that the flag for stopping the pgm is set but systemctl send the SGIKILL or SIFTERM to fast and the process is killed and not ended correctly.

So how to add a wait or somethings like this for ask systemd to wait the end of the program ?

lvm_ 04-24-2024 10:18 AM

Systemd requires ExecStop process to be synchronous, it should not exit until all service process have terminated. If it does systemd immediately kills whatever is left running. Make the stop script wait the proper way or just add 'sleep 10' to it.

cormanstnl 04-24-2024 10:24 AM

Thank you for the idea ... It's working...
I added sleep 30 on my stop script


All times are GMT -5. The time now is 10:16 PM.