On Fri, 2007-07-06 at 23:19 +0200, Jim Meyering wrote:
> Here's a proposed change:
>
> Update for Fedora/LSB init-scripts guidelines:
> <http://fedoraproject.org/wiki/FCNewInit/Initscripts>
> * etc/qpidd: Provide an LSB header.
> Allow options to be specified via QPIDD_OPTIONS=...
> in /etc/sysconfig/qpidd.
> Diagnose and 'exit 3' for the unsupported "reload".
> Don't mention unused $pidfile.
> Remove useless curly braces: ${lockfile} -> $lockfile.
> Write usage and error diagnostics to stderr, not stdout.
> Change spelling: condrestart -> try-restart.
>
> I'm not sure about the Default-Start/Stop run levels.
> If something different would be better, let me know.
>
> This little excursion leads me to propose a small
> improvement for qpidd: give qpidd a --pidfile=F (-p) option,
> whereby it would write its PID into the file F. This is better
> than relying on the default pidof-related machinery, for when the
> driver program is a script (e.g., a valgrind-running wrapper).
>
> Hmm... Since we're invoking qpid via the "daemon" function,
> I wonder if using qpid's --daemon option is unnecessary.
> At least it sure looks that way. For now I'm leaving it.
> Comments?
My original intent was to replace use of daemon in init scripts with the
--daemon flag.
--daemon has some advantages over the daemon script:
- The foreground process waits until the daemon is ready to start
processing requests before returning.
- The foreground process reports the actual port bound to by the daemon
if you specify --port 0.
- Allows you to stop a daemon by port number rather than by pid.
These points (first two in particular) are invaluable for testing, but
not very important for deployment, so moving the init scripts to
--daemon is nice-to-have but not really critical.
>
> Index: etc/qpidd
> ===================================================================
> --- etc/qpidd (revision 553520)
> +++ etc/qpidd (working copy)
> @@ -2,10 +2,21 @@
> #
> # qpidd Startup script for the Qpid messaging daemon.
> #
> +
> +### BEGIN INIT INFO
> +# Provides: qpidd
> +# Required-Start: $local_fs
> +# Required-Stop: $local_fs
> +# Default-Start: 2 3 4 5
> +# Default-Stop: 0 1 6
> +# Short-Description: start or stop qpidd
> +# Description: Qpidd is an AMQP broker. It receives, stores, routes and
> +# forwards messages using the AMQP protcol.
> +### END INIT INFO
> +
> # chkconfig: - 85 15
> # description: Qpidd is an AMQP broker. It receives, stores, routes and
> forwards messages using the AMQP protcol.
> # processname: qpidd
> -#
>
> prog=qpidd
> lockfile=/var/lock/subsys/$prog
> @@ -13,15 +24,20 @@
> # Source function library.
> . /etc/rc.d/init.d/functions
>
> +QPIDD_OPTIONS=
> +if [ -f /etc/sysconfig/$prog ] ; then
> + . /etc/sysconfig/$prog
> +fi
> +
> RETVAL=0
>
> start() {
> - echo -n $"Starting Qpid AMQP daemon: "
> - daemon $prog --daemon
> - RETVAL=$?
> - echo
> - [ $RETVAL = 0 ] && touch ${lockfile}
> - return $RETVAL
> + echo -n $"Starting Qpid AMQP daemon: "
> + daemon --check $prog $prog --daemon $QPIDD_OPTIONS
> + RETVAL=$?
> + echo
> + [ $RETVAL = 0 ] && touch $lockfile
> + return $RETVAL
> }
>
> stop() {
> @@ -29,9 +45,14 @@
> killproc $prog
> RETVAL=$?
> echo
> - [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> + [ $RETVAL = 0 ] && rm -f $lockfile
> }
>
> +reload() {
> + echo 1>&2 $"$0: reload not supported"
> + exit 3
> +}
> +
> restart() {
> stop
> start
> @@ -39,27 +60,21 @@
>
> # See how we were called.
> case "$1" in
> - start)
> - start
> + start|stop|restart|reload)
> + $1
> ;;
> - stop)
> - stop
> - ;;
> status)
> - status $prog
> + status $prog
> RETVAL=$?
> ;;
> - restart|reload)
> + force-reload)
> restart
> ;;
> - condrestart)
> - if [ -e $lockfile ] ; then restart ; fi
> + try-restart)
> + [ -e $lockfile ] && restart || :
> ;;
> - reload)
> - reload
> - ;;
> *)
> - echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
> + echo 1>&2 $"Usage: $0 {start|stop|restart|condrestart|status}"
> exit 1
> esac
>