[ZODB-Dev] zeo, data.fs permissions

Mark McEahern mark@mceahern.com
Tue, 3 Sep 2002 11:10:26 -0500


[Jeremy Hylton [mailto:jeremy@zope.com]]
> I can given you some hints about the questions you.  The crucial one
> seems to be: "Why is there a Data.fs in /var/zope/var AND in
> /usr/share/zope/var?"  There should only be one Data.fs.
>
> I'm puzzled about where /var/zope/var comes from.  All the details of
> the steps you took talk about /usr/share/zope.  Did the other
> directory get created as an accident / byproduct of building the Zope
> RPMs?  I assume you want to use /usr/share/zope.

I assume /var/zope/ is a remnant of the Zope SRPM I used to build the Zope
RPM.  Since I'm a relative newbie in both Linux and Zope, I don't know
exactly what part of the SRPM.  Probably the thing they call the spec, but I
don't know yet how to read, modify that.  So I'll most likely take Guido's
advice to scrap the whole RPM thing for now.  ;-)

Here's one useful bit of information.  When I look at my Zope through the
ZMI, the control panel says that INSTANCE_HOME is /var/zope.  I found myself
thinking, "Well, if Zope isn't reading the /usr/share/zope/custom_zodb.py,
what if I put custom_zodb.py in /var/zope?"  It sure did read it.  But now
when I try to access http://localhost:8080/manage, the server times out.

> It is clear that ZEO is using /usr/share/zope at any rate, since you
> found permissions problems.  I guess the question should be: How is
> the Zope service getting started?  What code runs when you do
> "/sbin/service zope start" and why does it insist on using /var/zope?

That's a shell script in /etc/init.d/zope, presumably installed by the Zope
RPM (and appended to the bottom of this message, fwiw).  It does indeed set
INSTANCE_HOME=/var/zope.  Is that foobar?

> Note that Zope has a notion called the instance home, usually
> specified by the INSTANCE_HOME environment variable.  The instance
> home contains the var and lib (& lib/python &c) directories.  It might
> be possible to define INSTANCE_HOME when you start Zope.  I don't know
> if that will get passed on by /sbin/service.  There must be some way
> to tell Zope what directory to use as its instance home.
>
> Also, you should be able to read the log files in /usr/share/zope/var
> to see if ZEO is working correctly.  The server log should contain a
> log entry for every connection; like this: "connect from ('127.0.0.1',
> 12034): ...".

I'm still trying to figure out the logging.  Reading LOGGING.txt shed some
light on it.  What controls the ZEO logs -- are they distinct from Zope
logs?

Thanks,

// mark

This is /etc/init.d/zope:

#!/bin/sh
#
# zope          Start/Stop the Zope web-application server.
#
# chkconfig: 2345 72 72
# description: zope is a web server specifically for handling \
#              HTTP requests to the Zope web-application service.
# probe: true

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

# Extracted from 'functions' to augment it to obtain Zope's
# watchdog and server PIDs from the ${INSTANCE_HOME}/var/Z2.pid
# file, where both the parent and child processes are recorded
# in the _same_ file. <sigh>

# A function to find the pid of a program.
pidofproc() {
	# Test syntax.
	if [ $# = 0 ] ; then
		echo "Usage: pidofproc {program}"
		return 1
	fi

	# First try the "$INSTANCE_HOME/var/Z2.pid" file
	if [ -f ${INSTANCE_HOME}/var/Z2.pid ] ; then
	        if [ "$1" = "zwatchdog" ] ; then
	                pid=`sed -e 's/^\([0-9]\+\) [0-9]\+/\1/'
${INSTANCE_HOME}/var/Z2.pid`
		else
		        if [ "$1" = "zserver" ] ; then
		                pid=`sed -e 's/^[0-9]\+ \([0-9]\+\)/\1/'
${INSTANCE_HOME}/var/Z2.pid`
			fi
	        fi

		if [ "$pid" != "" ] ; then
			echo $pid
			return 0
		fi
	fi

	# Next try "/var/run/*.pid" files
	if [ -f /var/run/$1.pid ] ; then
	        pid=`head -1 /var/run/$1.pid`
	        if [ "$pid" != "" ] ; then
	                echo $pid
	                return 0
	        fi
	fi

	# Next try "pidof"
	pid=`pidof -o $$ -o $PPID -o %PPID -x $1`
	if [ "$pid" != "" ] ; then
	        echo $pid
	        return 0
	fi
}

# Extracted from 'functions' to fix a tiny bug where it uses 'pidof'
# but should be using 'pidofproc'.
status() {
	# Test syntax.
	if [ $# = 0 ] ; then
		echo "Usage: status {program}"
		return 1
	fi

	# First try "pidofproc"
	pid=`pidofproc $1`
	if [ "$pid" != "" ] && ps h $pid >/dev/null 2>&1 ; then
	        echo "$1 (pid $pid) is running..."
	        return 0
        else
		pid=`pidof -o $$ -o $PPID -o %PPID -x $1`
		if [ "$pid" != "" ] ; then
		        echo "$1 (pid $pid) is running..."
		        return 0
		fi
	fi

	# Next try "/var/run/*.pid" files
	if [ -f /var/run/$1.pid ] ; then
	        pid=`head -1 /var/run/$1.pid`
	        if [ "$pid" != "" ] ; then
	                echo "$1 dead but pid file exists"
	                return 1
	        fi
	fi

	# See if /var/lock/subsys/$1 exists
	if [ -f /var/lock/subsys/$1 ]; then
		echo "$1 dead but subsys locked"
		return 2
	fi
	echo "$1 is stopped"
	return 3
}

INSTANCE_HOME=/var/zope
INSTANCE_NAME=`basename ${INSTANCE_HOME}`

# make sure starter script exists
[ -f ${INSTANCE_HOME}/zserver.sh ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting zope: "
  	cd ${INSTANCE_HOME}

	# See if it's already running.
	pid=`pidofproc zwatchdog`
	[ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && echo && exit $RETVAL

	pid=`pidofproc zserver`
	[ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && echo && exit $RETVAL

	rm -f ${INSTANCE_HOME}/var/Z2.pid
	daemon ${INSTANCE_HOME}/zserver.sh
	RETVAL=$?
  	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/${INSTANCE_NAME}
  	;;
  stop)
	echo -n "Shutting down zope: "
	killproc zwatchdog
	killproc zserver
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${INSTANCE_NAME}
${INSTANCE_HOME}/var/Z2.pid
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  status)
	status zwatchdog
	[ $RETVAL -ne 0 ] && RETVAL=$?
	status zserver
	[ $RETVAL -ne 0 ] && RETVAL=$?
	;;
  probe)
	# echo command to start/restart zope, only if NOT already running...
	# (this is a linuxconf convention, using the probe keyword above)
	if [ ! -f /var/lock/subsys/${INSTANCE_NAME} ] ; then
		echo start; exit 0
	fi

	pid=`pidofproc zwatchdog`
	[ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && exit $RETVAL

	pid=`pidofproc zserver`
	[ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && exit $RETVAL

	echo restart; exit 0
	;;
  *)
	echo "Usage: zope {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL

-