Andrei Popescu:
I recently needed something to run imapfilter and restart it in case
it might exit, so I had a look at daemontools. I gave up quickly [...]
And here's how one can do it with the nosh package
(http://homepage.ntlworld.com./jonathan.deboynepollard/Softwares/nosh.html).
I took a template service unit for imapfilter from the WWW and tweaked
it a little bit:
root /var/sv #cat imapfilter@.service
[Unit]
Description=%p daemon service for %I
[Service]
Type=simple
ExecStart=%p -c /home/%I/.%p/config.lua
Restart=always
User=%I
[Install]
WantedBy=workstation.target
root /var/sv #
The nosh package's native service configuration is of course the service
bundle, a compatible superset of the daemontools-family service/ and
supervise/ directories; and the package has a tool for converting
systemd service, socket, and target units (within some fairly broad
limits, as explained in depth in the chapter on converting systemd units
in the nosh Guide). So I ran it, instatiating the template:
root /var/sv #system-control convert-systemd-units
./imapfilter@popescu.service
root /var/sv #
It produced an entire service bundle. Since you've been talking about
how, supposedly, hard run scripts are to write, the interesting part is
the auto-generated run script that the import tool produced. Even this
isn't particularly complex:
root /var/sv #cat imapfilter@popescu/service/run
#!/bin/nosh
#Run file generated from ./imapfilter@.service
#imapfilter daemon service for popescu
chdir /
setuidgid popescu
imapfilter -c /home/popescu/.imapfilter/config.lua
root /var/sv #
It uses one of those minimum-functionality script interpreters that I
mentioned before. One could of course write a similarly short shell
script by hand:
root /var/sv #cat imapfilter@popescu/service/run.sh
#!/bin/sh -e
exec setuidgid popescu imapfilter -c
/home/popescu/.imapfilter/config.lua
root /var/sv #
But I'm illustrating starting from a systemd unit here, and letting the
import tool write the scripts.
For kicks, I decided to log the output of this service to a dedicated
logging service. I started with the cyclog@.service template that comes
in the nosh source archive and instantiated it with the same systemd
unit import tool as before:
root /var/sv #system-control convert-systemd-units
./cyclog@imapfilter@popescu.service
root /var/sv #
This made me another service bundle. Again, the interesting part for
this discussion is the run script that the import tool made:
root /var/sv #cat cyclog@imapfilter@popescu/service/run
#!/bin/nosh
#Run file generated from ./cyclog@.service
#Standard format cyclog logging service for imapfilter@popescu
chdir /var/log/sv/
setuidgid "imapfilter@popescu-log"
cyclog imapfilter@popescu/
root /var/sv #
Setting up /var/log/sv/imapfilter@popescu and its dedicated logging user
(or editing the run script to use, say, "popescu" as the logging user)
is a simple exercise in making a directory and adding a user to the
system's user database (and editing a script file), of course. I could
have made one big logging service for /var/log/sv/popescu instead:
root /var/sv #system-control convert-systemd-units
./cyclog@popescu.service
root /var/sv #
This is because I can plumb "main" services to "log" services however I
like, including many-to-one fan-in and 1:1 dedicated logging services.
I chose the latter:
root /var/sv #ln -s ../cyclog@imapfilter@popescu imapfilter@popescu/log
root /var/sv #
The rest of the process goes beyond this discussion of how simple it is
to write daemontools-family run scripts and is an exercise in enabling
the two services and starting them:
root /var/sv #systemctl enable imapfilter@popescu.service
cyclog@imapfilter@popescu.service
root /var/sv #systemctl start imapfilter@popescu.service
cyclog@imapfilter@popescu.service
root /var/sv #
Were this machine running the daemontools compatibility old-style
service scanner, enabling the two services and starting them would have
been:
root /var/sv #ln -s /var/sv/imapfilter@popescu/ /var/service/
root /var/sv #
But this machine is running the nosh package's system manager, has the
"standard targets" system in place, and is always starting things with
system-control (a.k.a. systemctl). It was the same machine as used at
http://homepage.ntlworld.com./jonathan.deboynepollard/Softwares/nosh-example.html
in fact (which will come as a surprise to those who remember that we're
starting from a systemd unit file here).
--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/543a5658.9040...@ntlworld.com