8

I use xinetd and it works for my purposes. However I recently discovered that systemd has something built in called "socket activation".

These two seem very similar, but systemd is "official" and seems like the better choice.

However before using it, are they really the same? Are there differences I should be aware of?

For example, I want to start some dockerised services only when they are first requested - my first thought would be to use xinetd. But is socket activation better / faster / stabler / whatever?

3
  • If both work, use what you are comfortable with.
    – RalfFriedl
    Sep 23, 2018 at 13:40
  • @RalfFriedl Good advice, but I'd rather use what is more official/standard - it seems to me that would be socket activation. However I can't find info anywhere stating whether they actually do the same thing, I don't want to run into any problems.
    – lonix
    Sep 23, 2018 at 13:42
  • 1
    According to the systemd crowd, systemd should be used for everything. xinetd won't cause you any problems. With systemd you have to write two files, a .service file and a .socket file. Both approaches will work.
    – RalfFriedl
    Sep 23, 2018 at 13:48

2 Answers 2

10

I don’t think systemd socket activation is significantly better than xinetd activation, when considered in isolation; the latter is stable too and has been around for longer. Socket activation is really interesting for service decoupling: it allows services to be started in parallel, even if they need to communicate, and it allows services to be restarted independently.

If you have a service which supports xinetd-style activation, it can be used with socket activation: a .socket description with Accept=true will behave in the same way as xinetd. You’ll also need a .service file to describe the service. The full benefits of systemd socket activation require support in the dæmon providing the service. See the blog post on the topic.

My advice tends to be “if it isn’t broken, don’t fix it”, but if you want to convert an xinetd-based service to systemd it’s certainly feasible.

5

You can use either xinetd or systemd for socket activation, both will work. I personally find xinetd easier to use because everything is in one file, but have also used systemd because it is more flexible, especially with listening on multiple addresses and socket forwarding to UNIX sockets and not just to IP sockets.

Here as an example I used to forward TCP connection to the MySQL file socket:

/etc/systemd/system/mysql-proxy.service

[Unit]                                                  
Description=MySql Proxy Service
Requires=mysql-proxy.socket

[Service]
Environment=MYSQL_PROXY_TARGET=/var/run/mysql/mysql.sock
EnvironmentFile=-/etc/sysconfig/mysql-proxy
ExecStart=/usr/lib/systemd/systemd-socket-proxyd ${MYSQL_PROXY_TARGET}

/etc/systemd/system/mysql-proxy.socket

[Unit]                                                  
Description=MySql Proxy Socket

[Socket]
ListenStream=192.168.1.1:3306
ListenStream=192.168.2.1:3306
NoDelay=true
FreeBind=true

[Install]
WantedBy=sockets.target

Traditional forwarding needs Accept=true, systemd aware processes are supposed to handle multiple connections in one process or fork additional processes as required.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .