Sign in Join

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

Mailing lists / fpc-pascal / 2020-04

Best practice porting a Windows service application to Linux?

5 messages · 4 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 this old (dev 2004-2008) service application for Win32, which I hope to migrate/port to Linux.

It was written in Delphi7 on WinXP at the time and I want to move it to a Debian based Linux.

Obviously stuff like handling control data via Windows Registry etc has to be rewritten as well as implementing handling of serial port communications, which used an external Delphi Windows-only component, and TCP/IP socket comm which was done using TServerSocket at the time. For TCP/IP I could probably use Indy.

But what about the general service framework?
The existing code uses a class inherited from TService, does this exist on FPC for Windows and Linux?
So it can be crosscompiled for both platforms?

This question has popped up today since they want me to fix issues that have appeared with the old service when running on Windows 10 x64...
I figured moving to Linux would make it more stable and less prone to strange side effects.

In any case I have left Delphi for FPC/Lazarus nowadays...

TIA

Bo Berglund Developer in Sweden

Reply by email

Dimitrios Chr. Ioannidis
to Bo Berglund

Hi,

Στις 22/4/2020 1:02 π.μ., ο Bo Berglund via fpc-pascal έγραψε:

< sip >

But what about the general service framework? The existing code uses a class inherited from TService, does this exist on FPC for Windows and Linux? So it can be crosscompiled for both platforms?

Attached you'll find a skeleton project that I use for windows / linux services ( incuded an fclel.res file for windows event loggging ).

For debugging I use the usual technique. An infinity loop in debug mode :

    Run Lazarus with administrator rights.

    Start the service which will hang into the loop.

    Add a breakpoint inside the loop and attach the service process.

    Evaluate, modify the boolean variable which used in the loop from true to false, and you're inside the service ....

#############################################

....

{$IFDEF DEBUG_BUILD}
   {$DEFINE DEBUG_BUILD_SERVICE}
{$ENDIF}

.....

   TFPSVC = class(TCustomDaemon)
   private
{$IFDEF DEBUG_BUILD_SERVICE}
     FServiceDebug: boolean;
{$ENDIF}

.....

   function TFPSVC.Start: boolean;
   begin
{$IFDEF DEBUG_BUILD_SERVICE}
     FServiceDebug := True;
     While FServiceDebug do      <------------------- add a breakpoint here
       Sleep(2000);
{$ENDIF}

......

#############################################

Dimitrios Chr. Ioannidis

Reply by email

Sven Barth
to Bo Berglund: I have this old (dev 2004-2008) service application for Win32, which I hope to…

Bo Berglund via fpc-pascal schrieb am
Mi., 22. Apr. 2020, 05:33:

Show quoted text 5 lines
But what about the general service framework? The existing code uses a class inherited from TService, does this exist on FPC for Windows and Linux? So it can be crosscompiled for both platforms?

The service framework is available as TDaemonApplication in daemonapp.pp and is available for both Windows and *nix systems. :)

Regards,
Sven

Reply by email

Bo Berglund
to Sven Barth
Sven Barth wrote 12 lines
Bo Berglund via fpc-pascal schrieb am Mi., 22. Apr. 2020, 05:33: > But what about the general service framework? > The existing code uses a class inherited from TService, does this > exist on FPC for Windows and Linux? > So it can be crosscompiled for both platforms? > The service framework is available as TDaemonApplication in daemonapp.pp and is available for both Windows and *nix systems. :)

It seems not to be available as an alternative in Lazarus new project dialogue...
At least not in the Tool/Delphi conversion dialogue.

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 18 lines
On Wed, 22 Apr 2020 07:56:38 +0200, Sven Barth via fpc-pascal wrote: > Bo Berglund via fpc-pascal schrieb am > Mi., 22. Apr. 2020, 05:33: > >> But what about the general service framework? >> The existing code uses a class inherited from TService, does this >> exist on FPC for Windows and Linux? >> So it can be crosscompiled for both platforms? >> > > The service framework is available as TDaemonApplication in daemonapp.pp > and is available for both Windows and *nix systems. :) > It seems not to be available as an alternative in Lazarus new project dialogue... At least not in the Tool/Delphi conversion dialogue.

You must install the lazdaemon package, then it becomes available.

The conversion dialogue does not handle service applications specially, as far as I know.

Michael.

Reply by email