depot.py revision 2962
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] 3313N/A# Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. 3143N/A# pkg.depotd - package repository daemon 454N/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 448N/A# various GET operations that a pkg(1) client makes. This split is expected to 3234N/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 290N/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 383N/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 1516N/A# dumb clients (like a notification service). 290N/A# The default path for static and other web content. 2698N/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 2535N/A# by cherrypy is 2048 * 1024 * 1024 - 1 (just short of 2048MB), but the default 2561N/A# here is purposefully conservative. 2339N/A# The minimum number of threads allowed. 290N/A# The default number of threads to start. 2535N/A# The maximum number of threads that can be started. 290N/A# The default server socket timeout in seconds. We want this to be longer than 290N/A# the normal default of 10 seconds to accommodate clients with poor quality 3253N/A """3.2.0) is required to use this program.""" 3117N/A """This is a dummy object that we can use to discard log entries 3203N/A without relying on non-portable interfaces such as /dev/null.""" 290N/A """Optionally emit a usage message and then exit using the specified 2516N/A # The full usage message isn't desired. 2516N/A emsg(_(
"Try `pkg.depotd --help or -?' for more " 290N/A [-t socket_timeout] [--cfg] [--content-root] 3185N/A [--disable-ops op[/1][,...]] [--debug feature_list] 2523N/A [--image-root dir] [--log-access dest] [--log-errors dest] 3138N/A [--mirror] [--nasty] [--nasty-sleep] [--proxy-base url] 2390N/A [--readonly] [--ssl-cert-file] [--ssl-dialog] [--ssl-key-file] 1498N/A [--sort-file-max-size size] [--writable-root dir] 2867N/A -a address The IP address on which to listen for connections. The 2310N/A default value is 0.0.0.0 (INADDR_ANY) which will listen 3237N/A on all active interfaces. To listen on all active IPv6 2310N/A -d inst_root The file system path at which the server should find its 2852N/A repository data. Required unless PKG_REPO has been set 2852N/A -p port The port number on which the instance should listen for 2852N/A incoming package requests. The default value is 80 if 2852N/A ssl certificate and key information has not been 2535N/A provided; otherwise, the default value is 443. 2867N/A -s threads The number of threads that will be started to serve 2867N/A requests. The default value is 10. 2310N/A -t timeout The maximum number of seconds the server should wait for 290N/A a response from a client before closing a connection. 1674N/A --cfg The pathname of the file to use when reading and writing 2262N/A depot configuration data, or a fully qualified service 1674N/A fault management resource identifier (FMRI) of the SMF 395N/A service or instance to read configuration data from. 430N/A --content-root The file system path to the directory containing the 395N/A the static and other web content used by the depot's 1544N/A browser user interface. The default value is 1557N/A --disable-ops A comma separated list of operations that the depot 1903N/A should not configure. If, for example, you wanted 2046N/A to omit loading search v1, 'search/1' should be 2240N/A provided as an argument, or to disable all search 1506N/A operations, simply 'search'. 2928N/A --debug The name of a debug feature to enable; or a whitespace 395N/A or comma separated list of features to enable. 395N/A Possible values are: headers, hash=sha1+sha256, 395N/A --image-root The path to the image whose file information will be 395N/A used as a cache for file data. 395N/A --log-access The destination for any access related information 2310N/A logged by the depot process. Possible values are: 2852N/A stderr, stdout, none, or an absolute pathname. The 395N/A default value is stdout if stdout is a tty; otherwise 661N/A the default value is none. 2867N/A --log-errors The destination for any errors or other information 2867N/A logged by the depot process. Possible values are: 2867N/A stderr, stdout, none, or an absolute pathname. The 2867N/A --mirror Package mirror mode; publishing and metadata operations 2852N/A disallowed. Cannot be used with --readonly or 3216N/A --nasty Instruct the server to misbehave. At random intervals 3216N/A it will time-out, send bad responses, hang up on 2867N/A clients, and generally be hostile. The option 2867N/A takes a value (1 to 100) for how nasty the server 661N/A --nasty-sleep In nasty mode (see --nasty), how many seconds to 3185N/A randomly sleep when a random sleep occurs. 3185N/A --proxy-base The url to use as the base for generating internal 395N/A --readonly Read-only operation; modifying operations disallowed. 849N/A Cannot be used with --mirror or --rebuild. 290N/A --ssl-cert-file The absolute pathname to a PEM-encoded Certificate file. 395N/A This option must be used with --ssl-key-file. Usage of 395N/A this option will cause the depot to only respond to SSL 1968N/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, 395N/A or increase it for speed. 395N/A --writable-root The path to a directory to which the program has write 1231N/A access. Used with --readonly to allow server to 1557N/A create needed files, such as search indices, without 1903N/A needing write access to the package information. 395N/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. """ 3313N/A # Track initial configuration values. 3139N/A "content-root=",
"debug=",
"disable-ops=",
"exit-ready",
3139N/A "help",
"image-root=",
"log-access=",
"log-errors=",
395N/A "llmirror",
"mirror",
"nasty=",
"nasty-sleep=",
3139N/A "proxy-base=",
"readonly",
"rebuild",
"refresh-index",
3139N/A "set-property=",
"ssl-cert-file=",
"ssl-dialog=",
3139N/A "ssl-key-file=",
"sort-file-max-size=",
"writable-root="]
3139N/A # A list of features can be specified using a 3139N/A # "," or any whitespace character as separators. 3139N/A # We also allow key=value debug flags, which 3139N/A # get set in pkg.client.debugvalues 3139N/A "An argument must be specified." 2690N/A # ValueError is caught by caller. 742N/A "for nasty option.\n Please " \
742N/A "choose a value between 1 and 100." 742N/A # ValueError is caught by caller. 3136N/A # Attempt to decompose the url provided into 2688N/A # its base parts. This is done so we can 2688N/A # remove any scheme information since we 742N/A "determine the hostname from " \
2310N/A "the provided URL; please use a " \
2867N/A "and https are the only supported " \
2338N/A # Rebuild the url with the sanitized components. 2523N/A # Note: This argument is for internal use 2310N/A # This flag is purposefully omitted in usage. 2677N/A # The supported way to forcefully reindex is to 2310N/A # kill any pkg.depot using that directory, 2310N/A # remove the index directory, and restart the 2310N/A # pkg.depot process. The index will be rebuilt 3237N/A # automatically on startup. 2852N/A "the form '<section.property>=" 3237N/A # Assume this is an override to clear 2852N/A "the Certificate file must be " \
2508N/A # Assume this is an override to clear 2535N/A "the Private Key file must be " \
395N/A "specified. Expected: builtin, " \
591N/A # Don't allow a somewhat 591N/A # insecure authentication method 2639N/A "not a supported dialog " \
2639N/A "type for this operating " \
1505N/A "file path specified for " \
2339N/A # Build configuration object. 2828N/A usage(
"pkg.depotd: illegal option value: %s specified " \
2828N/A # If stdout is a tty, then send access output there by default instead 2828N/A # Check for invalid option combinations. 2892N/A usage(
"--add-content cannot be used with --rebuild")
2828N/A usage(
"--refresh-index cannot be used with --rebuild")
2828N/A usage(
"--readonly and --mirror cannot be used with --rebuild " 2828N/A usage(
"--mirror cannot be used with --refresh-index")
3158N/A usage(
"--readonly can only be used with --refresh-index if " 2828N/A usage(
"--image-root can only be used with --llmirror.")
2339N/A usage(
"--image_root and --writable-root cannot be used " 2339N/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. 2339N/A # Only use the first value for now; multiple bind addresses may be 3253N/A usage(
"The --ssl-cert-file and --ssl-key-file options must " 3253N/A "must both be provided when using either option.")
395N/A # If the program is going to reindex, the port is irrelevant since 395N/A # the program will not bind to a port. 290N/A emsg(
"pkg.depotd: unable to bind to the specified " 290N/A # Not applicable if we're not going to serve content 290N/A # Any relative paths should be made absolute using pkg_root. 'pkg_root' 290N/A # is a special property that was added to enable internal deployment of 290N/A # multiple disparate versions of the pkg.depotd software. 3026N/A "executing [%s]; unable to obtain the " 3158N/A "passphrase needed to decrypt the SSL " 290N/A # Assume the configuration target was an SMF 290N/A # FMRI and let svcprop fail with an error if 691N/A # The key file requires decryption, but the user has requested 691N/A # exec-based authentication, so it will have to be decoded first 2339N/A # to an un-named temporary file. 2339N/A emsg(
"pkg.depotd: unable to read the SSL private key " 2339N/A emsg(
"pkg.depotd: authentication or cryptography " 2339N/A "failure while attempting to decode\nthe SSL " 2339N/A # Redirect the server to the decrypted key file. 2339N/A # Setup our global configuration. 290N/A "environment":
"production",
395N/A "server.shutdown_timeout":
0,
506N/A # Despite its name, this only logs headers when there is an 513N/A # error; it's redundant with the debug feature enabled. 506N/A # Causes the headers of every request to be logged to the error 506N/A # log; even if an exception occurs. 395N/A "param":
"log.error_file",
1674N/A "param":
"log.access_file",
395N/A # Since we've replaced cherrypy's log handler with our 506N/A # own, we don't want the output directed to a file. 834N/A # Now that our logging, etc. has been setup, it's safe to perform any 290N/A # remaining preparation. 2561N/A # Initialize repository state. 2561N/A # Not readonly, so assume a new repository should be created. 2561N/A # Already exists, nothing to do. 2535N/A # Automatically update search indexes on startup if not already 2535N/A # Only execute a index refresh here if --exit-ready was 3234N/A # requested; it will be handled later in the setup 849N/A # Ready to start depot; exit now if requested. 2688N/A # Now build our site configuration. 2535N/A # We have to override cherrypy's default response_class so that 2597N/A # we have access to the write() callable to stream data 3234N/A # This changes the base URL for our server, and is primarily 2535N/A # intended to allow our depot process to operate behind Apache 2535N/A # or some other webserver process. 2535N/A # Visit the following URL for more information: 2535N/A # Now merge or add our proxy configuration information into the 2597N/A # Tell depot to update search indexes when possible; 2597N/A # this is done as a background task so that packages 2597N/A # can be served immediately while search indexes are 3246N/A # If stdin is not a tty and the pkgdepot controller isn't being used, 3246N/A # then assume process should be daemonized. 3246N/A emsg(
"pkg.depotd: unknown error starting depot server, " \
2597N/A "illegal option value specified?")