Difference between revisions of "Daemons and Services"

From Lazarus wiki
Jump to navigationJump to search
Line 33: Line 33:
 
*install, uninstall or run every instance.
 
*install, uninstall or run every instance.
  
*if run: wait for Stop/TERM signal.
+
*if run: start every instance in its own thread and then wait for Stop/TERM signal.

Revision as of 19:25, 28 November 2007

What are daemons and services?

Unix daemons and windows services are programs running without user interaction. For example www or ftp servers are called daemons under linux and services under windows. Because they do not interact with the user directly, they close their stdin, stdout, stderr descriptors at start.

With Free Pascal, Lazarus it is possible to write these daemons/services platform independent via the Lazarus lazdaemon package. To avoid name conlicts with the Delphi components these classes are called 'daemons'.

Classes

TCustomDaemon

This is a TDataModule descendant that does all the work. There can be several TCustomDaemons classes and/or instances running at the same time and in the same process (multi threaded).

TCustomDaemonApplication

This is a TCustomApplication descendant which creates the TCustomDaemons. This does not need any change. It runs under windows until it receives the Stop call or under linux until the TERM signal.

TDaemonMapper

This component handles the service registration. Each instance needs one entry in the property DaemonDefs.

Daemon - Step by Step

  • When the daemon is started the command line parameters are parsed. The following are predefined:
    • -i --install: register the daemon. This has no effect under unix.
    • -u --uninstall: unregister the daemon. This has no effect under unix.
    • -r --run: start the daemon. Windows does this normally itself.
  • Create the TDaemonMapper
  • Create one TCustomDaemon for each entry of DaemonDefs.
  • install, uninstall or run every instance.
  • if run: start every instance in its own thread and then wait for Stop/TERM signal.