Installing xinetd

  • Download source from xinetd The current version is 2.3.14, so the command to download it is wget http://xinetd.org/xinetd-2.3.14.tar.gz.
  • Unzip the file using the command gunzip -c xinetd-2.3.14.tar.gz|tar x and change into the directory this creates (cd xinetd-2.3.14)
  • Configure it using the command ./configure –prefix=/usr/mylocal >log.config 2>err.config
  • Check err.config for any errors
  • Build the source code using the command make >log.make 2>err.make
  • Check err.make for errors
  • Install the package using the command make install >log.install 2>err.install
  • Check err.install for any errors
  • Now create the configuration file for the services you want to run using the command pico /etc/xinetd.conf. It should look something like this example:
    1. # Configuration file for xinetd
    2. #
    3.  
    4. defaults
    5. {
    6.         instances               = 25
    7.         log_type                = FILE /var/log/xinetd
    8.         log_on_success  = HOST PID
    9.         log_on_failure = HOST
    10. }
    11.  
    12. #service imapd
    13. #{
    14. #       socket_type             = stream
    15. #       wait                    = no
    16. #       user                    = vuser
    17. #       server                  = /usr/local/sbin/imapd
    18. #       log_on_failure += USERID
    19. #}
    20.  
    21. #service imaps
    22. #{
    23. #       socket_type             = stream
    24. #       wait                    = no
    25. #       user                    = vuser
    26. #       server                  = /usr/local/sbin/imapd
    27. #       log_on_failure += USERID
    28. #}
    29.  
    30. ## rsyncd can't run on 873/tcp because WestHost's own backup
    31. ## tools are running there.
    32. #service rsync-alt
    33. #{
    34. #       disable                 = no
    35. #       type                    = UNLISTED
    36. #       port                    = 8730
    37. #       socket_type             = stream
    38. #       wait                    = no
    39. #       user                    = vuser
    40. #       server                  = /usr/local/bin/rsync
    41. #       server_args             = --daemon
    42. #       log_on_failure += USERID
    43. #}

    Replace vuser with your user name

  • Test your installation of xinetd by typing /usr/mylocal/sbin/xinetd -d. Fix any errors. If there are none, then terminate the daemon using Control-X
  • Create the file /etc/rc.d/init.d/xinetd which will be used to start and stop the xinetd task using the command pico /etc/rc.d/init.d/xinetd
    1. #!/bin/bash
    2. #
    3. # Startup script for the xinetd server
    4. #
    5. # chkconfig: - 86 14
    6. # description: xinetd
    7. # processname: xinetd
    8. # pidfile: /var/run/xinetd.pid
    9. # config: /etc/xinetd.conf
    10.  
    11. # Source function library.
    12. . /etc/rc.d/init.d/functions
    13.  
    14. xinetd=/usr/mylocal/sbin/xinetd
    15. prog=xinetd
    16. RETVAL=0
    17.  
    18. start() {
    19.         echo -n $"Starting $prog: "
    20.         pidfile=/var/run/xinetd.pid
    21.         pid=`cat $pidfile 2>/dev/null`
    22.         [ "$pid" ] && \
    23.                 [ "`find  /proc/${pid}/exe -printf '%l%U\n' 2>/dev/null |
    24. awk -F'/' '{print $NF}'`" != "xinetd`id -u`" ] && \
    25.                                 /bin/rm -f $pidfile
    26.         daemon $xinetd
    27.         RETVAL=$?
    28.         echo
    29.         [ $RETVAL = 0 ] && touch /var/lock/subsys/xinetd
    30.         return $RETVAL
    31. }
    32. stop() {
    33.         echo -n $"Stopping $prog: "
    34.         killproc $xinetd
    35.         RETVAL=$?
    36.         echo
    37.         if [ $RETVAL = 0 ] ; then
    38.                 rm -f /var/lock/subsys/xinetd /var/run/xinetd.pid
    39.                 pid=`pidof -o $$ -o $PPID -o %PPID -x ${xinetd} || pidof -o $$ -o $PPID -o %PPID -x ${prog}`
    40.                 if [ "$pid" ] ; then
    41.                         killproc $xinetd
    42.                         RETVAL=$?
    43.                 fi
    44.         fi
    45. }
    46. reload() {
    47.         echo -n $"Reloading $prog: "
    48.         killproc $xinetd -HUP
    49.         RETVAL=$?
    50.         echo
    51. }
    52.  
    53. # See how we were called.
    54. case "$1" in
    55.   start)
    56.         start
    57.         ;;
    58.   stop)
    59.         stop
    60.         ;;
    61.   status)
    62.         status $xinetd
    63.         RETVAL=$?
    64.         ;;
    65.   restart)
    66.         stop
    67.         start
    68.         ;;
    69.   condrestart)
    70.         if [ -f /var/run/xinetd.pid ] ; then
    71.                 stop
    72.                 start
    73.         fi
    74.         ;;
    75.   reload)
    76.         reload
    77.         ;;
    78.   *)
    79.         echo $"Usage: $prog
    80. {start|stop|restart|condrestart|reload|status}"
    81.         exit 1
    82. esac
    83.  
    84. exit $RETVAL
  • Make this file executable by using chmod u+x /etc/rc.d/init.d/xinetd
  • Create the links Snnxinetd and Knnxinetd in /etc/rc.d/rc2.d so that xinetd will start and stop whenever you restart and shutdown your VPS. Choose suitable unique numbers for nn. Packages are started and stopped in ascending order. I chose nn=100.
    • ln -s /etc/rc.d/init.d/xinetd /etc/rc.d/rc2.d/S100xinetd
    • ln -s /etc/rc.d/init.d/xinetd /etc/rc.d/rc2.d/K100xinetd

One thought on “Installing xinetd

  1. Pingback: Rolling Resource » Automatically Starting Programs with Linux

Comments are closed.