brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd-socket-activate tests socket activation without writing any units

Systemd
~/tips/tip-systemd-socket-activate-test

systemd-socket-activate -l 2000 --inetd -a cat

Starts a test listener that launches a program per connection, mimicking socket activation.

To see how socket activation behaves, I would rather use a one-liner than create two unit files.

systemd-socket-activate -l 2000 --inetd -a cat
nc localhost 2000

The tool listens on port 2000 and starts a new cat for each connection, with the socket as stdin and stdout (--inetd -a). Type something in nc and it comes back, because cat echoes it. Without --inetd, the program gets the socket as file descriptor 3 and the variables LISTEN_FDS and LISTEN_PID, which is how a real activated service receives it. It binds as your user, so use ports above 1023.

Further reading: systemd-socket-activate manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link