Recent

Author Topic: [Solved partially] Daemons with Windows  (Read 16668 times)

afortuny

  • New Member
  • *
  • Posts: 21
[Solved partially] Daemons with Windows
« on: July 20, 2011, 12:55:16 pm »
Hi guys.

Got a problem with windows daemons.
I've made my own windows service after instaling lazdaemon package.
Lazarus 0.9.30 (FPC 2.4.2) on Windows Server 2003 X64
Lararus 0.9.31 (FCP 2.4.4) on Vista 32
Rebuild Lazarus: OK
Create new project as service: got the service frame (mapper and daemon components)
Daemon class assigned into on item of mapper
Events implemented:
Mapper: Create, Destroy, Install, Run, Uninstall. Code is only a comment in a text flat file
Daemon: Create, Destroy, Start, Stop, Execute. Same code as above except for Start in which the code launches a Thread which writes comments into the same text file, one live every second, for ever, until thread is terminated (in Stop event).
So far so good. :)
BUT:
Pragram.exe -install works (got the comments in the text file)
Pragram.exe -uninstall works (got the comments in the text file)
Mapper and Daemon are both registered, created, destoyed  :D
Within Services manager: start service and stop service do nothing at all. I mean neither procedures nor events are fired and nothing is written into the text file.  :(
Both versions (Win32 and Win64) give exactly the same results: Start Stop do not work.  %)

BTW, I've compiled and run the example cleandirs and it doesn't work either. I have replaced then original thread code by my own and commented all directory process code. It has been replaced by my own code.

New ideas are welcome.

Antonio.
« Last Edit: July 26, 2011, 12:58:56 pm by afortuny »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Daemons with Windows
« Reply #1 on: July 20, 2011, 02:25:21 pm »
Antonio,

You might want to search through the bugtracker, IIRC, there are some daemon bugs in there. If not, you can open one of your own with an example program...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #2 on: July 20, 2011, 06:58:33 pm »
Hi guys.

Got a problem with windows daemons.
I've made my own windows service after instaling lazdaemon package.
Lazarus 0.9.30 (FPC 2.4.2) on Windows Server 2003 X64
Lararus 0.9.31 (FCP 2.4.4) on Vista 32
Rebuild Lazarus: OK
Create new project as service: got the service frame (mapper and daemon components)
Daemon class assigned into on item of mapper
Events implemented:
Mapper: Create, Destroy, Install, Run, Uninstall. Code is only a comment in a text flat file
Daemon: Create, Destroy, Start, Stop, Execute. Same code as above except for Start in which the code launches a Thread which writes comments into the same text file, one live every second, for ever, until thread is terminated (in Stop event).
So far so good. :)
BUT:
Pragram.exe -install works (got the comments in the text file)
Pragram.exe -uninstall works (got the comments in the text file)
Mapper and Daemon are both registered, created, destoyed  :D
Within Services manager: start service and stop service do nothing at all. I mean neither procedures nor events are fired and nothing is written into the text file.  :(
Both versions (Win32 and Win64) give exactly the same results: Start Stop do not work.  %)


I'm using Laz 0.9.31, FPC 2.4.4/2.4.3, onStart and onStop event work.  Did you setup TDaemon and TDaemonMapper correctly?  The default created on New Project needs configuration.  From what I notice of Lazarus, if it can compile doesn't mean it will work.

However, onDestroy and onShutdown don't work, and the daemon cannot be stopped properly on Linux.  I posted a bug report here - http://62.166.198.202/view.php?id=19510
« Last Edit: July 20, 2011, 07:00:13 pm by touchring »

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #3 on: July 21, 2011, 09:21:46 am »
Hi.

Thanks for answer.
I've found issue 0014850  and applied solution: add unit in uses.
Same result.
See the trace of events in my log file:
==== start ===
D:\Compiled\Lazarus>SyncFlatSv.exe --install
Mapper register
Daemon register
Mapper install
Daemon create
Daemon destroy
====================
D:\Compiled\Lazarus>net start "SynchroFlatFile"
Le service SynchroFlatFile démarre.
Le service SynchroFlatFile a démarré.
(Vista 32 reports that service has started but nothing in log file)
====================
D:\Compiled\Lazarus>net stop "SynchroFlatFile"
.
Le service SynchroFlatFile n'a pas pu être arrêté.
(Vista32: Service cannot be stopped)
=============================
D:\Compiled\Lazarus>SyncFlatSv.exe --uninstall
Mapper register
Daemon register
Mapper uninstall
Daemon create
Daemon destroy

I'm convinced that I miss something but I'm unable to point it.

Antonio.

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #4 on: July 21, 2011, 10:27:09 am »
Did you use my test daemon to try?  Thks.

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #5 on: July 21, 2011, 10:32:19 am »
Nope.

Is it the one attached with issue 0019510   ?

Antonio.

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #6 on: July 21, 2011, 11:46:45 am »
Nope.

Is it the one attached with issue 0019510   ?

Antonio.


Yes.

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #7 on: July 21, 2011, 11:59:18 am »
Hi touchring

I downloaded, unzipped, and compiled the project.
Got this result in log file:

v1.3   2011_07_21_10_59_59   sys   Main      0   Destroying service.
v1.3   2011_07_21_11_00_36   sys   Main      0   Initializing service.
v1.3   2011_07_21_11_01_08   sys   Main      0   Stopping service.
v1.3   2011_07_21_11_01_19   sys   Main      0   Destroying service.

I guess that because second line is showing ("Initializing service.") the start procedure has been called
I've used command line as administrator on Vista32

>BasicDaemon.exe --install
(no comment)

>net start "BasicDaemon"
Le service BasicDaemon démarre...
Le service BasicDaemon a démarré.

>net stop "BasicDaemon"
.
Le service BasicDaemon a été arrêté.

<BasicDaemon.exe --uninstall
(no comment)

This example does not  give any idea on what doesn't work actually.
Anyway, I will enrich your execution code with my own and see what happens. Thanks.

I will explore both codes and come back with a post explaining what was wrong.

Antonio.

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #8 on: July 21, 2011, 05:24:03 pm »
Hi touchring

I downloaded, unzipped, and compiled the project.
Got this result in log file:

v1.3   2011_07_21_10_59_59   sys   Main      0   Destroying service.
v1.3   2011_07_21_11_00_36   sys   Main      0   Initializing service.
v1.3   2011_07_21_11_01_08   sys   Main      0   Stopping service.
v1.3   2011_07_21_11_01_19   sys   Main      0   Destroying service.

I guess that because second line is showing ("Initializing service.") the start procedure has been called
I've used command line as administrator on Vista32

>BasicDaemon.exe --install
(no comment)


Hi Antonio, in that you did better because on my system, Destroying service doesn't even appear.  I used /install.

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #9 on: July 22, 2011, 08:39:46 am »
HI touchring.

I'm happy  ;D
To be honest I have to mention the platform:
Vista Pro 32
Lazarus 0.9.31 with FPC 2.4.4
I'll port all on WinServer 2003 64 same Lazarus and I will let you know the results as well.
If the test succeeds I'll close this topic as solved.

Antonio.

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #10 on: July 23, 2011, 03:24:36 am »
Anyway, I will enrich your execution code with my own and see what happens. Thanks.


Hi Antonio, by the way, did you managed to find out what was the problem?  Thks.

Could you also please upload your test code?  So we can upgrade basicdaemon to a better test.  I think we need a better daemon better. 
« Last Edit: July 23, 2011, 03:27:07 am by touchring »

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #11 on: July 25, 2011, 08:33:27 am »
Hi touchring,

Not yet but I'll do it. Because I'm busy with other tasks as well, I plan to do it this week anyway.

Antonio.

afortuny

  • New Member
  • *
  • Posts: 21
Re: Daemons with Windows
« Reply #12 on: July 26, 2011, 12:57:17 pm »
Hi folks.

I've pointed out what appears to be wrong with LazDaemon.
I've made a test based upon touchring source code BasicDaemon.
Vista pro 32, Lazarus 0.9.31
Here are the comments and results:

Basically, three events do not fire:Shutdown Daemon, Mapper Create, Mapper Destroy
Another one prevents the service to act in a normal way: TDaemon.OnExecute

The file "diagnostic.txt" Inside the zip explains the full process and tests: enjoy  :'(
The zip file contains all the source of the project.

Antonio.

touchring

  • Full Member
  • ***
  • Posts: 174
Re: Daemons with Windows
« Reply #13 on: July 26, 2011, 07:33:06 pm »
Hi folks.

I've pointed out what appears to be wrong with LazDaemon.
I've made a test based upon touchring source code BasicDaemon.
Vista pro 32, Lazarus 0.9.31
Here are the comments and results:

Basically, three events do not fire:Shutdown Daemon, Mapper Create, Mapper Destroy
Another one prevents the service to act in a normal way: TDaemon.OnExecute

The file "diagnostic.txt" Inside the zip explains the full process and tests: enjoy  :'(
The zip file contains all the source of the project.

Antonio.


I've only used OnCreate, OnStart and OnStop, OnPause and OnContinue for my daemons, I guess they represent the start/stop/pause and continue actions on the Service Manager.  They work on Linux also i believe.

OnDestroy doesn't work for me, so I'm curious but it doesn't matter as I believe I can use OnStop.  The same case with OnShutdown.

OnShutdown is defined as "Shutdown called when the daemon should stop absolutely it’s work. This method should
immediatly return, and must return True if the work was stopped succesfully. This
is called if the system is shutting down, and all services must be stopped." in this PDF - ttp://www.linuxprogramlama.com/downloads/lazarus/daemons.pdf

Yes, OnExecute doesn't work, but we can use OnStart instead to create the threads.