changeset 3025:ccf6d7ffb310

standalone server integrated into 'moin' script command (moin server standalone --help), thanks to Forrest Voight
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 30 Jan 2008 09:36:59 +0100
parents a438cc63c626
children 6275f8695bc8
files MoinMoin/script/__init__.py MoinMoin/script/server/__init__.py MoinMoin/script/server/standalone.py docs/CHANGES moin.py setup.py
diffstat 6 files changed, 163 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/__init__.py	Tue Jan 29 17:18:06 2008 +0100
+++ b/MoinMoin/script/__init__.py	Wed Jan 30 09:36:59 2008 +0100
@@ -212,6 +212,8 @@
 
 moin ... migration data ...
 
+moin ... server standalone ...
+
 moin ... xmlrpc mailimport ...
 moin ... xmlrpc remote ...
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/server/__init__.py	Wed Jan 30 09:36:59 2008 +0100
@@ -0,0 +1,14 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - Server Script Package
+
+    @copyright: 2008 MoinMoin:ForrestVoight
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.util import pysupport
+
+# create a list of extension scripts from the subpackage directory
+server_scripts = pysupport.getPackageModules(__file__)
+modules = server_scripts
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/server/standalone.py	Wed Jan 30 09:36:59 2008 +0100
@@ -0,0 +1,135 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - run standalone server, optionally daemonizing it
+
+    @copyright: 2008 MoinMoin:ForrestVoight
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import os
+import sys
+import signal
+
+from MoinMoin.script import MoinScript
+from MoinMoin.server.server_standalone import StandaloneConfig, run
+from MoinMoin.server.daemon import Daemon
+
+class PluginScript(MoinScript):
+    def __init__(self, argv, def_values):
+        MoinScript.__init__(self, argv, def_values)
+        self.parser.add_option(
+            "--docs", dest="docs",
+            help="Set the documents directory. Default: wiki/htdocs or /usr/share/moin/htdocs"
+        )
+        self.parser.add_option(
+            "--user", dest="user",
+            help="Set the user to change to. UNIX only. Default: Don't change"
+        )
+        self.parser.add_option(
+            "--group", dest="group",
+            help="Set the group to change to. UNIX only. Default: Don't change"
+        )
+        self.parser.add_option(
+            "--port", dest="port", type="int",
+            help="Set the port to listen on. Default: 8080"
+        )
+        self.parser.add_option(
+            "--interface", dest="interface",
+            help="Set the ip to listen on. Use \"\" for all interfaces. Default: localhost"
+        )
+        self.parser.add_option(
+            "--serverClass", dest="serverClass",
+            help="Set the server model to use. Choices: ThreadPool, serverClass, Forking, Simple. Default: ThreadPool"
+        )
+        self.parser.add_option(
+            "--threadLimit", dest="threadLimit", type="int",
+            help="Set the maximum number of threads to use. Default: 10"
+        )
+        self.parser.add_option(
+            "--requestQueueSize", dest="requestQueueSize", type="int",
+            help="Set the size of the request queue. Default: 50"
+        )
+        self.parser.add_option(
+            "--start", dest="start", action="store_true",
+            help="Start server in background."
+        )
+        self.parser.add_option(
+            "--stop", dest="stop", action="store_true",
+            help="Stop server in background."
+        )
+        self.parser.add_option(
+            "--pidfile", dest="pidfile",
+            help="Set file to store pid of moin daemon in. Default: moin.pid"
+        )
+    
+    def mainloop(self):
+        # we don't expect non-option arguments
+        if self.args:
+            self.parser.error("incorrect number of arguments")
+        
+        thread_choices = ["ThreadPool", "Threading", "Forking", "Simple"]
+        serverClass = "ThreadPool"
+        if self.options.serverClass:
+            thread_choices2 = [x.upper() for x in thread_choices]
+            thread_choice = self.options.serverClass.upper()
+            try:
+                serverClass_index = thread_choices2.index(thread_choice)
+            except ValueError:
+                self.parser.error("invalid serverClass type")
+            serverClass = thread_choices[serverClass_index]
+       
+        pidfile = "moin.pid"
+        if self.options.pidfile:
+            pidfile = self.options.pidfile
+        
+        if self.options.stop:
+            try:
+                pids = open(pidfile, "r").read()
+            except IOError:
+                print "pid file not found (server not running?)"
+            else:
+                try:
+                    os.kill(int(pids), signal.SIGTERM)
+                except OSError:
+                    print "kill failed (server not running?)"
+            os.remove(pidfile)
+        else:
+            try:
+                if self.options.config_dir:
+                    sys.path.insert(0, self.options.config_dir)
+                from wikiserverconfig import Config
+            except ImportError:
+                Config = DefaultConfig
+            
+            if self.options.docs:
+                Config.docs = self.options.docs
+            if self.options.user:
+                Config.user = self.options.user
+            if self.options.port:
+                Config.port = self.options.port
+            if self.options.interface:
+                Config.interface = self.options.interface
+            Config.serverClass = serverClass + 'Server'
+            if self.options.threadLimit:
+                Config.threadLimit = self.options.threadLimit
+            if self.options.requestQueueSize:
+                Config.requestQueueSize = self.options.requestQueueSize
+            
+            if self.options.start:
+                daemon = Daemon('moin', run, Config)
+                daemon.pidfile = pidfile
+                daemon.do_start()
+            else:
+                run(Config)
+
+class DefaultConfig(StandaloneConfig):
+    docs = os.path.join('wiki', 'htdocs')
+    if not os.path.exists(docs):
+        docs = "/usr/share/moin/htdocs"
+    user = ''
+    group = ''
+    port = 8080
+    interface = 'localhost'
+    serverClass = 'ThreadPoolServer'
+    threadLimit = 10
+    requestQueueSize = 50
--- a/docs/CHANGES	Tue Jan 29 17:18:06 2008 +0100
+++ b/docs/CHANGES	Wed Jan 30 09:36:59 2008 +0100
@@ -75,6 +75,8 @@
       Use password_checker = None to disable password checking.
     * jabber notification support; for more information see:
       http://moinmo.in/MoinMoinTodo/Release_1.7/HelpOnNotification
+    * standalone server can now be started via the "moin" script command,
+      optionally backgrounding itself. See: moin server standalone --help
 
   Bugfixes:
     * lots of bugfixes related to link parsing
--- a/moin.py	Tue Jan 29 17:18:06 2008 +0100
+++ b/moin.py	Wed Jan 30 09:36:59 2008 +0100
@@ -2,147 +2,23 @@
 """
     Start script for the standalone Wiki server.
 
-    @copyright: 2004-2006 Nir Soffer, Alexander Schremmer,
-                2004-2007 MoinMoin:Thomas Waldmann
+    @copyright: 2007 MoinMoin:ForrestVoight
     @license: GNU GPL, see COPYING for details.
 """
 
-print "Loading ..."
-
-import os, sys
-
-class PythonTooOldError:
-    pass
+import sys
+import os
 
-try:
-    if sys.version_info[:3] < (2, 3, 0):
-        raise PythonTooOldError
-except:
-    sys.exit("Unfortunately, your installed Python is too old. Please download at "
-             "least Python 2.3.0 (the latest Python 2.4.x or 2.5.x release is recommended).\n\n"
-             "You can get Python here: http://www.python.org/download/")
-
-
-# We insert the path where THIS script is located into the python search path.
-# If your wikiconfig.py / farmconfig.py / etc. is located there, this is all
-# you'll need.
-moinpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
-sys.path.insert(0, moinpath)
-
-# Path of the directory where wikiconfig.py is located.
-# YOU MAYBE NEED TO CHANGE THIS TO MATCH YOUR SETUP.
-#sys.path.insert(0, '/path/to/wikiconfig')
+from MoinMoin.script import MoinScript
 
 # Path to MoinMoin package, needed if you installed with --prefix=PREFIX
 # or if you did not use setup.py.
 #sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
 
-# Path of the directory where farmconfig is located (if different).
-#sys.path.insert(0, '/path/to/farmconfig')
-
-# Debug mode - show detailed error reports
-## import os
-## os.environ['MOIN_DEBUG'] = '1'
-
-from MoinMoin.server.server_standalone import StandaloneConfig, run
-from MoinMoin.version import project, release, revision
-
-print "%s - %s [%s]" % (project, release, revision)
-
-if os.name == 'nt':
-    print
-    print "Just close this window to shutdown MoinMoin DesktopEdition."
-print
-
-
-class DefaultConfig(StandaloneConfig):
-
-    # Server name
-    # Used to create .log, .pid and .prof files
-    name = 'moin'
-
-    # Path to moin shared files (default '/usr/share/moin/wiki/htdocs')
-    # If you installed with --prefix=PREFIX, use 'PREFIX/share/moin/wiki/htdocs'
-    #docs = '/usr/share/moin/htdocs'
-    # If your wiki/ directory is below the moin.py command, you don't need to
-    # change this:
-    docs = os.path.join(moinpath, 'wiki', 'htdocs')
-
-    # URL prefix for the static stuff (used to access stuff in docs) - you
-    # usually should not need to change this because moin standalone uses
-    # matching defaults for here and for wikiconfig.py:
-    #url_prefix_static = '/moin_static160'
-
-    # The server will run with as this user and group (default 'www-data')
-    #user = 'www-data'
-    #group = 'www-data'
-
-    # Port (default 8000)
-    # To serve privileged port under 1024 you will have to run as root
-    port = 8080
-
-    # Interface (default 'localhost')
-    # '' - will listen to any interface
-    interface = 'localhost'
-
-    # Log (default commented)
-    # Log is written to stderr or to a file you specify here.
-    ## logPath = name + '.log'
-
-    # Server class (default ThreadPoolServer)
-    # 'ThreadPoolServer' - create a constant pool of threads, simplified
-    # Apache worker mpm.
-    # 'ThreadingServer' - serve each request in a new thread. Much
-    # slower for static files.
-    # 'ForkingServer' - serve each request on a new child process -
-    # experimental, slow.
-    # 'SimpleServer' - server one request at a time. Fast, low
-    # memory footprint.
-    # If you set one of the threading servers and threads are not
-    # available, the server will fallback to ForkingServer. If fork is
-    # not available, the server will fallback to SimpleServer.
-    #serverClass = 'ThreadPoolServer'
-
-    # Thread limit (default 10)
-    # Limit the number of threads created. Ignored on non threaded servers.
-    #threadLimit = 10
-
-    # Request queue size (default 50)
-    # The size of the socket listen backlog.
-    #requestQueueSize = 50
-
-    # Properties
-    # Allow overriding any request property by the value defined in
-    # this dict e.g properties = {'script_name': '/mywiki'}.
-    #properties = {}
-
-    # Memory profile (default commented)
-    # Useful only if you are a developer or interested in moin memory usage
-    # A memory profile named 'moin--2004-09-27--01-24.log' is
-    # created each time you start the server.
-    ## from MoinMoin.util.profile import Profiler
-    ## memoryProfile = Profiler(name, requestsPerSample=100, collect=0)
-
-    # Hotshot profile (default commented)
-    # Not compatible with threads - use with SimpleServer only.
-    ## hotshotProfile = name + '.prof'
-
-    # cProfile profile (default commented)
-    # Use with SimpleServer only.
-    ## cProfileProfile = name + '.prof'
-
-    # Using pycallgraph to make nice graphics of how moin works internally
-    # hint: using zgrviewer to view .dot is much more effective than using
-    #       some .png viewer
-    ##pycallgraph_output = 'moin-pycallgraph.dot' # can be either .dot or .png
-    ##serverClass = 'SimpleServer' # pycallgraph doesn't support multithreading
-
-try:
-    from wikiserverconfig import Config
-except ImportError:
-    Config = DefaultConfig
+moinpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, moinpath)
+os.chdir(moinpath)
 
 if __name__ == '__main__':
-    # Run moin moin server:
-    run(Config)
-
+    sys.argv = ["moin.py", "server", "standalone"]
+    MoinScript().run()
--- a/setup.py	Tue Jan 29 17:18:06 2008 +0100
+++ b/setup.py	Wed Jan 30 09:36:59 2008 +0100
@@ -241,6 +241,7 @@
         'MoinMoin.script.old',
         'MoinMoin.script.old.migration',
         'MoinMoin.script.old.xmlrpc-tools',
+        'MoinMoin.script.server',
         'MoinMoin.script.xmlrpc',
         'MoinMoin.search',
         'MoinMoin.security',