[Dnsmasq-discuss] patch to support systemd socket activation

Simon Kelley simon at thekelleys.org.uk
Mon Nov 14 20:15:25 GMT 2011


On 14/11/11 09:19, 微菜 wrote:
> Hi there,
> 
> I was once send it to our maintainers the patch for 2.57.
> Now I've rebased it to 2.59 and resend it here for discussion.

I remember the previous discussion. In the meantime, support for systemd
activation support has been added to the Debian package of dnsmasq. That
uses DBus activation and doesn't require any extra code in dnsmasq itself.


The dnsmasq.service file looks like this: some of it is Debian specific,
but it gives the general idea.

[Unit]
Description=A lightweight DHCP and caching DNS server

[Service]
Type=dbus
BusName=uk.org.thekelleys.dnsmasq

# Test the config file and refuse starting if it is not valid.
ExecStartPre=/usr/sbin/dnsmasq --test

# Enable DBus by default because we use DBus activation.
#
# Drop privileges and become the 'dnsmasq' user. It is recommended by
# dnsmasq upstream to run dnsmasq as an isolated user that does not run
# any other processes, owns no files and has no shell. The default
# 'nobody' user has a shell and might be used for other processes.
#
# Debian-specific: add /etc/dnsmasq.d to config search path (with the
# exception of .dpkg-*). Packages such as libvirt leave config files
# there.
#
# --pid-file without argument disables writing a PIDfile, we don't need
# one.
ExecStart=/usr/sbin/dnsmasq -k \
          --enable-dbus \
          --user=dnsmasq \
          -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new \
          --pid-file

ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target


> 
> This patch enables dnsmasq to support systemd socket activation.
> 
> 
> #systemctl enable dnsmasq.socket
> #systemctl enable dnsmasq-tftp.socket
> 
> Then if some one try to access tftp or local DNS, dnsmasq will be
> started automatically.
> 
> I didn't test DHCP functionality, so I did't come up with
> dnsmasq-dhcp.socket. sorry for the in-convenience.
> 

I'm not a systemd expert, by any means, (I didn't write the code above)
but I'd like to understand the advantages and problems with the two
methods of activation (DBus and socket)


Cheers,

Simon.

> 
> 



More information about the Dnsmasq-discuss mailing list