Commit e0dd5f5e authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid duplication of code between zopectl and zdaemon.

parent 9c6ed42d
...@@ -11,8 +11,16 @@ ...@@ -11,8 +11,16 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""
The Zope run script.
"""Command-line processor for Zope.""" Usage: runzope [-C URL][-h] [options]
Options:
-C/--configure URL -- configuration file or URL
-X -- overwrite config file settings, e.g. -X "debug-mode=on"
-h/--help -- print this usage message and exit
"""
import os import os
...@@ -20,30 +28,9 @@ import zdaemon.zdoptions ...@@ -20,30 +28,9 @@ import zdaemon.zdoptions
class ZopeOptions(zdaemon.zdoptions.ZDOptions): class ZopeOptions(zdaemon.zdoptions.ZDOptions):
"""The Zope zdaemon runner script.
# Provide help message, without indentation.
Usage: python Zope2/run.py [-C URL][-h] [zdrun-options] [action [arguments]] __doc__ = __doc__
Options:
-C/--configure URL -- configuration file or URL
-h/--help -- print usage message and exit
-b/--backoff-limit SECONDS -- set backoff limit to SECONDS (default 10)
-d/--daemon -- run as a proper daemon; fork a subprocess, close files etc.
-f/--forever -- run forever (by default, exit when backoff limit is exceeded)
-h/--help -- print this usage message and exit
-s/--socket-name SOCKET -- Unix socket name for client (default "zdsock")
-u/--user USER -- run as this user (or numeric uid)
-m/--umask UMASK -- use this umask for daemon subprocess (default is 022)
-x/--exit-codes LIST -- list of fatal exit codes (default "0,2")
-z/--directory DIRECTORY -- directory to chdir to when using -d (default off)
action [arguments] -- see below
Actions are commands like "start", "stop" and "status". If -i is
specified or no action is specified on the command line, a "shell"
interpreting actions typed interactively is started (unless the
configuration option default_to_interactive is set to false). Use the
action "help" to find out about available actions.
"""
schemadir = os.path.dirname(os.path.abspath(__file__)) schemadir = os.path.dirname(os.path.abspath(__file__))
schemafile = "zopeschema.xml" schemafile = "zopeschema.xml"
...@@ -32,8 +32,7 @@ action [arguments] -- see below ...@@ -32,8 +32,7 @@ action [arguments] -- see below
Actions are commands like "start", "stop" and "status". If -i is Actions are commands like "start", "stop" and "status". If -i is
specified or no action is specified on the command line, a "shell" specified or no action is specified on the command line, a "shell"
interpreting actions typed interactively is started (unless the interpreting actions typed interactively is started. Use the
configuration option default_to_interactive is set to false). Use the
action "help" to find out about available actions. action "help" to find out about available actions.
""" """
...@@ -45,12 +44,10 @@ import signal ...@@ -45,12 +44,10 @@ import signal
import pkg_resources import pkg_resources
import zdaemon import zdaemon
import Zope2.Startup from zdaemon.zdctl import ZDCmd, ZDCtlOptions
from zdaemon.zdctl import ZDCmd
from zdaemon.zdoptions import ZDOptions
from ZConfig.components.logger.handlers import FileHandlerFactory from ZConfig.components.logger.handlers import FileHandlerFactory
from ZConfig.datatypes import existing_dirpath
from Zope2.Startup.options import ZopeOptions
if sys.version_info > (3, 0): if sys.version_info > (3, 0):
basestring = str basestring = str
...@@ -76,25 +73,23 @@ def quote_command(command): ...@@ -76,25 +73,23 @@ def quote_command(command):
return command return command
class ZopeCtlOptions(ZDOptions): class ZopeCtlOptions(ZopeOptions, ZDCtlOptions):
# Zope controller options. # Zope controller options.
# #
# After initialization, this should look very much like a # After initialization, this should look very much like a
# zdaemon.zdctl.ZDCtlOptions instance. Many of the attributes are # zdaemon.zdctl.ZDCtlOptions instance. Many of the attributes are
# initialized from different sources, however. # initialized from different sources, however.
# Provide help message, without indentation.
__doc__ = __doc__ __doc__ = __doc__
positional_args_allowed = 1 positional_args_allowed = True
schemadir = os.path.dirname(Zope2.Startup.__file__)
schemafile = "zopeschema.xml"
uid = gid = None
# this indicates that no explict program has been provided. # this indicates that no explicit program has been provided.
# the command line option can set this. # the command line option can set this.
program = None program = None
# this indicates that no explict socket name has been provided. # this indicates that no explicit socket name has been provided.
# the command line option can set this. # the command line option can set this.
sockname = None sockname = None
...@@ -104,29 +99,13 @@ class ZopeCtlOptions(ZDOptions): ...@@ -104,29 +99,13 @@ class ZopeCtlOptions(ZDOptions):
logsectionname = None logsectionname = None
def __init__(self): def __init__(self):
ZDOptions.__init__(self) ZDCtlOptions.__init__(self)
self.add("program", "runner.program", "p:", "program=",
handler=string_list)
self.add("backofflimit", "runner.backoff_limit",
"b:", "backoff-limit=", int, default=10)
self.add("daemon", "runner.daemon", "d", "daemon", flag=1, default=1)
self.add("forever", "runner.forever", "f", "forever",
flag=1, default=0)
self.add("hang_around", "runner.hang_around", default=0)
self.add("interactive", None, "i", "interactive", flag=1) self.add("interactive", None, "i", "interactive", flag=1)
self.add("default_to_interactive", "runner.default_to_interactive", self.add("default_to_interactive", "runner.default_to_interactive",
default=1) default=1)
self.add("logfile", None, "l:", "logfile=")
self.add("user", "runner.user", "u:", "user=")
self.add("prompt", "runner.prompt", default="zopectl>")
self.add("umask", "runner.umask", "m:", "umask=")
self.add("sockname", "runner.socket_name", "s:", "socket-name=",
existing_dirpath, default=None)
self.add("transcript", "runner.transcript", "t:", "transcript=",
default="/dev/null")
def realize(self, *args, **kw): def realize(self, *args, **kw):
ZDOptions.realize(self, *args, **kw) ZopeOptions.realize(self, *args, **kw)
# Additional checking of user option; set uid and gid # Additional checking of user option; set uid and gid
if self.user is not None: if self.user is not None:
import pwd import pwd
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment