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