Xinetd service to systemd socket
To use rrdtool remotely for example, to update the RRD database, create graphs, and more, you can use rrdtool with standard input, which was previously handled via xinetd.
Xinetd service
/etc/xinetd.d/rrdsrv:
service rrdsrv
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/bin/rrdtool
server_args = -
log_type = FILE /var/log/rrdsrv.log
}
/etc/services:
rrdsrv 13900/tcp # RRD server
Systemd
RHEL 9 and its clones no longer include xinetd. It has been replaced by systemd socket activation.
You can use the following script to create a socket for rrdtool, for example:
#!/bin/bash
if [ $# -lt 3 ]; then
echo "$0 nameservice port program in/out"
exit 1
fi
NAME=$1
PORT=$2
SCRIPT=$3
INOUT=$4
if [ "$INOUT" == "in" ]; then
STDINOUT="StandardInput=socket"
else
STDINOUT="StandardOutput=socket"
fi
cat << EOF > /etc/systemd/system/$NAME\@.service
[Unit]
Description=$NAME Agent Service
After=network.target $NAME.socket
Requires=$NAME.socket
[Service]
Type=simple
User=root
# Note the - to make systemd ignore the exit code
ExecStart=-$SCRIPT
# This is the part that makes it work like inetd
$STDINOUT
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
cat << EOF > /etc/systemd/system/$NAME.socket
[Install]
WantedBy = sockets.target
[Unit]
Description=$NAME Agent Socket
PartOf=$NAME.service
[Socket]
ListenStream=$PORT
Accept=yes
[Install]
WantedBy=sockets.target
EOF
systemctl daemon-reload
systemctl enable $NAME.socket
systemctl start $NAME.socket
Usage:
./createsocket.sh rrdsrv 13900 "/usr/bin/rrdtool -" in