Re: Springboot and systemd, clean shutdown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 02, 2024 at 08:57:52PM +0200, Etienne Doms wrote:
> Hi,
> 
> https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecStop=
> 
> Your curl command just sends an HTTP POST request and waits for the
> reply, but at this point I guess your Spring Boot application is just
> shutting down, and has not yet cleanly terminated.

Ok, this (and others) provides a useful clue.

My hacky way of doing this, and this works for me:

  ExecStop=/usr/bin/curl -X POST localhost:${SERVER_PORT}/shutdown ; /usr/local/sbin/block_on -c -P ${SERVER_PORT}

'block_on' is a script I already had rattling around that blocks until
recources are freed up.  It's not pretty, but does what I needed.

Things I learned; these are documented, but I never really grasped some of
the subtleties:

  I didn't realize that ExecStart and ExecStop could be lists of
  commands. I've been relying on multiple ExecStopPost directives to
  introduce 'block_on', as I needed a syncronous way for 'systemctl
  stop webapp.service' to actually block until the process has
  stopped.

  I didn't realize the sense of success/failure only reflected
  ExecStop, not ExecStopPost directives.

> I remember in a past life having to deal with POSIX signahandling in a
> Java application and I ended up with Runtime.addShutdownHook()

I would have preferred the Java developers implemented a signal
handler, but that's out of my control.

For the record, many other sites seems to propose masking the 143 issue with

  SuccessExitStatus=143

but's that's clearly bogus. :/

I wish there was a systemd-pure way of implementing 'block until
PID exits'.

-- 
Brian Reichert				<reichert@xxxxxxxxxxx>
BSD admin/developer at large	



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux