[Solved partially] Daemons with Windows lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- afortuny · 2011-07-20 10:55 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  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. ---------------------------------------------------------------------- BigChimp · 2011-07-20 12:25 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... ---------------------------------------------------------------------- jl · 2011-07-20 16:58 Quote from: afortuny on July 20, 2011, 12:55:16 pmHi 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  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 ---------------------------------------------------------------------- afortuny · 2011-07-21 07:21 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. ---------------------------------------------------------------------- jl · 2011-07-21 08:27 Did you use my test daemon to try?  Thks. ---------------------------------------------------------------------- afortuny · 2011-07-21 08:32 Nope. Is it the one attached with issue 0019510   ? Antonio. ---------------------------------------------------------------------- jl · 2011-07-21 09:46 Quote from: afortuny on July 21, 2011, 10:32:19 amNope. Is it the one attached with issue 0019510   ? Antonio. Yes. ---------------------------------------------------------------------- afortuny · 2011-07-21 09:59 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 --install (no comment) Hi Antonio, in that you did better because on my system, Destroying service doesn't even appear.  I used /install. ---------------------------------------------------------------------- afortuny · 2011-07-22 06:39 HI touchring. I'm happy  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. ---------------------------------------------------------------------- jl · 2011-07-23 01:24 Quote from: afortuny on July 22, 2011, 08:39:46 amAnyway, 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. ---------------------------------------------------------------------- afortuny · 2011-07-25 06:33 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 · 2011-07-26 10:57 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. ---------------------------------------------------------------------- jl · 2011-07-26 17:33 Quote from: afortuny on July 26, 2011, 12:57:17 pmHi 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.