morgon has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

assume I want to write a daemon that would consist of some modules and a script.
It would depend on some CPAN-modules, should be started at boot-time and would write a log-file.
It should be distributed to a (small) number of Debian-systems.

What are the current best practices to for implementing and distributing such a perl-service?

I would base such a daemon on something like Daemon::Control that can also create init-scripts, manually create some log-rotate configuration and package everything as a deb-file.

Is this the way to do it?
Or would I nowadays use Docker or whatever else for distribution?

And what would be the easiest way to package everything as a deb?

Many thanks!

  • Comment on current best practices for Perl-daemons on Linux

Replies are listed 'Best First'.
Re: current best practices for Perl-daemons on Linux
by jonass (Initiate) on Oct 27, 2014 at 11:35 UTC
    Separate in universal and distro-specific parts. Release to CPAN as universally consumable (maybe including e.g. an init-script only in an "examples/" dir), and create Debian-specific setup (which includes init script and logrotate hints) in a Debian package built from the CPAN release.
    Seems to me that Daemon::Control is specifically for having code integrate with sysV start-stop-daemon system. Leave it open to users of your CPAN project how to start the daemon - some may favor systemd, runit or maybe plain starting from the commandline.
    Consider if relevant to also support alternate admin-controlled system-wide use (e.g. static data below /usr/local/share instead of /usr/share and dynamic data below /var/local instead of /var/lib).
    If your daemons make use of external data files, consider use File::ShareDir::ProjectDistDir, or for data potentially overridable by the user consider use File::BaseDir instead.
    Hope that helps :-)
Re: current best practices for Perl-daemons on Linux
by duelafn (Parson) on Oct 27, 2014 at 10:19 UTC

    Looks good to me. I generally would prefer just a .deb package over a docker image (of course, you should also create a regular CPAN distribution for perlbrew, non-debian users, etc). For creating the .deb file, have a look at the cpan2deb script in the dh-make-perl package.

    Good Day,
        Dean

Re: current best practices for Perl-daemons on Linux
by afoken (Chancellor) on Oct 29, 2014 at 19:32 UTC

    Generally, don't write code that attempts to "background itself". Leave that to whatever "service manager" is used by the system - init à la BSD, init scripts, daemontools, runit, whatever. Just let the program run in foreground.

    I prefer daemontools (running on Slackware, not Debian). See this search for details.

    Note that there are Debian packages for daemontools and runit, so you can use either service manager on Debian and simply let your package depend on one of those packages.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)