depot.py revision 3171
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] 2223N/A# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. 290N/A# pkg.depotd - package repository daemon 290N/A# XXX The prototype pkg.depotd combines both the version management server that 290N/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 383N/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 395N/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 290N/A# XXX Although we pushed the evaluation of next-version, etc. to the pull 849N/A# client, we should probably provide a query API to do same on the server, for 290N/A# dumb clients (like a notification service). 290N/A# The default path for static and other web content. 383N/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 290N/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 290N/A# here is purposefully conservative. 1660N/A# The minimum number of threads allowed. 1660N/A# The default number of threads to start. 1660N/A# The maximum number of threads that can be started. 1660N/A# The default server socket timeout in seconds. We want this to be longer than 1660N/A# the normal default of 10 seconds to accommodate clients with poor quality 465N/A print(
"""cherrypy 3.1.0 or greater (but less than """ 1391N/A """This is a dummy object that we can use to discard log entries 1391N/A without relying on non-portable interfaces such as /dev/null.""" 742N/A """Discard the bits.""" 941N/A """Optionally emit a usage message and then exit using the specified 2023N/A # The full usage message isn't desired. 2023N/A emsg(_(
"Try `pkg.depotd --help or -?' for more " 1513N/A [-t socket_timeout] [--cfg] [--content-root] 1191N/A [--disable-ops op[/1][,...]] [--debug feature_list] 2180N/A [--image-root dir] [--log-access dest] [--log-errors dest] 1191N/A [--mirror] [--nasty] [--nasty-sleep] [--proxy-base url] 1191N/A [--readonly] [--ssl-cert-file] [--ssl-dialog] [--ssl-key-file] 1191N/A [--sort-file-max-size size] [--writable-root dir] 1660N/A -a address The IP address on which to listen for connections. The 1660N/A default value is 0.0.0.0 (INADDR_ANY) which will listen 1660N/A on all active interfaces. To listen on all active IPv6 2026N/A -d inst_root The file system path at which the server should find its 2026N/A repository data. Required unless PKG_REPO has been set 2026N/A -p port The port number on which the instance should listen for 2026N/A incoming package requests. The default value is 80 if 2026N/A ssl certificate and key information has not been 2026N/A provided; otherwise, the default value is 443. 2026N/A -s threads The number of threads that will be started to serve 448N/A requests. The default value is 10. 448N/A -t timeout The maximum number of seconds the server should wait for 534N/A a response from a client before closing a connection. 534N/A The default value is 60. 534N/A --cfg The pathname of the file to use when reading and writing 534N/A depot configuration data, or a fully qualified service 534N/A fault management resource identifier (FMRI) of the SMF 534N/A service or instance to read configuration data from. 534N/A --content-root The file system path to the directory containing the 290N/A the static and other web content used by the depot's 290N/A browser user interface. The default value is 954N/A --disable-ops A comma separated list of operations that the depot 954N/A should not configure. If, for example, you wanted 954N/A to omit loading search v1, 'search/1' should be 534N/A provided as an argument, or to disable all search 1099N/A operations, simply 'search'. 290N/A --debug The name of a debug feature to enable; or a whitespace 1516N/A or comma separated list of features to enable. 290N/A Possible values are: headers, hash=sha1+sha256, 290N/A hash=sha256, hash=sha1+sha512_256, hash=sha512_256 290N/A --image-root The path to the image whose file information will be 661N/A used as a cache for file data. 290N/A --log-access The destination for any access related information 290N/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 290N/A the default value is none. 2125N/A --log-errors The destination for any errors or other information 290N/A logged by the depot process. Possible values are: 1483N/A stderr, stdout, none, or an absolute pathname. The 290N/A default value is stderr. 1498N/A --mirror Package mirror mode; publishing and metadata operations 1498N/A disallowed. Cannot be used with --readonly or 1674N/A --nasty Instruct the server to misbehave. At random intervals 1674N/A it will time-out, send bad responses, hang up on 1674N/A clients, and generally be hostile. The option 1674N/A takes a value (1 to 100) for how nasty the server 1674N/A --nasty-sleep In nasty mode (see --nasty), how many seconds to 1674N/A randomly sleep when a random sleep occurs. 395N/A --proxy-base The url to use as the base for generating internal 395N/A --readonly Read-only operation; modifying operations disallowed. 1544N/A Cannot be used with --mirror or --rebuild. 1968N/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 2046N/A requests on the provided port. 1506N/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, 424N/A default value is builtin. If smf is specified, an 1024N/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 2078N/A requests on the provided port. 1172N/A The maximum size of the indexer sort file. Used to 395N/A limit the amount of RAM the depot uses for indexing, 661N/A or increase it for speed. 1099N/A --writable-root The path to a directory to which the program has write 1902N/A access. Used with --readonly to allow server to 661N/A create needed files, such as search indices, without 395N/A needing write access to the package information. 1968N/A PKG_REPO Used as default inst_root if -d not provided. 395N/A PKG_DEPOT_CONTENT Used as default content_root if --content-root 395N/A """Option exception. """ 395N/A # Track initial configuration values. 2046N/A "content-root=",
"debug=",
"disable-ops=",
"exit-ready",
1506N/A "help",
"image-root=",
"log-access=",
"log-errors=",
413N/A "llmirror",
"mirror",
"nasty=",
"nasty-sleep=",
2026N/A "proxy-base=",
"readonly",
"rebuild",
"refresh-index",
413N/A "set-property=",
"ssl-cert-file=",
"ssl-dialog=",
1978N/A "ssl-key-file=",
"sort-file-max-size=",
"writable-root="]
954N/A # A list of features can be specified using a 954N/A # "," or any whitespace character as separators. 1483N/A # We also allow key=value debug flags, which 1483N/A # get set in pkg.client.debugvalues 1498N/A "An argument must be specified." 290N/A # ValueError is caught by caller. 290N/A "for nasty option.\n Please " \
290N/A "choose a value between 1 and 100." 290N/A # ValueError is caught by caller. 290N/A # Attempt to decompose the url provided into 395N/A # its base parts. This is done so we can 395N/A # remove any scheme information since we 591N/A "determine the hostname from " \
591N/A "the provided URL; please use a " \
290N/A "and https are the only supported " \
290N/A # Rebuild the url with the sanitized components. 290N/A # Note: This argument is for internal use 395N/A # This flag is purposefully omitted in usage. 395N/A # The supported way to forcefully reindex is to 290N/A # kill any pkg.depot using that directory, 290N/A # remove the index directory, and restart the 290N/A # pkg.depot process. The index will be rebuilt 395N/A # automatically on startup. 290N/A "the form '<section.property>=" 290N/A # Assume this is an override to clear 506N/A "the Certificate file must be " \
506N/A "pathname is not a file." 506N/A # Assume this is an override to clear 395N/A "the Private Key file must be " \
413N/A "pathname is not a file." 1674N/A "specified. Expected: builtin, " \
1674N/A # insecure authentication method 1674N/A "not a supported dialog " \
395N/A "type for this operating " \
395N/A "file path specified for " \
849N/A # Build configuration object. 849N/A usage(
"pkg.depotd: illegal option value: {0} specified " \
1513N/A # If stdout is a tty, then send access output there by default instead 290N/A # Check for invalid option combinations. 883N/A usage(
"--add-content cannot be used with --rebuild")
883N/A usage(
"--refresh-index cannot be used with --rebuild")
883N/A usage(
"--readonly and --mirror cannot be used with --rebuild " 883N/A usage(
"--mirror cannot be used with --refresh-index")
1099N/A usage(
"--readonly can only be used with --refresh-index if " 1099N/A usage(
"--image-root can only be used with --llmirror.")
1516N/A usage(
"--image_root and --writable-root cannot be used " 1099N/A usage(
"--image-root and -d cannot be used together.")
1099N/A # If the image format changes this may need to be reexamined. 1099N/A # Set any values using defaults if they weren't provided. 1099N/A # Only use the first value for now; multiple bind addresses may be 465N/A usage(
"The --ssl-cert-file and --ssl-key-file options must " 395N/A "must both be provided when using either option.")
1191N/A # If the program is going to reindex, the port is irrelevant since 1191N/A # the program will not bind to a port. 1208N/A emsg(
"pkg.depotd: unable to bind to the specified " 1208N/A # Not applicable if we're not going to serve content 1191N/A # Any relative paths should be made absolute using pkg_root. 'pkg_root' 1391N/A # is a special property that was added to enable internal deployment of 1391N/A # multiple disparate versions of the pkg.depotd software. 465N/A emsg(
"pkg.depotd: an error occurred while " 1099N/A "executing [{0}]; unable to obtain the " 465N/A "passphrase needed to decrypt the SSL " 383N/A # Assume the configuration target was an SMF 395N/A # FMRI and let svcprop fail with an error if 849N/A # The key file requires decryption, but the user has requested 849N/A # exec-based authentication, so it will have to be decoded first 849N/A # to an un-named temporary file. 383N/A emsg(
"pkg.depotd: unable to read the SSL private key " 422N/A emsg(
"pkg.depotd: authentication or cryptography " 422N/A "failure while attempting to decode\nthe SSL " 422N/A # Redirect the server to the decrypted key file. 422N/A # Setup our global configuration. 422N/A "environment":
"production",
383N/A "server.shutdown_timeout":
0,
849N/A # Despite its name, this only logs headers when there is an 383N/A # error; it's redundant with the debug feature enabled. 430N/A # Causes the headers of every request to be logged to the error 395N/A # log; even if an exception occurs. 290N/A # If stdin is not a tty and the pkgdepot controller isn't being used, 290N/A # then assume process will be daemonized and redirect output. 395N/A # Ensure log handlers are setup to use the file descriptors for 290N/A # stdout and stderr as the Daemonizer (used for test suite and 395N/A # SMF service) requires this. 1513N/A "param":
"log.access_file",
1101N/A # Since we've replaced cherrypy's log handler with our 290N/A # own, we don't want the output directed to a file. 448N/A # Now that our logging, etc. has been setup, it's safe to perform any 430N/A # remaining preparation. 290N/A # Initialize repository state. 290N/A # Not readonly, so assume a new repository should be created. 2180N/A # Already exists, nothing to do. 2180N/A # Automatically update search indexes on startup if not already 290N/A # Only execute a index refresh here if --exit-ready was 613N/A # requested; it will be handled later in the setup 613N/A # process for other cases. 395N/A # Ready to start depot; exit now if requested. 395N/A # Now build our site configuration. 395N/A # We have to override cherrypy's default response_class so that 1498N/A # we have access to the write() callable to stream data 395N/A # This changes the base URL for our server, and is primarily 395N/A # intended to allow our depot process to operate behind Apache 395N/A # or some other webserver process. 395N/A # Visit the following URL for more information: 395N/A "tools.proxy.local":
"",
430N/A # Now merge or add our proxy configuration information into the 395N/A # existing configuration. 691N/A # Tell depot to update search indexes when possible; 691N/A # this is done as a background task so that packages 691N/A # can be served immediately while search indexes are 395N/A # If stdin is not a tty and the pkgdepot controller isn't being used, 395N/A # then assume process should be daemonized. 395N/A # Translate the values in log_cfg into paths. 395N/A emsg(
"pkg.depotd: unknown error starting depot server, " \
"illegal option value specified?")