vinegar.cli.server
Vinegar server daemon.
If executed as a Python script, this module starts a Vinegar server, looking
for a configuration file in /etc/vinegar/vinegar-server.yaml.
The path to the configuration file can be overridden through the
--config-file command line argument.
Instead of executing this module as a script, it can be imported and its
run_server function can be used to start the server. In this case, the
configuration is expected to be passed to run_server in the form of a
dictionary.
The configuration file uses the YAML syntax and has the following keys (all of them are optional):
data_sources:List of data sources. Each item in the list must be a dictionary. This dictionary must have a key
namethat specifies the type of the data source. Please refer to the documentation ofvinegar.data_source.get_data_sourceto learn more about how the name is resolved. All other keys are used for the configuration dictionary that is passed to the data source. It is perfectly legal to use multiple data sources with the same name, but having a different configuration. Please refer to the documentation of the data sources to learn more about the configuration options for each data sources. The resulting list of data sources is passed toget_composite_datasourcein order to create a single data source that combines them all. The behavior of the compositve data source is also controlled by thedata_sources_merge_listsoption.data_sources_merge_lists:Flag controlling the behavior of the composite data source that is created for the list of
data_sources. The composite data source merges the data returned by each data source with the data from the previous data sources. This happens by merging mappings, preserving keys that are present in the previous data, but not in the data from the next data source. This process also applies to nested mappings. Ifdata_sources_merge_listsis set toTrue, sequences are also merged, meaning that elements that are not present in the list in the previous data are added to the list. IfFalse(the default), sequences replace each other, removing all elements that were only present in the previous data.data_sources_merge_sets:Flag controlling the behavior of the composite data source that is created for the list of
data_sources. The composite data source merges the data returned by each data source with the data from the previous data sources. This happens by merging mappings, preserving keys that are present in the previous data, but not in the data from the next data source. This process also applies to nested mappings. Ifdata_sources_merge_setsis set toTrue(the default), sets are also merged, meaning that the resulting set is the union of the set in the previous data and the set returned by the data source. IfFalse, sets replace each other, removing all elements that were only present in the previous data.http:Dictionary of configuration options for the HTTP server. The options are passed on to
vinegar.server.http.create_http_server. The only exception is therequest_handlersoption. That option expects a list, where each item is a dictionary. This dictionary must have a keynamethat specifies the type of the request handler. Please refer to the documentation ofvinegar.request_handler.get_http_request_handlerto learn more about how the name is resolved. All other keys are used for the configuration dictionary that is passed to the request handler. It is perfectly legal to use multiple request handlers with the same name, but having a different configuration. Please refer to the documentation of the request handlers to learn more about the configuration options for each request handler.logging_config_file:Path to a logging configuration file. This file must be in the format expected by
logging.config.fileConfig. This configuration option cannot be used together with thelogging_leveloption.logging_level:Logging level to be used. Can be one of
CRITICAL,ERROR,WARN,INFO(the default), orDEBUG. This configuration option cannot be used together with thelogging_config_fileoption.tftp:Dictionary of configuration options for the TFTP server. The options are passed on to
vinegar.server.tftp.create_tftp_server. The only exception is therequest_handlersoption. That option expects a list, where each item is a dictionary. This dictionary must have a keynamethat specifies the type of the request handler. Please refer to the documentation ofvinegar.request_handler.get_tftp_request_handlerto learn more about how the name is resolved. All other keys are used for the configuration dictionary that is passed to the request handler. It is perfectly legal to use multiple request handlers with the same name, but having a different configuration. Please refer to the documentation of the request handlers to learn more about the configuration options for each request handler.
- vinegar.cli.server.main()
Run Vinegar server.
This function parses the command-line arguments, calls
reader_server_config, and subsequently callsrun_server.
- vinegar.cli.server.read_server_config(config_file: str | None = None) Mapping[str, Any]
Read the server configuration.
If the configurtion file cannot be read (because it does not exist, permissions are insufficient, or it is not a valid YAML file), an exception is raised.
The returned object can then be passed to
run_server.- Parameters:
config_file – path to the configuration file. If
Nonea platform specifc default value is used.- Returns:
configuration read from the file.
- vinegar.cli.server.run_server(config: Mapping[str, Any]) None
Run the Vinegar server.
This function only returns when it is interrupted from the keyboard or when the process receives a
SIGTERM.This function raises an exception if the configuration object is invalid or if the server cannot be started.
- Parameters:
config – configuration object used by the server. Please refer to the
module documentationfor a description of the structure of the configuration object.