depot.py revision 2728
290N/A# The contents of this file are subject to the terms of the 290N/A# Common Development and Distribution License (the "License"). 290N/A# You may not use this file except in compliance with the License. 290N/A# See the License for the specific language governing permissions 290N/A# and limitations under the License. 290N/A# When distributing Covered Code, include this CDDL HEADER in each 290N/A# If applicable, add the following below this CDDL HEADER, with the 290N/A# fields enclosed by brackets "[]" replaced with your own identifying 290N/A# information: Portions Copyright [yyyy] [name of copyright owner] 2339N/A# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 883N/A# pkg.depotd - package repository daemon 290N/A# XXX The prototype pkg.depotd combines both the version management server that 448N/A# answers to pkgsend(1) sessions and the HTTP file server that answers to the 290N/A# various GET operations that a pkg(1) client makes. This split is expected to 290N/A# be made more explicit, by constraining the pkg(1) operations such that they 290N/A# can be served as a typical HTTP/HTTPS session. Thus, pkg.depotd will reduce 383N/A# to a special purpose HTTP/HTTPS server explicitly for the version management 290N/A# operations, and must manipulate the various state files--catalogs, in 395N/A# particular--such that the pkg(1) pull client can operately accurately with 849N/A# XXX Although we pushed the evaluation of next-version, etc. to the pull 1516N/A# client, we should probably provide a query API to do same on the server, for 2508N/A# dumb clients (like a notification service). 2535N/A# The default path for static and other web content. 290N/A# cherrypy has a max_request_body_size parameter that determines whether the 290N/A# server should abort requests with REQUEST_ENTITY_TOO_LARGE when the request 2535N/A# body is larger than the specified size (in bytes). The maximum size supported 290N/A# by cherrypy is 2048 * 1024 * 1024 - 1 (just short of 2048MB), but the default 2508N/A# here is purposefully conservative. 290N/A# The minimum number of threads allowed. 2535N/A# The default number of threads to start. 290N/A# The maximum number of threads that can be started. 2508N/A# The default server socket timeout in seconds. We want this to be longer than 2508N/A# the normal default of 10 seconds to accommodate clients with poor quality 534N/A print >>
sys.
stderr,
"""cherrypy 3.1.0 or greater (but less than """ \
534N/A """3.2.0) is required to use this program.""" 661N/A """This is a dummy object that we can use to discard log entries 290N/A without relying on non-portable interfaces such as /dev/null.""" 2523N/A """Optionally emit a usage message and then exit using the specified 2535N/A # The full usage message isn't desired. 2535N/A emsg(_(
"Try `pkg.depotd --help or -?' for more " 2535N/A [-t socket_timeout] [--cfg] [--content-root] 2535N/A [--disable-ops op[/1][,...]] [--debug feature_list] 2535N/A [--image-root dir] [--log-access dest] [--log-errors dest] 2310N/A [--mirror] [--nasty] [--proxy-base url] [--readonly] 290N/A [--ssl-cert-file] [--ssl-dialog] [--ssl-key-file] 1674N/A [--sort-file-max-size size] [--writable-root dir] 2262N/A -a address The IP address on which to listen for connections. The 1674N/A default value is 0.0.0.0 (INADDR_ANY) which will listen 395N/A on all active interfaces. To listen on all active IPv6 395N/A -d inst_root The file system path at which the server should find its 1544N/A repository data. Required unless PKG_REPO has been set 1557N/A -p port The port number on which the instance should listen for 1903N/A incoming package requests. The default value is 80 if 2046N/A ssl certificate and key information has not been 2240N/A provided; otherwise, the default value is 443. 1506N/A -s threads The number of threads that will be started to serve 395N/A requests. The default value is 10. 395N/A -t timeout The maximum number of seconds the server should wait for 2026N/A a response from a client before closing a connection. 424N/A The default value is 60. 1024N/A --cfg The pathname of the file to use when reading and writing 395N/A depot configuration data, or a fully qualified service 395N/A fault management resource identifier (FMRI) of the SMF 395N/A service or instance to read configuration data from. 2078N/A --content-root The file system path to the directory containing the 578N/A the static and other web content used by the depot's 1172N/A browser user interface. The default value is 395N/A --disable-ops A comma separated list of operations that the depot 2535N/A should not configure. If, for example, you wanted 2535N/A to omit loading search v1, 'search/1' should be 2535N/A provided as an argument, or to disable all search 661N/A operations, simply 'search'. 1099N/A --debug The name of a debug feature to enable; or a whitespace 1902N/A or comma separated list of features to enable. 2310N/A Possible values are: headers. 2535N/A --image-root The path to the image whose file information will be 661N/A used as a cache for file data. 395N/A --log-access The destination for any access related information 849N/A logged by the depot process. Possible values are: 290N/A stderr, stdout, none, or an absolute pathname. The 395N/A default value is stdout if stdout is a tty; otherwise 395N/A the default value is none. 1968N/A --log-errors The destination for any errors or other information 395N/A logged by the depot process. Possible values are: 395N/A stderr, stdout, none, or an absolute pathname. The 395N/A default value is stderr. 395N/A --mirror Package mirror mode; publishing and metadata operations 395N/A disallowed. Cannot be used with --readonly or 395N/A --nasty Instruct the server to misbehave. At random intervals 395N/A it will time-out, send bad responses, hang up on 395N/A clients, and generally be hostile. The option 395N/A takes a value (1 to 100) for how nasty the server 290N/A --proxy-base The url to use as the base for generating internal 395N/A --readonly Read-only operation; modifying operations disallowed. 395N/A Cannot be used with --mirror or --rebuild. 1231N/A --ssl-cert-file The absolute pathname to a PEM-encoded Certificate file. 1557N/A This option must be used with --ssl-key-file. Usage of 1903N/A this option will cause the depot to only respond to SSL 1557N/A requests on the provided port. 395N/A --ssl-dialog Specifies what method should be used to obtain the 395N/A passphrase needed to decrypt the file specified by 395N/A --ssl-key-file. Supported values are: builtin, 395N/A default value is builtin. If smf is specified, an 395N/A SMF FMRI must be provided using the --cfg option. 395N/A --ssl-key-file The absolute pathname to a PEM-encoded Private Key file. 395N/A This option must be used with --ssl-cert-file. Usage of 395N/A this option will cause the depot to only respond to SSL 395N/A requests on the provided port. 290N/A The maximum size of the indexer sort file. Used to 290N/A limit the amount of RAM the depot uses for indexing, 430N/A or increase it for speed. 395N/A --writable-root The path to a directory to which the program has write 395N/A access. Used with --readonly to allow server to 395N/A create needed files, such as search indices, without 395N/A needing write access to the package information. 395N/A PKG_REPO Used as default inst_root if -d not provided. 1024N/A PKG_DEPOT_CONTENT Used as default content_root if --content-root 2516N/A # Track initial configuration values. 2516N/A "content-root=",
"debug=",
"disable-ops=",
"exit-ready",
2516N/A "help",
"image-root=",
"log-access=",
"log-errors=",
2516N/A "llmirror",
"mirror",
"nasty=",
"proxy-base=",
"readonly",
2516N/A "rebuild",
"refresh-index",
"set-property=",
2516N/A "ssl-cert-file=",
"ssl-dialog=",
"ssl-key-file=",
2516N/A "sort-file-max-size=",
"writable-root="]
742N/A # A list of features can be specified using a 742N/A # "," or any whitespace character as separators. 1902N/A "An argument must be specified." 2535N/A "for nasty option.\n Please " \
2535N/A "choose a value between 1 and 100." 2535N/A # Attempt to decompose the url provided into 2535N/A # its base parts. This is done so we can 2535N/A # remove any scheme information since we 2535N/A "determine the hostname from " \
2535N/A "the provided URL; please use a " \
2535N/A "and https are the only supported " \
2535N/A # Rebuild the url with the sanitized components. 2535N/A # Note: This argument is for internal use 2535N/A # This flag is purposefully omitted in usage. 2535N/A # The supported way to forcefully reindex is to 2535N/A # kill any pkg.depot using that directory, 2535N/A # remove the index directory, and restart the 2535N/A # pkg.depot process. The index will be rebuilt 2535N/A # automatically on startup. 691N/A "the form '<section.property>=" 395N/A # Assume this is an override to clear 591N/A "the Certificate file must be " \
2339N/A # Assume this is an override to clear 2339N/A "the Private Key file must be " \
2339N/A "specified. Expected: builtin, " \
2339N/A # insecure authentication method 2339N/A "not a supported dialog " \
2339N/A "type for this operating " \
2364N/A "file path specified for " \
2339N/A # Build configuration object. 290N/A usage(
"pkg.depotd: illegal option value: %s specified " \
290N/A # If stdout is a tty, then send access output there by default instead 395N/A # Check for invalid option combinations. 691N/A usage(
"--add-content cannot be used with --rebuild")
2339N/A usage(
"--refresh-index cannot be used with --rebuild")
2339N/A usage(
"--readonly and --mirror cannot be used with --rebuild " 290N/A usage(
"--mirror cannot be used with --refresh-index")
290N/A usage(
"--readonly can only be used with --refresh-index if " 591N/A "--writable-root is used")
691N/A usage(
"--image-root can only be used with --llmirror.")
2339N/A usage(
"--image_root and --writable-root cannot be used " 290N/A usage(
"--image-root and -d cannot be used together.")
2339N/A # If the image format changes this may need to be reexamined. 2339N/A # Set any values using defaults if they weren't provided. 290N/A # Only use the first value for now; multiple bind addresses may be 506N/A usage(
"The --ssl-cert-file and --ssl-key-file options must " 506N/A "must both be provided when using either option.")
1674N/A # If the program is going to reindex, the port is irrelevant since 1674N/A # the program will not bind to a port. 1674N/A emsg(
"pkg.depotd: unable to bind to the specified " 1674N/A # Not applicable if we're not going to serve content 1674N/A # Any relative paths should be made absolute using pkg_root. 'pkg_root' 1674N/A # is a special property that was added to enable internal deployment of 395N/A # multiple disparate versions of the pkg.depotd software. 2535N/A "executing [%s]; unable to obtain the " 2535N/A "passphrase needed to decrypt the SSL " 2535N/A # Assume the configuration target was an SMF 2535N/A # FMRI and let svcprop fail with an error if 1660N/A # The key file requires decryption, but the user has requested 1660N/A # exec-based authentication, so it will have to be decoded first 1660N/A # to an un-named temporary file. 2535N/A emsg(
"pkg.depotd: unable to read the SSL private key " 2535N/A emsg(
"pkg.depotd: authentication or cryptography " 2535N/A "failure while attempting to decode\nthe SSL " 2535N/A # Redirect the server to the decrypted key file. 2535N/A # Setup our global configuration. 2535N/A "environment":
"production",
2535N/A "server.shutdown_timeout":
0,
2535N/A # Despite its name, this only logs headers when there is an 2535N/A # error; it's redundant with the debug feature enabled. 2535N/A # Causes the headers of every request to be logged to the error 2535N/A # log; even if an exception occurs. 2535N/A "param":
"log.access_file",
2535N/A # Since we've replaced cherrypy's log handler with our 2535N/A # own, we don't want the output directed to a file. 2535N/A # Now that our logging, etc. has been setup, it's safe to perform any 2535N/A # Initialize repository state. 2535N/A # Not readonly, so assume a new repository should be created. 2535N/A # Already exists, nothing to do. 2242N/A # Automatically update search indexes on startup if not already 2337N/A # Only execute a index refresh here if --exit-ready was 2337N/A # requested; it will be handled later in the setup 2508N/A # Ready to start depot; exit now if requested. 2508N/A # Now build our site configuration. 2508N/A # We have to override cherrypy's default response_class so that 2508N/A # we have access to the write() callable to stream data 2508N/A # This changes the base URL for our server, and is primarily 2508N/A # intended to allow our depot process to operate behind Apache 2508N/A # or some other webserver process. 2508N/A # Visit the following URL for more information: 2508N/A # Now merge or add our proxy configuration information into the 2508N/A # Tell depot to update search indexes when possible; 2508N/A # this is done as a background task so that packages 2508N/A # can be served immediately while search indexes are 849N/A # If stdin is not a tty and the pkgdepot controller isn't being used, 383N/A # then assume process should be daemonized. 422N/A emsg(
"pkg.depotd: unknown error starting depot server, " \
422N/A "illegal option value specified?")