Skip to main content
Home
//verder in webdiensten, techniek en beheer
  • Home
  • Private cloud
  • Salestracker CRM
  • Open source
  • Blog

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
 

 

Ulterius - T. 0623391101 - E. info@ulterius.nl
KvK. 55625207
Linkedin

ulterius: verder, meer geavanceerd, meer op afstand

#Linux - redhat - ubuntu - debian #Virtualisatie - proxmox  - kvm - lxc - docker - kubernetes     #Web - drupal - backdrop cms  - wordpress - php - apache - nginx - haproxy   #Mail - postfix - imap - zimbra   #Databases - mysql - postgresql #Netwerken - switches - routers - firewall - pfsense - iptables - openvpn - ipsec - nfs - samba - nis - ldap - dhcp - ftp - sftp - ssh #Backup - amanda - rsync - bacula - rsnapshot #Monitoring - nagios - zabbix - check_mk - elk stack #Scripting - bash - perl - python #Installatie methoden kickstart - preseed- Redhat sattellite #Configuratie management ansible - git