[Lazarus] Linux service
Michael Van Canneyt
michael at freepascal.org
Wed Nov 27 15:06:59 CET 2013
On Wed, 27 Nov 2013, Patrick Chevalley wrote:
> Hi,
>
> To enable your program to react to signal you need to use fpSigAction.
> See here for usage: http://www.freepascal.org/docs-html/rtl/baseunix/fpsigaction.html
>
> Instead of SigUsr1 in the example you can register a procedure for SIGTerm to handle a termination request.
> You can also add a procedure for SIGHUP if you want to implement a "service .. reload" action.
> The complete list of signal is in rtl/linux/signal.inc
That is exactly what the daemon code does.
Procedure DoShutDown(Sig : Longint; Info : PSigInfo; Context : PSigContext); cdecl;
begin
Application.StopDaemons(True);
Application.Terminate;
end;
Procedure SysInitDaemonApp;
Var
old,new : SigactionRec;
begin
New.sa_handler:=@DoShutDown;
fpSigaction(SIGQUIT, at New, at Old);
fpSigaction(SIGTERM, at New, at Old);
fpSigaction(SIGINT, at New, at Old);
end;
Michael.
More information about the Lazarus
mailing list