[Zope] My custom scripts for starting/stopping multiple Zope instances

Chris McDonough chrism@digicool.com
Tue, 01 Feb 2000 15:32:17 -0500


Jim, many thanks!!

Do you think you can make this into a HOW-TO on Zope.org?

Jim Cain wrote:
> 
> All,
> 
> There have been some questions on here recently on how to start and stop
> Zope. The system I've created may not be the fanciest, but it works for
> me.
> 
> It all begins with the standard SysV script in /etc/rc.d/init.d, which
> calls zstart and zstop as appropriate. This is fairly standard, and I
> won't bore you with the contents of my script here.
> 
> zstart and zstop both read configuration files in /etc/zope.d/*, which
> currently contains two files: env and instances. The env file is sourced
> to redefine defaults that are set in zstart and zstop. The instances file
> describes how to start z2.py. I run ZServer on Red Hat 6.0 from behind
> Apache.
> 
> Here is env:
> 
> ---begin---
> # /etc/zope.d/env
> #
> # Set environment variables that differ from default
> 
> ZOPE_USER=www
> ZOPE_BASE=/usr/local/Zope
> ---end---
> 
> Here is instances:
> 
> ---begin---
> # /etc/zope.d/instances
> #
> # instance_name ftp_port n_threads use_manager
> #
> polonius        8022    2       0
> gertrude        8023    2       1
> ---end---
> 
> Here is zstart:
> 
> ---start---
> #!/bin/bash
> 
> #
> # Set default environment
> #
> 
> ENV_FILE=/etc/zope.d/env
> INSTANCES_FILE=/etc/zope.d/instances
> ZOPE_USER=nobody
> ZOPE_BASE=/opt/Zope
> CGIBIN_BASE=/home/httpd/cgi-bin
> INSTANCE_BASE=/home/httpd/zope
> PS="ps wax"
> PYTHON=/usr/local/bin/python
> 
> #
> # process command line options
> #
> 
> while getopts "c:" opt
> do
>         case "$opt" in
>                 i)      if [ -r "$OPTARG" ]
>                         then
>                                 INSTANCES_FILE=$OPTARG
>                         else
>                                 echo "$0: cannot read $OPTARG"
>                                 exit 1
>                         fi
>                         ;;
> 
>                 e)      if [ -r "$OPTARG" ]
>                         then
>                                 ENV_FILE=$OPTARG
>                         else
>                                 echo "$0: cannot read $OPTARG"
>                                 exit 1
>                         fi
>                         ;;
> 
>                 ?)      echo "Usage: $0 [-i instances-file] [-e environment-file]"
>                         exit 3
>                         ;;
>         esac
> done
> 
> #
> # Read environment file
> #
> 
> . "$ENV_FILE"
> 
> #
> # is_running instance_name
> #
> 
> is_running ()
> {
>         if $PS | grep -v grep | grep "z2\.py.*$1" > /dev/null 2>&1
>         then
>                 echo yes
>         else
>                 echo no
>         fi
> }
> 
> #
> # start_instance instance_name ftp_port n_threads use_manager
> #
> 
> start_instance ()
> {
>         if [ "$4" = "0" ]
>         then
>                 manager=
>         else
>                 manager="-Z $INSTANCE_BASE/$1/manager.pid"
>         fi
> 
>         su $ZOPE_USER -c \
>                 "$PYTHON $ZOPE_BASE/z2.py \
>                 -p $CGIBIN_BASE/$1/Zope.cgi \
>                 -w '' -m '' -f $2 -t $3 $manager\
>                 INSTANCE_HOME=$INSTANCE_BASE/$1 \
>                 >> $INSTANCE_BASE/$1/z2.log 2>&1 &"
> }
> 
> ###############################################################################
> #
> # Main program
> #
> 
> awk 'substr($1, 0, 1) != "#" {print $0}' $INSTANCES_FILE | (
> while read line; do
>         set $line
>         if [ "`is_running $1`" = "yes" ]
>         then
>                 echo "$0: Warning: instance $1 already running"
>         else
>                 start_instance $1 $2 $3 $4
>         fi
> done)
> ---end---
> 
> Here is zstop:
> 
> ---begin---
> #!/bin/bash
> 
> #
> # Set default environment
> #
> 
> ENV_FILE=/etc/zope.d/env
> INSTANCES_FILE=/etc/zope.d/instances
> ZOPE_USER=nobody
> ZOPE_BASE=/usr/local/Zope
> CGIBIN_BASE=/home/httpd/cgi-bin
> INSTANCE_BASE=/home/httpd/zope
> PS="ps wax"
> PYTHON=/usr/local/bin/python
> 
> #
> # process command line options
> #
> 
> while getopts "c:" opt
> do
>         case "$opt" in
>                 i)      if [ -r "$OPTARG" ]
>                         then
>                                 INSTANCES_FILE=$OPTARG
>                         else
>                                 echo "$0: cannot read $OPTARG"
>                                 exit 1
>                         fi
>                         ;;
> 
>                 e)      if [ -r "$OPTARG" ]
>                         then
>                                 ENV_FILE=$OPTARG
>                         else
>                                 echo "$0: cannot read $OPTARG"
>                                 exit 1
>                         fi
>                         ;;
> 
>                 ?)      echo "Usage: $0 [-i instances-file] [-e environment-file]"
>                         exit 3
>                         ;;
>         esac
> done
> 
> #
> # Read environment file
> #
> 
> . "$ENV_FILE"
> 
> #
> # stop_instance instance_name use_manager
> #
> 
> stop_instance ()
> {
>         if [ "$2" = "0" ]
>         then
>                 pidfile=pcgi.pid
>         else
>                 pidfile=manager.pid
>         fi
> 
>         kill `cat "$INSTANCE_BASE/$1/var/Z2.pid"` # > /dev/null 2>&1
> }
> 
> ###############################################################################
> #
> # Main program
> #
> 
> awk 'substr($1, 0, 1) != "#" {print $0}' $INSTANCES_FILE | (
> while read line; do
>         set $line
>         stop_instance $1
> done)
> ---end---
> 
> Hope some people find this helpful. If it's helpful enough, maybe I'll
> submit it as a HOWTO on Zope.org.
> 
> Cheers,
> Jim
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

-- 
Chris McDonough - Digital Creations, Inc.
Publishers of Zope - http://www.zope.org