Hi all,
What is the best way to stop an application via systemd (in my case a java app) using a script that waits up to a max. 1 minute for the java application to close correctly when the reboot/halt/poweroff command is invoked ?
We had thought of a unit like this:
The application starts correctly and if I call the same script from cli with the "stop" parameter (sudo systemctl stop myservice.service), the Java application stops correctly.
When I use the reboot/halt/shutdown command, systemd does not wait for the Java application to properly close.
Raspberry restarts/shuts down immediately without waiting for the Java application to close properly.
the function that stops the java application and possibly closes it after a minute present in myscript.sh is the following:
I was wondering if you have any suggestions for me to solve my problem ?
Thank you.
What is the best way to stop an application via systemd (in my case a java app) using a script that waits up to a max. 1 minute for the java application to close correctly when the reboot/halt/poweroff command is invoked ?
We had thought of a unit like this:
Code:
[Unit]Description=java boot and shutdown serviceAfter=syslog.target network-online.target[Service]Type=simpleExecStart=/etc/init.d/myscript.sh startExecStop=/etc/init.d/myscript.sh stopRemainAfterExit=yes[Install]WantedBy=multi-user.target
When I use the reboot/halt/shutdown command, systemd does not wait for the Java application to properly close.
Raspberry restarts/shuts down immediately without waiting for the Java application to close properly.
the function that stops the java application and possibly closes it after a minute present in myscript.sh is the following:
Code:
shutdown_application() { ((sleep 2; echo "app shutdown"; sleep 1; echo "bye bye"; sleep 1;)|nc 127.0.0.1 50000 > /dev/null 2>&1) & for I in 1 2 3 4 5 6 7 8 9 10 11 12; do echo "$I.." sleep 5 done killall -9 $my_java_app}
Thank you.
Statistics: Posted by skcasb — Fri Feb 02, 2024 3:31 pm — Replies 1 — Views 66