[svlug] Writing start-up scripts...

Seth David Schoen schoen at loyalty.org
Mon Mar 12 11:32:02 PST 2001


Eric Pretorious writes:

> Hello!
> 
> I've been trying to start qmail using a hacked version of the 
> /etc/init.d/httpd script from Redhat 7 but the script - /etc/init.d/smtp - 
> just hangs after echo'ing the message "Starting qmail: ". (Executing the 
> start-up script directly, `csh -cf '/var/qmail/rc'`, works just fine, 
> though.) I'm not familiar with shell scripting - could the error be caused 
> because /var/qmail/rc doesn't return a value to `RETVAL=$?` ? 
> (/etc/init.d/smtp stop works just great!)

Does /var/qmail/rc actually exit?  The "daemon" function in
/etc/rc.d/init.d/functions assumes that the program it calls will exit
or put itself in the background.  The symptom of this would be

Starting qmail: qmail

without a newline.

You should run Bourne shell scripts with sh instead of csh.  (Your
/var/qmail/rc doesn't do anything Bourne-shell specific, though,
which is why it worked with csh.)

If you want to see the steps in the script as they're executed,
do sh -x instead.

> Thanks in advance!
> Eric P.
> Los Gatos, CA
> 
> /var/qmail/rc
> =============
> #!/bin/sh
> exec env - PATH="/var/qmail/bin:$PATH" \
> qmail-start ./Mailbox splogger qmail
> 
> 
> /etc/init.d/smtp:
> ================
> #!/bin/sh
> #
> # Startup script for the qmail mail transfer agent (MTA)
> #
> 
> # Source function library.
> . /etc/rc.d/init.d/functions
> 
> # Path to the qmail boot script.
> qmail=/var/qmail/rc
> RETVAL=0
> 
> # Until glibc's locale support is working right again, work around it.
> LANG=C
> 
> # Change the major functions into functions.
> start() {
> 	echo -n "Starting qmail: "
> 	daemon ${qmail}
> 	RETVAL=$?
> 	echo
> 	[ $RETVAL = 0 ] && touch /var/lock/subsys/smtp
> 	return $RETVAL
> }
> stop() {
> 	echo -n "Shutting down qmail: "
> 	killproc qmail-send
> 	RETVAL=$?
> 	echo
> 	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/smtp
> 	return $RETVAL
> }
> 
> # See how we were called.
> case "$1" in
>   start)
> 	start
> 	;;
>   stop)
> 	stop
> 	;;
>   restart)
> 	stop
> 	start
> 	;;
> *)
> 	echo "Usage: $0 {start|stop|restart}"
> 	exit 1
> esac
> 
> exit $RETVAL

-- 
Seth David Schoen <schoen at loyalty.org>  | And do not say, I will study when I
Temp.  http://www.loyalty.org/~schoen/  | have leisure; for perhaps you will
down:  http://www.loyalty.org/   (CAF)  | not have leisure.  -- Pirke Avot 2:5




More information about the svlug mailing list