Systemd-style daemons

Systemd is a service and package manager for Linux which is growing on popularity (and controversy) every day. The most popular distributions implement it as of today.

Launching a daemon is achieved through Units. Units are files that defined the behaviour of a certain service, mount, device, or socket. Marco and Polo are configured as different units with some dependencies.

Both daemons require a connection to work, so both will have the dependencies network.target network-online.target to wait for the network functionality to be loaded and sys-subsystem-net-devices-net0.device to wait for the main interface to be configured before starting to work.

Python 2 units

In Python 2 the daemon management is done by twistd.

Marco unit

[Unit]
Description=A simple service discovery protocol resolver
Requires=network.target network-online.target
After=network.target network-online.target 
After=sys-subsystem-net-devices-net0.device

[Service]
ExecStart=/usr/bin/twistd --pidfile=/var/run/marcod.pid --logfile=/var/log/marcopolo/marcod.log -y /etc/marcopolo/daemon/marco_twistd.tac

Type=simple
User=root
Group=root
PIDFile=/var/run/marcod.pid

[Install]
WantedBy=multi-user.target

Polo unit

[Unit]
Description=A simple service discovery protocol advertiser
Requires=network.target network-online.target
After=network.target network-online.target 
After=sys-subsystem-net-devices-net0.device

[Service]
ExecStart=/usr/bin/twistd --pidfile=/var/run/polod.pid --logfile=/var/log/marcopolo/polod.log -y /etc/marcopolo/daemon/polo_twistd.tac

ExecReload=/usr/local/bin/poloreload.py &> /dev/null

Type=simple
User=root
Group=root
PIDFile=/var/run/polod.pid

[Install]
WantedBy=multi-user.target

Python 3 units

In Python 3 the daemon is configured manually.

Marco unit

[Unit]
Description=A simple service discovery protocol resolver
Requires=network.target network-online.target
After=network.target network-online.target 
After=sys-subsystem-net-devices-net0.device

[Service]
ExecStart=/usr/bin/marcod &>/dev/null

Type=simple
User=root
Group=root
PIDFile=/var/run/marcod.pid

[Install]
WantedBy=multi-user.target

Polo unit

[Unit]
Description=A simple service discovery protocol advertiser
Requires=network.target network-online.target
After=network.target network-online.target 
After=sys-subsystem-net-devices-net0.device

[Service]
ExecStart=/usr/bin/polod &>/dev/null
ExecReload=/usr/bin/poloreload.py &> /dev/null

Type=simple
User=root
Group=root
PIDFile=/var/run/polod.pid

[Install]
WantedBy=multi-user.target