#!/bin/sh # # /usr/sbin/zopectl # # Written by Gregor Hoffleit for the Debian Zope package. # # License: Feel free to use, share and modify this code as you like. # # # This is a comfortable replacement for Zope's start and stop scripts # It let's you start, stop, restart and examine a Zope process managed # by a zdaemon. # OPTION=$1 shift # # You might want to modify the following settings (the defaults are # valid for Debian's Zope installation): # ZOPE_HOME=/usr/lib/zope INSTANCE_HOME=/var/lib/zope zdaemon_pidfile=$INSTANCE_HOME/var/zProcessManager.pid zdaemon_logfile=$INSTANCE_HOME/var/Z2_debug.log zope_pidfile=$INSTANCE_HOME/var/Z2.pid zope_logfile=$INSTANCE_HOME/var/Z2.log PYTHONHOME=$ZOPE_HOME export INSTANCE_HOME PYTHONHOME test_zdaemon() { if [ -f $zdaemon_pidfile ]; then zdaemon_pid=`cat $zdaemon_pidfile` if [ ! "x$zdaemon_pid" = "x" ] && kill -0 $zdaemon_pid 2>/dev/null; then zdaemon=1 true else zdaemon=-1 rm -f $zdaemon_pidfile false fi else zdaemon=0 false fi } test_zope() { if [ -f $zope_pidfile ]; then zope_pid=`cat $zope_pidfile | cut -d' ' -f2` if [ ! "x$zope_pid" = "x" ] && kill -0 $zope_pid 2>/dev/null; then zope=1 true else zope=-1 false fi else zope=0 false fi } start_zdaemon() { # /usr/sbin/zope-z2 -D $@ \ # >>$zdaemon_logfile 2>>$zdaemon_logfile & /usr/sbin/zope-z2 $@ } stop_zdaemon() { test_zdaemon if [ $zdaemon -eq 1 ]; then kill $zdaemon_pid 2>/dev/null && true test_zdaemon if [ $zdaemon -eq -1 ]; then rm -f $zdaemon_pidfile fi else if [ $zdaemon -eq -1 ]; then rm -f $zdaemon_pidfile echo "Removed stale zdaemon pidfile (pid $zdaemon_pid)." fi fi } stop_zope() { test_zope if [ $zope -eq 1 ]; then kill $zope_pid 2>/dev/null && true test_zope if [ $zope -eq -1 ]; then rm -f $zope_pidfile fi else if [ $zope -eq -1 ]; then rm -f $zope_pidfile echo "Removed stale zope pidfile (pid $zope_pid)." fi fi } case $OPTION in status) test_zdaemon test_zope if [ $zdaemon -eq 1 ]; then if [ $zope -eq 1 ]; then echo "Zope running (pids $zdaemon_pid, $zope_pid)." else echo "Zope (re)starting (zdaemon pid $zdaemon_pid)." fi else if [ $zope -eq 1 ]; then echo "Found zope process (pid $zope_pid), but no zdaemon." else echo "Zope not running." fi fi ;; start) test_zdaemon test_zope if [ ! $zdaemon -eq 1 ] && [ ! $zope -eq 1 ]; then start_zdaemon echo "Zope started." else if [ $zdaemon -eq 1 ] && [ $zope -eq 1 ]; then echo "Zope already running." false else if [ $zdaemon -eq 1 ]; then echo "Zope currently restarting." else echo "Only z2 running. This should not happen." fi false fi fi ;; stop) test_zdaemon test_zope if [ $zdaemon -eq 0 ] && [ $zdaemon -eq 0 ]; then echo "Zope not running." not_running=1 else not_running=0 fi if [ $zdaemon -eq 1 ]; then stop_zdaemon echo "zdaemon process killed (pid $zdaemon_pid)." else if [ $zdaemon -eq -1 ]; then rm -f $zdaemon_pidfile echo "Removed stale zdaemon pidfile (pid $zdaemon_pid)." fi fi test_zope if [ $zope -eq 1 ]; then stop_zope echo "zope process killed (pid $zope_pid)." else if [ $zope -eq -1 ]; then rm -f $zope_pidfile echo "Removed stale zope pidfile (pid $zope_pid)." fi fi if [ $not_running -eq 0 ]; then echo "Zope stopped." fi ;; restart) test_zdaemon test_zope if [ ! $zdaemon -eq 1 ] && [ ! $zope -eq 1 ]; then start_zdaemon echo "Zope started." else if [ $zdaemon -eq 1 ] && [ $zope -eq 1 ]; then echo "Restarting zope process (old pid $zope_pid)." stop_zope else echo "Zope currently restarting or something strange." fi fi ;; *) echo "Usage: $0 (start|stop|restart|status)" ;; esac