How to convert xinetd service to systemd?
Environment
- Red Hat Enterprise Linux (RHEL) 7, 8 and 9
- xinetd
- systemd
Issue
- Need to convert
xinetdtosystemdunit file.
Resolution
- Let's assume an
xinetdservice file like the following:
# cat /etc/xinetd.d/appld
service application
{
flags = REUSE
socket_type = stream
wait = no
user = example
server = /opt/appl/bin/appld
type = UNLISTED
port = 24146
protocol = tcp
disable = no
}
- The name
appld, the path to the code which gets to handle the incoming request (/opt/appl/bin/appld) and the other values are examples and would likely have other values in the real world. Above service file would be translated into the two unit files below :
# cd /etc/systemd/system
# cat application.socket
[Unit]
Description=Application Socket
[Socket]
ListenStream=24146
Accept=yes
[Install]
WantedBy=sockets.target
# cat application@.service
[Unit]
Description=Application Per-Connection Server
[Service]
ExecStart=-/usr/bin/appld # the binary to start
User=example
Group=example
StandardInput=socket
- Enable, Start and check the status of the application socket.
# systemctl enable application.socket
# systemctl start application.socket
# systemctl status -l application.socket
- To see which services are now active :
# systemctl --full | grep application
appld@172.31.0.52:24146-172.31.0.4:47779.service loaded active running App Per-Connection Server
appld@172.31.0.52:24146-172.31.0.54:52985.service loaded active running App Per-Connection Server
appld.socket loaded active listening App Socket for Per-Connection Servers
-
As expected, there are now two service instances running, for the two connections, and they are named after the source and destination address of the TCP connection as well as the port numbers. (For AF_UNIX sockets the instance identifier will carry the PID and UID of the connecting client.) This allows us to individually introspect or kill specific App instances.
-
To terminate the session of a specific client :
# systemctl stop appld@172.31.0.52:24146-172.31.0.4:47779.service
SBR
Product(s)
Components
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.