Tclhttpd as a Unix service

ES: Here is an init script for running Tclhttpd as a RedHat 9 service. Copy to /etc/init.d/tclhttpd and run chkconfig --add tclhttpd then chkconfig --level 2345 tclhttpd on. For Linux distributions that use a similar init.d structure as RedHat, you can try adapting this script. Otherwise, use it as a guide for adapting an already-installed Apache init script (which is what I did).

Note that this script assumes that the Tclhttpd directory is /opt/tclhttpd/ (seemed logical). You can of course change that to whatever you want.

If you're running Gentoo Linux, I recommend you look here: [L1 ]

 #!/bin/sh
 # chkconfig: 235 99 10
 # description: Start or stop the Tclhttpd server
 #
 ### BEGIN INIT INFO
 # Provides: tclhttpd
 # Required-Start: $network
 # Required-Stop: $network
 # Default-Start: 2 3 5
 # Default-Stop: 0 1 6
 # Description: Start or stop the Tclhttpd server
 ### END INIT INFO

 # Edwin A. Suominen: Hacked from Apache httpd init script, licensed likewise.

 # Source function library.
 . /etc/rc.d/init.d/functions

 binDir=/opt/tclhttpd/bin
 interp=/usr/bin/tclhttpd
 lockfile=/var/lock/subsys/tclhttpd
 pidFile=/var/run/tclhttpd.pid
 name='tclhttpd'
 RETVAL=0

 setup () {
         # Ensure we have proper /etc/tclhttpd.conf setup
         local confFile1=$binDir/tclhttpd.rc
         local confFile2=/etc/tclhttpd.conf
         if [ ! -h $confFile1 ]
             then
             if [ ! -f $confFile2 ] && [ -f $confFile1 ]
                 then
                 mv $confFile1 $confFile2
             fi
             ln -s $confFile2 $confFile1
         fi

         # Ensure we have a script for starting the TCL interpreter
         # with httpd.tcl running
         if [ ! -x $interp ]
             then
             echo '#!/usr/bin/tclsh
             if { [file exists /var/lock/subsystem/tclhttpd] } { exit 1 }
             set fh [open /var/run/tclhttpd.pid w]
             puts $fh [pid]
             close $fh
             after 2000 {source /opt/tclhttpd/bin/httpd.tcl}
             vwait forever' > $interp
             chmod u+x $interp
         fi
 }
 start () {
         echo -n $"Starting $name: "
         $interp &
         RETVAL=$?
         echo
         [ $RETVAL = 0 ] && touch $lockfile
 }
 stop () {
         echo -n $"Stopping $name: "
         killproc $interp
         RETVAL=$?
         echo
         [ $RETVAL = 0 ] && rm -f $lockfile $pidfile
 }

 case "$1" in
 'start')
         setup
         start
         ;;
 'stop')
         stop
         ;;
 'status')
         status $interp
         RETVAL=$?
         ;;
 'restart')
         stop
         start
         ;;
 *)
         echo "Usage: $0 { start | stop | status | restart }"
         RETVAL=1
         ;;
 esac
 exit $RETVAL