[Zope-Checkins] CVS: Zope/inst - custom_zodb.py.in:1.1.2.1 make_instance.py:1.3.4.6 zctl.in:1.1.2.2 zope.conf.in:1.1.2.2

Chris McDonough chrism@zope.com
Mon, 2 Sep 2002 03:35:40 -0400


Update of /cvs-repository/Zope/inst
In directory cvs.zope.org:/tmp/cvs-serv17315/inst

Modified Files:
      Tag: chrism-install-branch
	make_instance.py zctl.in zope.conf.in 
Added Files:
      Tag: chrism-install-branch
	custom_zodb.py.in 
Log Message:
Overhaul of installer branch.

z2.py is no longer necessary (nor used in the default config).  
In prior iterations of the installer branch, the "controller" process
(zctl) "front-ended" for z2.py, translating environment variables and
command-line options as necessary to pass in to z2.py.

In this iteration, a new file named "zope.py" is responsible for starting
the Zope process.  It reads configuration directives directly and has
the capability to obtain a configuration from a file or via XML-RPC.
z2.py still exists in the branch, but it's unused.

The zope.py file can be used to start Zope, but a nicer front-end
for it is "zctl", which is a heavily-modified offshoot of Tres'
"zopectl".  The zctl module is now generalized enough that it
*might* be able to run on Windows (I haven't tested it, though).

zctl is still a standalone process.  This is to allow for the fact that
Windows doesn't have os.fork (or zctl would have just imported zope.py
and forked).

In order to maintain cross-platform capability, the "logtail" option
of zctl was removed.  We should create a Python "tail" function
to get around this.

Niceties: zctl is able to tell if its Zope is already running (so you
cant inadvertently start it twice).  The Z2.pid file is cleaned up
when Zope exits, also.

A small bug in FindHomes.py was also fixed (dont add SOFTWARE_HOME to
sys.path if it's already in there).  Additionally, zdaemon was modified
so that if a child Zope process exits with error code 255, the daemon
process does not restart it (not strictly necessary, but nice to have).


=== Added File Zope/inst/custom_zodb.py.in ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
Create the storage for the Zope appserver.  If you don't know what
you're doing, do not change this file or remove it from your instance
home or your Zope instance will likely not work properly, especially if
you use ZEO.
"""

__version__='$Revision: 1.1.2.1 $'[11:-2]

import warnings, traceback
import sys, os
import zLOG
from Controller import Directives

def get(directive):
    return directive.value

INSTANCE_HOME = get(Directives.instance_home)

if get(Directives.use_zeo_server):
    port         = None
    path         = None
    hostname     = get(Directives.zeo_storage_server_name)
    port_or_path = get(Directives.zeo_storage_server_port)
    storage_name = get(Directives.zeo_storage_server_storagename) or '1'
    cache_size   = get(Directives.zeo_client_cache_size) or 200000000
    debug        = get(Directives.zeo_client_debug) or 0
    cache_dir    = (get(Directives.zeo_client_cache_directory) or
                    os.path.join(INSTANCE_HOME, 'var'))
    max_disconn  = get(Directives.zeo_client_max_disconnect_poll) or 300
    min_disconn  = get(Directives.zeo_client_min_disconnect_poll) or 5
    wait         = (get(Directives.zeo_client_wait_for_server_on_startup)
                    or 0)
    client_name  = get(Directives.zeo_client_name) or ''
    try:
        port = int(port_or_path)
        conn = (hostname, port)
    except:
        conn = path
    try:
        import ZServer
        import ZEO.ClientStorage
        # we left out "name" here but it's ok as it's just the
        # "pretty name" shown in the control panel
        Storage = ZEO.ClientStorage.ClientStorage(
            connection=conn, storage=storage_name, cache_size=cache_size,
            client=client_name, debug=debug, var=cache_dir,
            min_disconnect_poll=min_disconn, max_disconnect_poll=max_disconn,
            wait_for_server_on_startup=wait)
    except:
        zLOG.LOG('custom_zodb', 100, 'Could not use ZEO!', err=sys.exc_info())
        traceback.print_exc()
        err = ('Could not successfully start Zope due to ZEO configuration '
               'error!  Clues exist in the traceback printed above.  Check '
               'your zope.conf file for a misconfiguration.')
        warnings.warn(err)
        # exit the process instead of silently using a FileStorage
        sys.exit(127)

else:
    import ZODB.FileStorage
    default = os.path.join(INSTANCE_HOME, 'var')
    filename = get(Directives.zodb_filestorage_filepath) or default
    Storage = ZODB.FileStorage.FileStorage(filename)

# use environment to try to get cache size and pool size
# parameters
pool_size  = get(Directives.zodb_db_pool_size) or 7
cache_size = get(Directives.zodb_db_cache_size) or 5000

DB=ZODB.DB(Storage, pool_size=pool_size, cache_size=cache_size)


=== Zope/inst/make_instance.py 1.3.4.5 => 1.3.4.6 ===
--- Zope/inst/make_instance.py:1.3.4.5	Thu Aug 29 12:38:14 2002
+++ Zope/inst/make_instance.py	Mon Sep  2 03:35:09 2002
@@ -104,7 +104,7 @@
 
     # Set up other *.in files
     # Note: They will be %-substituted, so quote '%'s!
-    idata = {'python': sys.executable, 'software_home': home}
+    idata = {'<<PYTHON>>': sys.executable, '<<ZOPE_HOME>>': home}
     from glob import glob
     for infile in glob(os.path.join(home, 'inst', '*.in')):
         fn = os.path.split(infile)[1][:-3]
@@ -112,7 +112,9 @@
         if os.path.exists(target):
             print '%s exists, so I left it alone' % fn
         else:
-            txt = open(infile, 'rb').read() % idata
+            txt = open(infile, 'rb').read()
+            for k, v in idata.items():
+                txt = txt.replace(k, v)
             outfile = open(target, 'wb')
             outfile.write(txt)
             outfile.close()


=== Zope/inst/zctl.in 1.1.2.1 => 1.1.2.2 === (499/599 lines abridged)
--- Zope/inst/zctl.in:1.1.2.1	Thu Aug 29 01:22:08 2002
+++ Zope/inst/zctl.in	Mon Sep  2 03:35:09 2002
@@ -1,26 +1,65 @@
-#!%(python)s
+#!<<PYTHON>>
+##############################################################################
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
 """
-    Zope appserver controller.
+    Zope appserver controller.  This is akin to apache's apachectl,
+    except with an interactive interpreter if no commands are specified
+    on the command-line.
 """
-import os, sys
-SOFTWARE_HOME = '%(software_home)s/lib/python'
+
+__version__ = '$Revision$'[11:-2]
+
+import getopt, os, sys, re, signal, cmd, time
+try:
+    import readline
+except:
+    pass
+
+_marker = []
+
+ZOPE_HOME     = '<<ZOPE_HOME>>'
+SOFTWARE_HOME = os.path.join(ZOPE_HOME, 'lib', 'python')
+
+sys.path.insert(0, SOFTWARE_HOME)
+sys.path = filter(None, sys.path)
+
+from Controller.Main import parse_config_file, get_xmlrpc_config, \
+     Configuration, lock_file
+from Controller import TextBlockFormatter
 
 USAGE = """\
 
-zopectl:  Zope appserver controller
+zctl:  Zope appserver controller

[-=- -=- -=- 499 lines omitted -=- -=- -=-]

-            else:
+        for k, v in o:
+            if k in ('-h', '--help'):
                 usage()
-
-        if args:
-            self.cmdqueue.append( ' '.join( args ) )
+                sys.exit(0)
+            elif k == '--config-file':
+                filename = v
+            elif k == '--config-url':
+                url = v
+        if url:
+            self._engine._setConfig(Configuration(get_xmlrpc_config(url)))
+            self._engine._setConfigPath(url)
+        else:
+            self._engine._setConfig(Configuration(parse_config_file(filename)))
+            self._engine._setConfigPath(filename)
+        self._engine._setCommandLineOpts(o)
+        if a:
+            self.cmdqueue.append( ' '.join( a ) )
             self.cmdqueue.append( 'EOF' )
 
         self.cmdloop()
+
+def get_pids(filename):
+    for line in open(filename).readlines():
+        pids = line.split()
+        if pids:
+            return [ int(x.strip()) for x in pids ]
+
+def kill(pid, sig):
+    if sys.platform == 'win32':
+        # we ignore the signal on win32
+        import win32api
+        handle = win32api.OpenProcess(1, 0, pid)
+        try:
+            return (0 != win32api.TerminateProcess(handle, 0))
+        except:
+            return 1
+    else:
+        try:
+            os.kill(pid, sig)
+        except OSError, why:
+            return 1
+        else:
+            return 0
 
 if __name__ == '__main__':
 


=== Zope/inst/zope.conf.in 1.1.2.1 => 1.1.2.2 === (591/691 lines abridged)
--- Zope/inst/zope.conf.in:1.1.2.1	Mon Aug 26 02:22:36 2002
+++ Zope/inst/zope.conf.in	Mon Sep  2 03:35:09 2002
@@ -1,55 +1,49 @@
-###############################################################################
-# Welcome to Zope 2.
-###############################################################################
-
-# This is the default Zope configuration file.  The default Zope configuration
-# file shows what the default configuration directives are, and show examples
-# for each directive.  To declare a directive, make sure that you add it
-# to a line that does not begin with "#".
 
-# Directive: software_home
+# Directive: zope_home
 #
 # Description:
-#     The path to the majority of the Python software files used by Zope.
+#     The 'top-level' Zope software directory (home of the Zserver
+#     directory, the doc directory, the utilities directory, etc.)
 #
-# Influences: SOFTWARE_HOME environment variable
+# Influences: ZOPE_HOME environment variable
 #
-# Default: none
+# Default: The directory in which the 'zope.py' file (or other executable file used to start Zope) lives.
 #
 # Example:
 #
-#    software_home /home/chrism/software/Trunk/lib/python
+#    zope_home /home/chrism/software/Trunk
 #
 
+
 # Directive: instance_home
 #
 # Description:
 #     The path to the data files, local product files, import directory,
-#     and Extensions directory used by Zope. One software_home can support
-#     many instance_homes.
+#     and Extensions directory used by Zope.
 #
 # Influences: INSTANCE_HOME environment variable
 #
-# Default: none
+# Default: The current working directory when Zope is started.
 #
 # Example:
 #
 #    instance_home /home/chrism/projects/sessions
 #

[-=- -=- -=- 591 lines omitted -=- -=- -=-]

+#     The minimum number of seconds that a ClientStorage will wait before
+#     retrying a connection after a failure. The default is 5 if this is
+#     left unset.
+#
+# Influences: special (custom_zodb.py) command-line switch to z2.py
+#
+# Default: 5
+#
+# Example:
+#
+#    zeo_client_min_disconnect_poll 10
+#
+
+
+# Directive: zeo_client_max_disconnect_poll
+#
+# Description:
+#     The maximum number of seconds that a ClientStorage will wait before
+#     retrying a connection after a failure. The default is 300 if this is
+#     left unset.
+#
+# Influences: special (custom_zodb.py) command-line switch to z2.py
+#
+# Default: 300
+#
+# Example:
+#
+#    zeo_client_max_disconnect_poll 300
+#
+
+
+# Directive: zeo_client_wait_for_server_on_startup
+#
+# Description:
+#     If this is set to "on", the ZEO ClientStorage will wait for a
+#     connection to its storage before serving data. If this is set to
+#     "off", the ZEO ClientStorage will attempt to serve data out of its
+#     cache file at startup even if it cannot make a connection to a
+#     storage server.
+#
+# Influences: special (custom_zodb.py) command-line switch to z2.py
+#
+# Default: off
+#
+# Example:
+#
+#    zeo_client_wait_for_server_on_startup on
+#
+
+