[Lazarus] Linux service

Antonio Fortuny a.fortuny at sitasoftware.lu
Wed Nov 27 15:45:32 CET 2013


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, at New, at Old);
>   fpSigaction(SIGTERM, at New, at Old);
>   fpSigaction(SIGINT, at New, at 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 at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>







More information about the Lazarus mailing list