Revision: 875 http://trac.macosforge.org/projects/calendarserver/changeset/875 Author: dreid@apple.com Date: 2006-12-20 15:45:33 -0800 (Wed, 20 Dec 2006) Log Message: ----------- various improvements, BindAddress support, and new service types Modified Paths: -------------- CalendarServer/branches/users/dreid/cluster/bin/caldavd CalendarServer/branches/users/dreid/cluster/conf/caldavd-test.plist CalendarServer/branches/users/dreid/cluster/conf/caldavd.plist CalendarServer/branches/users/dreid/cluster/run CalendarServer/branches/users/dreid/cluster/twistedcaldav/cluster.py CalendarServer/branches/users/dreid/cluster/twistedcaldav/config.py CalendarServer/branches/users/dreid/cluster/twistedcaldav/tap.py Modified: CalendarServer/branches/users/dreid/cluster/bin/caldavd =================================================================== --- CalendarServer/branches/users/dreid/cluster/bin/caldavd 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/bin/caldavd 2006-12-20 23:45:33 UTC (rev 875) @@ -24,6 +24,7 @@ configfile=""; twistdpath="$(type -p twistd)"; plugin_name="caldav"; +service_type=""; py_version () { @@ -75,7 +76,7 @@ if [ "${1--}" != "-" ]; then echo "${1}"; echo; fi; - echo "Usage: ${program} [-hX] [-u username] [-g groupname] [-T twistd] [-f caldavd.plist]"; + echo "Usage: ${program} [-hX] [-u username] [-g groupname] [-T twistd] [-t type] [-f caldavd.plist]"; echo "Options:"; echo " -h Print this help and exit"; echo " -X Do not daemonize"; @@ -83,12 +84,13 @@ echo " -g Group to run as"; echo " -f Configuration file to read"; echo " -T Path to twistd binary"; + echo " -t Service type (master, slave, standalone, cluster)"; if [ "${1-}" == "-" ]; then return 0; fi; exit 64; } -while getopts 'hXu:g:f:T:P:' option; do +while getopts 'hXu:g:f:T:P:t:' option; do case "${option}" in '?') usage; ;; 'h') usage -; exit 0; ;; @@ -98,6 +100,7 @@ 'u') username="-u ${OPTARG}"; ;; 'g') grouname="-g ${OPTARG}"; ;; 'P') plugin_name="${OPTARG}"; ;; + 't') service_type="-o ServerType=${OPTARG}"; ;; esac; done; @@ -105,4 +108,4 @@ if [ $# != 0 ]; then usage "Unrecognized arguments:" "$@"; fi; -exec "${python}" "${twistdpath}" "${daemonize}" ${username} ${groupname} "${plugin_name}" ${configfile}; +exec "${python}" "${twistdpath}" "${daemonize}" ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type}; Modified: CalendarServer/branches/users/dreid/cluster/conf/caldavd-test.plist =================================================================== --- CalendarServer/branches/users/dreid/cluster/conf/caldavd-test.plist 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/conf/caldavd-test.plist 2006-12-20 23:45:33 UTC (rev 875) @@ -29,6 +29,9 @@ <key>DocumentRoot</key> <string>twistedcaldav/test/data/</string> + <key>BindAddress</key> + <string>127.0.0.1</string> + <key>Port</key> <integer>8008</integer> @@ -165,14 +168,11 @@ <array> <string>/principals/user/admin</string> </array> - - <key>ClusterEnable</key> - <false/> <key>Cluster</key> <dict> <key>processes</key> - <integer>0</integer> + <integer>2</integer> <key>scheduler</key> <string>leastconns</string> @@ -185,10 +185,12 @@ <key>password</key> <string></string> </dict> + </dict> - <key>pydirLocation</key> - <string>../pydirector-1.0.0/pydir++.py</string> + <key>pydirLocation</key> + <string>../pydirector-1.0.0/pydir.py</string> - </dict> + <key>pydirConfig</key> + <string>conf/pydir.xml</string> </dict> </plist> Modified: CalendarServer/branches/users/dreid/cluster/conf/caldavd.plist =================================================================== --- CalendarServer/branches/users/dreid/cluster/conf/caldavd.plist 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/conf/caldavd.plist 2006-12-20 23:45:33 UTC (rev 875) @@ -29,6 +29,9 @@ <key>DocumentRoot</key> <string>/Library/CalendarServer/Documents</string> + <key>BindAddress</key> + <string></string> + <key>Port</key> <integer>8008</integer> @@ -112,8 +115,8 @@ <string>/principals/user/admin</string> </array> - <key>ClusterEnable</key> - <false/> + <key>ServerType</key> + <string>singleprocess</string> <key>Cluster</key> <dict> @@ -134,6 +137,7 @@ <key>pydirLocation</key> <string>/usr/share/caldavd/bin/pydir++.py</string> + </dict> </dict> </plist> Modified: CalendarServer/branches/users/dreid/cluster/run =================================================================== --- CalendarServer/branches/users/dreid/cluster/run 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/run 2006-12-20 23:45:33 UTC (rev 875) @@ -35,6 +35,7 @@ install=""; daemonize="-X"; plugin_name="caldav"; + service_type="standalone"; usage () { @@ -58,7 +59,7 @@ exit 64; } -while getopts 'hvsfnpdP:i:I:' option; do +while getopts 'hvsfnpdP:i:I:t:' option; do case "$option" in '?') usage; ;; 'h') usage -; exit 0; ;; @@ -71,6 +72,7 @@ 'P') plugin_name="${OPTARG}"; ;; 'i') setup_only="true"; install="${OPTARG}"; install_flag="--root="; ;; 'I') setup_only="true"; install="${wd}/build/dst"; install_flag="--root="; install_home="${OPTARG}"; ;; + 't') service_type="${OPTARG}"; ;; esac; done; shift $((${OPTIND} - 1)); @@ -186,7 +188,7 @@ -f "${config}" \ -T "${twisted}/bin/twistd" \ -P "${plugin_name}" \ - ; + -t "${service_type}"; cd /; fi; } Modified: CalendarServer/branches/users/dreid/cluster/twistedcaldav/cluster.py =================================================================== --- CalendarServer/branches/users/dreid/cluster/twistedcaldav/cluster.py 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/twistedcaldav/cluster.py 2006-12-20 23:45:33 UTC (rev 875) @@ -1,17 +1,14 @@ import os +import sys import tempfile -import socket from twisted.runner import procmon -from twisted.python import usage - from twistedcaldav.config import config -# from twistedcaldav.tap import CaldavOptions, CaldavServiceMaker serviceTemplate = """ <service name="%(name)s"> - <listen ip="127.0.0.1:%(port)s" /> + <listen ip="%(bindAddress)s:%(port)s" /> <group name="main" scheduler="%(scheduler)s"> %(hosts)s </group> @@ -25,7 +22,6 @@ <admin listen="localhost:7001"> <user name="%(username)s" password="%(password)s" access="full"/> </admin> - <logging file="pydir.log"/> </pdconfig> """ @@ -54,13 +50,16 @@ return '%s-%s' % (self.prefix, self.sslPort) def getCommandLine(self): - return [self.twistd, '-n', 'caldav', - '-f', self.configFile, - '-t', 'standalone', - '-o', 'Port=%s' % (self.port,), - '-o', 'SSLPort=%s' % (self.sslPort,), - '-o', 'PIDFile=%s' % (self.pidFile,)] - + return [ + sys.executable, + self.twistd, '-n', 'caldav', + '-f', self.configFile, + '-o', 'ServerType=standalone', + '-o', 'BindAddress=127.0.0.1', + '-o', 'Port=%s' % (self.port,), + '-o', 'SSLPort=%s' % (self.sslPort,), + '-o', 'PIDFile=%s' % (self.pidFile,)] + def getHostLine(self, ssl=None): name = self.getName() port = self.port @@ -71,13 +70,7 @@ return hostTemplate % {'name': name, 'port': port} -def makeService(self, options): - if not config.ClusterEnable: - raise usage.UsageError( - ("Clustering is not enabled in the config " - "file, use -o ClusterEnable=True to " - "override")) - +def makeService_multiprocess(self, options): service = procmon.ProcessMonitor() hosts = [] @@ -108,9 +101,9 @@ services = [] if not config.SSLOnly: - services.append(serviceTemplate % { 'name': 'http', + 'bindAddress': config.BindAddress, 'port': config.Port, 'scheduler': config.Cluster['scheduler'], 'hosts': '\n'.join(hosts) @@ -119,6 +112,7 @@ if config.SSLEnable: services.append(serviceTemplate % { 'name': 'https', + 'bindAddress': config.BindAddress, 'port': config.SSLPort, 'scheduler': config.Cluster['scheduler'], 'hosts': '\n'.join(sslHosts), @@ -134,7 +128,17 @@ os.write(fd, pdconfig) os.close(fd) - service.addProcess('pydir', [config.Cluster['pydirLocation'], + service.addProcess('pydir', [sys.executable, + config.pydirLocation, fname]) return service + +def makeService_pydir(self, options): + service = procmon.ProcessMonitor() + + service.addProcess('pydir', [sys.executable, + config.pydirLocation, + config.pydirConfig]) + + return service Modified: CalendarServer/branches/users/dreid/cluster/twistedcaldav/config.py =================================================================== --- CalendarServer/branches/users/dreid/cluster/twistedcaldav/config.py 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/twistedcaldav/config.py 2006-12-20 23:45:33 UTC (rev 875) @@ -23,6 +23,7 @@ defaultConfigFile = '/etc/caldavd/caldavd.plist' defaultConfig = { + 'BindAddress': '127.0.0.1', 'DirectoryService': { 'params': {'node': '/Search'}, 'type': 'twistedcaldav.directory.appleopendirectory.OpenDirectoryService' @@ -45,11 +46,16 @@ 'ServerStatsFile': '/Library/CalendarServer/Documents/stats.plist', 'UserQuotaBytes': 104857600, 'Verbose': False, - 'twistdLocation': '/usr/share/caldavd/bin/twistd', 'SACLEnable': False, 'AuthSchemes': ['Basic'], 'AdminPrincipals': ['/principals/user/admin'], - 'ClusterEnable': True, + + 'twistdLocation': '/usr/share/caldavd/bin/twistd', + 'pydirLocation': '/usr/share/caldavd/bin/pydir++.py', + 'pydirConfig': '/etc/caldavd/pydir.xml', + + 'ServerType': 'singleprocess', + 'Cluster': { 'processes': 10, 'scheduler': 'leastconns', @@ -57,7 +63,6 @@ 'username': None, 'password': None, }, - 'pydirLocation': '/usr/share/caldavd/bin/pydir++.py', }, } Modified: CalendarServer/branches/users/dreid/cluster/twistedcaldav/tap.py =================================================================== --- CalendarServer/branches/users/dreid/cluster/twistedcaldav/tap.py 2006-12-20 23:11:27 UTC (rev 874) +++ CalendarServer/branches/users/dreid/cluster/twistedcaldav/tap.py 2006-12-20 23:45:33 UTC (rev 875) @@ -23,7 +23,7 @@ from twisted.python import log -from twisted.python.usage import Options +from twisted.python.usage import Options, UsageError from twisted.python.reflect import namedClass from twisted.application import internet, service @@ -42,7 +42,7 @@ from twisted.web2.log import LogWrapperResource from twisted.web2.server import Site -from twistedcaldav.cluster import makeService as makeService_cluster +from twistedcaldav.cluster import makeService_multiprocess, makeService_pydir from twistedcaldav.config import config, parseConfig, defaultConfig from twistedcaldav.logging import RotatingFileAccessLoggingObserver from twistedcaldav.root import RootResource @@ -54,7 +54,6 @@ optParameters = [ ["config", "f", "/etc/caldavd/caldavd.plist", "Path to configuration file."], - ["type", "t", "standalone", "Select the type of service to run"], ] zsh_actions = {"config" : "_files -g '*.plist'"} @@ -86,7 +85,7 @@ value = value.split(',') elif isinstance(defaultConfig[key], dict): - raise usage.UsageError( + raise UsageError( "We do not support dict options on the command line") self.overrides[key] = value @@ -124,7 +123,7 @@ principalResourceClass = DirectoryPrincipalProvisioningResource calendarResourceClass = CalendarHomeProvisioningFile - def makeService_standalone(self, options): + def makeService_singleprocess(self, options): # # Setup the Directory # @@ -226,7 +225,8 @@ service = Web2Service(logObserver) if not config.SSLOnly: - httpService = internet.TCPServer(int(config.Port), channel) + httpService = internet.TCPServer(int(config.Port), channel, + interface=config.BindAddress) httpService.setServiceParent(service) if config.SSLEnable: @@ -235,24 +235,28 @@ int(config.SSLPort), channel, DefaultOpenSSLContextFactory(config.SSLPrivateKey, - config.SSLCertificate) + config.SSLCertificate), + interface=config.BindAddress ) httpsService.setServiceParent(service) return service - makeService_slave = makeService_standalone + makeService_slave = makeService_singleprocess - makeService_cluster = makeService_cluster + makeService_multiprocess = makeService_multiprocess + makeService_master = makeService_pydir + def makeService(self, options): - serviceType = options['type'] + serverType = config.ServerType - serviceMethod = getattr(self, 'makeService_%s' % (serviceType,)) + serviceMethod = getattr(self, 'makeService_%s' % (serverType,), None) - if not serviceMethod: - raise usage.UsageError( - ("Unknown service type %s, please choose: " % (serviceType,))) + if not serverMethod: + raise UsageError( + ("Unknown server type %s, please choose: singleprocess, " + "multiprocess, master, slave" % (serverType,))) else: return serviceMethod(options)
participants (1)
-
source_changes@macosforge.org