Ubuntu/Debian init.d script for Zope/Plone

Posted by Sim at Jun 19, 2008 02:35 PM |
Filed under: , , ,

Here is yet another script for starting up Zope/Plone instances. This one is Ubuntu/Debian compatible and allows for starting up multiple instances. It is also compatible with the newer "bin/instance" controller, and doesn't assume "zopectl".

Here is the init.d script file:

/etc/init.d/zope

#! /bin/sh -e
#### BEGIN INIT INFO
# Provides:          zope
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start zope instances
# Description:       Debian init script for the starting zope
#                    instances.  Basically just calls "bin/instance".
### END INIT INFO
#
# Author:    Sim Harbert 
#
set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin

#
# Configuration file for zope instances.
# At miniumum should have:
#
# ZOPE_INSTANCES="/home/zope/plone_fptd/bin/instance"
#
conf="/etc/default/zope"
# Exit if not found.
test -f "$conf" || exit 0
. "$conf"

. /lib/lsb/init-functions

for instance in $ZOPE_INSTANCES ; do
    # Use \\ to allow us to handle space betwee it and the operation arg.
    cmd="su zope -c '$instance'\\"
    RETVAL=0
    case "$1" in
    start)
        log_daemon_msg "Starting: $instance"
        echo -n "     "
        if eval $cmd status | grep 'program running;' ; then
        continue
        fi
        eval $cmd start
        if ! eval $cmd status | grep 'program running;' >/dev/null ; then
        log_end_msg 1
        RETVAL=1
        fi
        log_end_msg 0
        ;;
    stop)
        log_daemon_msg "Stopping: $instance"
        echo -n "     "
            eval $cmd stop
        if eval $cmd status | grep 'program running;' >/dev/null ; then
        log_end_msg 1
        RETVAL=1
        fi
        log_end_msg 0
        ;;
    restart)
        log_daemon_msg "Restarting: $instance"
        echo -n "     "
            eval $cmd restart
        if ! eval $cmd status | grep 'program running;' >/dev/null ; then
        log_end_msg 1
        RETVAL=1
        fi
        log_end_msg 0
        ;;
    status)
            RETVAL=0
        log_daemon_msg "Status: $instance"
        echo -n "     "
        eval $cmd status
        ;;
    *)
        echo "Usage: /etc/init.d/atd {start|stop|restart|status}"
        exit 1
        ;;
    esac
done

 

And here is the corresponding configuration file:

/etc/default/zope

#                                                                              
# Configuration for zope services included                                     
# by /etc/init.d/zope                                                          
#                                                                              
# This is a space separated list of zope instances control scripts.            
# It can be old style ones with "bin/zopectl" or new ones with                 
# "bin/instance" as long as the script takes the 'start', 'stop', and          
# 'restart' arguments.                                                         
#                                                                              
# ZOPE_INSTANCES="/home/zope/myzope/bin/instance"                              
#                                                                              
ZOPE_INSTANCES="/home/zope/myzope/bin/instance"

Document Actions