Recent

Author Topic: DaemonSystemdInstallerUnit  (Read 1941 times)

Чебурашка

  • Hero Member
  • *****
  • Posts: 579
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
DaemonSystemdInstallerUnit
« on: December 28, 2022, 05:48:10 pm »
Hello,
 
the unit DaemonSystemdInstallerUnit mentioned in

https://wiki.freepascal.org/Daemons_and_Services

that is supposed to create the systemd control files, is also part of the deamon stuff units or is it a custom unit belonging to the writer of the article?

I did not find in my filesystem.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Thaddy

  • Hero Member
  • *****
  • Posts: 14850
  • Censorship about opinions does not belong here.
Re: DaemonSystemdInstallerUnit
« Reply #1 on: December 28, 2022, 06:52:11 pm »
That wiki entry is ,well, not very good.
Stick with:

from the official FPC documentation here:
https://www.freepascal.org/docs-html/current/fcl/daemonapp/tdaemoncontroller.html

The example in the fcl-extra directory here:
packages\fcl-extra\examples

and this article by Michael van Canneyt here:
https://www.freepascal.org/~michael/articles/#daemons (also covers Windows services)

and ignore the wiki. (well, it is not that bad and may help you a bit when you first read and understand official sources).
The wiki is an abberation of "components" where there need not be components at all, just classes. You can just as well turn 'Hello, World' into a component < sigh>, but OTOH it may be that Michael also contributed a bit to the wiki to keep at least some control...
(And yes, Michael's articles are an official source)
« Last Edit: December 28, 2022, 07:05:12 pm by Thaddy »
Remember the Medway disaster..

Чебурашка

  • Hero Member
  • *****
  • Posts: 579
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: DaemonSystemdInstallerUnit
« Reply #2 on: December 29, 2022, 09:34:22 am »
That wiki entry is ,well, not very good.
Stick with:

from the official FPC documentation here:
https://www.freepascal.org/docs-html/current/fcl/daemonapp/tdaemoncontroller.html

The example in the fcl-extra directory here:
packages\fcl-extra\examples

and this article by Michael van Canneyt here:
https://www.freepascal.org/~michael/articles/#daemons (also covers Windows services)

and ignore the wiki. (well, it is not that bad and may help you a bit when you first read and understand official sources).
The wiki is an abberation of "components" where there need not be components at all, just classes. You can just as well turn 'Hello, World' into a component < sigh>, but OTOH it may be that Michael also contributed a bit to the wiki to keep at least some control...
(And yes, Michael's articles are an official source)

Thanks, in reality I had no problem in writing a deamonized application (and as you say I did it just looking at the sources/pdfs). Only now I also need this deamon to get along with systemd and I was wondering if the cited unit is public or not, so that I don't have to create a custom tool to generate systemd configuration files.

From your answer I understand it is not public. 
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

dbannon

  • Hero Member
  • *****
  • Posts: 2862
    • tomboy-ng, a rewrite of the classic Tomboy
Re: DaemonSystemdInstallerUnit
« Reply #3 on: December 29, 2022, 10:00:23 am »
The content you are looking for (I think) is in an example included with trunk but not yet the release versions of Lazarus.

If you are not using Trunk, the content can be found here - https://gitlab.com/dbannon/laz_examples/-/tree/main/General/TDaemon

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Чебурашка

  • Hero Member
  • *****
  • Posts: 579
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: DaemonSystemdInstallerUnit
« Reply #4 on: December 29, 2022, 10:06:10 am »
The content you are looking for (I think) is in an example included with trunk but not yet the release versions of Lazarus.

If you are not using Trunk, the content can be found here - https://gitlab.com/dbannon/laz_examples/-/tree/main/General/TDaemon

Davo

Thank you.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

AlexTP

  • Hero Member
  • *****
  • Posts: 2434
    • UVviewsoft
Re: DaemonSystemdInstallerUnit
« Reply #5 on: December 29, 2022, 10:41:38 am »
Added the found URL to the wiki topic.

Чебурашка

  • Hero Member
  • *****
  • Posts: 579
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: DaemonSystemdInstallerUnit
« Reply #6 on: December 29, 2022, 11:28:07 am »
At the end what I did was:

- make the daemon (easy, just see the examples)
- create a systemd config file and make sure to have:

Code: INI  [Select][+][-]
  1. [Unit]
  2. Description=TT daemon
  3.  
  4. [Service]
  5. Type=forking
  6. WorkingDirectory=/home/user_tt/.tt_daemon
  7. ExecStart=/usr/local/bin/tt_daemon -r -b
  8. User=user_tt
  9. Group=users
  10.  
  11.  


- the option -r in the ExecStart line tells the daemon to run
- the option -b in the ExecStart line tells the daemon created with fpc to daemonize itself = fork and become background process
- the Type=forking is designed to deal with processes capable of daemonizing

in alternative

Code: INI  [Select][+][-]
  1. [Unit]
  2. Description=TT daemon
  3.  
  4. [Service]
  5. Type=simple
  6. WorkingDirectory=/home/user_tt/.tt_daemon
  7. ExecStart=/usr/local/bin/tt_daemon -r
  8. User=user_tt
  9. Group=users
  10.  
  11.  

- skip the option -b in the ExecStart so that the daemon will start and not daemonize itself (it will keep runnig until stopped from outside or it crashes)
- in this case I have to use Type=simple (is the default) which is designed to deal with processes that do not daemonize, and systemd will go ahead with other services without being locked by my process.
« Last Edit: December 30, 2022, 10:14:55 am by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018