xinetd stands for extended Internet services daemon. This is a replacement for inetd. xinetd starts and listens on all the service ports that you’ve defined, and when there is an incoming request to a particular port that it is listening to, it starts the corresponding service.
1. Specify a custom Config file using -f
By default xinetd uses the /etc/xinetd.conf file to store xinetd configurations. Inside the xinted.conf file, there is an includedir directive, which points to /etc/xinetd.d directory.
# grep includedir /etc/xinetd.conf includedir /etc/xinetd.d
The following services will be used by default by xinetd to watch.
# ls -l /etc/xinetd.d total 44 -rw-------. 1 root root 1157 Feb 21 19:03 chargen-dgram -rw-------. 1 root root 1159 Feb 21 19:03 chargen-stream -rw-------. 1 root root 1157 Feb 21 19:03 daytime-dgram -rw-------. 1 root root 1159 Feb 21 19:03 daytime-stream -rw-------. 1 root root 1157 Feb 21 19:03 discard-dgram -rw-------. 1 root root 1159 Feb 21 19:03 discard-stream -rw-------. 1 root root 1148 Feb 21 19:03 echo-dgram -rw-------. 1 root root 1150 Feb 21 19:03 echo-stream -rw-------. 1 root root 1212 Feb 21 19:03 tcpmux-server -rw-------. 1 root root 1149 Feb 21 19:03 time-dgram -rw-------. 1 root root 1150 Feb 21 19:03 time-stream
You can specify your own config file using -f option when xinetd is starting as shown below.
/usr/sbin/xinetd -f /root/myxinetd.conf -stayalive -pidfile /var/run/xinetd.pid
If you don’t have the /root/myxinetd.conf file, you’ll see the following error message in the /var/log/messages
# tail /var/log/messages Apr 10 23:06:07 centos xinetd[29901]: open( /root/myxinetd.conf ) failed: No such file or directory (errno = 2) Apr 10 23:06:07 centos xinetd[29901]: 29901 {init_services} couldn't get configuration. Exiting...
Note: If you are using “service xinetd start” (or stop), then you can modify the following file, and specify the extra options in the EXTRAOPTIONS variable, and restart xinetd service.
# cat /etc/sysconfig/xinetd EXTRAOPTIONS="-f /root/myxinetd.conf" # service xinetd restart
If it is able to read the custom file, xinetd will start without any issues as shown in the /var/log/messages below.
# tail /var/log/messages Apr 10 23:07:52 centos xinetd[29906]: xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in. Apr 10 23:07:52 centos xinetd[29906]: Started working: 0 available services
2. Specify Custom Log file for Xinetd using -filelog
You can also specify a custom log file for xinetd using the -filelog as shown below. This writes all the xinetd log messages to /var/log/myxinetd.log
# /usr/sbin/xinetd -filelog /var/log/myxinetd.log -stayalive -pidfile /var/run/xinetd.pid
Now if you view your custom xinetd log file, you’ll see that the messages are getting logged.
# tail /var/log/myxinetd.log 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing daytime 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing discard 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing discard 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing echo 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing echo 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing tcpmux 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing time 13/4/10@15:10:23 xinetd[29932]: DEBUG: removing time 13/4/10@15:10:23 xinetd[29932]: NOTICE: xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in. 13/4/10@15:10:23 xinetd[29932]: NOTICE: Started working: 0 available services
Please note that you can also set “-filelog” in the EXTRAOPTIONS variable of /etc/sysconfig/xinetd and use “service xinetd restart”.
3. Limit Concurrent Process Limit using -limit
Using -limit option, you can also limit the number of concurrent process that can be running. i.e When xinetd starts processes based on the incoming request, how many process can be running concurrently at any given time? This helps xinted to avoid process table over-flow.
The following example limits the xinetd concurrent process to 10.
# /usr/sbin/xinetd -filelog /var/log/myxinetd.log -limit 10 -stayalive -pidfile /var/run/xinetd.pid
Please note that you can also set “-limit” in the EXTRAOPTIONS variable of /etc/sysconfig/xinetd and use “service xinetd restart”.
4. Perform Periodic Consistency Checks using -cc
The following example will perform xinted internal state consistency check every two minutes (120 seconds) as specified in the -cc option.
# /usr/sbin/xinetd -filelog /var/log/myxinetd.log -cc 120 -stayalive -pidfile /var/run/xinetd.pid
Please note that you can also set “-cc” in the EXTRAOPTIONS variable of /etc/sysconfig/xinetd and use “service xinetd restart”.
5. Create Xinetd Dump File
For debugging purpose, sometimes you may want to create an internal dump file of the current state of the xinetd.
To create a xinetd dump file, get the PID of xinetd.
# ps -ef | grep xinetd root 29981 1 0 25:21 ? 00:00:00 /usr/sbin/xinetd -filelog /var/log/myxinetd.log -cc 30 -stayalive -pidfile /var/run/xinetd.pid
Pass SIGUSR1 signal to the xinetd PID as shown below.
# kill -SIGUSR1 29981
The above command will dump the xinted.dump file in the default /var/run directory as shown below.
# ls -l /var/run/xinetd.dump -rw-r--r--. 1 root root 728 Apr 10 25:21 /var/run/xinetd.dump