Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2020-06

Making a Linux systemd service, how does one handle the shutdown?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have read that a systemd service on Linux will be taken down by the service manager using kill -TERM, i.e. the application is given a chance for a clean shutdown.

So my question is:
How/where do I implement a handler for the terminate message in a FreePascal console application (no GUI or form available)?

I have never done anything similar to this but I think that this might be a way to solve my problem of porting a Windows TService application to Linux by changing the framework from the Delphi TService to a simple program...

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 7 lines
I have read that a systemd service on Linux will be taken down by the service manager using kill -TERM, i.e. the application is given a chance for a clean shutdown. So my question is: How/where do I implement a handler for the terminate message in a FreePascal console application (no GUI or form available)?

https://www.freepascal.org/docs-html/current/rtl/sysutils/hooksignal.html

or

https://www.freepascal.org/docs-html/current/rtl/baseunix/fpsigaction.html You should install handlers for SIGQUIT/SIGTERM/SIGINT

The hooksignal internally uses fpsigaction, by the way.

Michael.

Reply by email