Le 27/11/2013 15:06, Michael Van Canneyt a écrit :


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,@New,@Old);
  fpSigaction(SIGTERM,@New,@Old);
  fpSigaction(SIGINT,@New,@Old);
end;
Well, all this is already running. I managed to trap SIGTERM and SIGHUP to start the program shutdow an the config reload respectively and it works (# ./my_program -r & in background). My only trouble was that the program looked like to be hung after it completely finished with its task (seen in the log file).
Now, thanks to some misterious power (maybe the Force ?) doing:
# bash -x my_service_script start
launches the service: new log started, all init tasks done, responds to requests and ... waits for jobs
# bash -x my_service_script stop
oh miracle, runs as well: the log file reflects all the tasks done on closing, the pidfile has gone and the process too ! (BTW, if you know some other good god who responds so fast that I could invoke, please let me know 8-) no Michael, not your turn yet) I suspect that I wrote (or delete) something in the script that made it to work. Last step, install a normal service into the UBUNTU box: this should be a piece of cake
Thanks anyway.

Antonio;


Michael.

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus





--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to