Bedrock Server Manager Core Documentation
- class bedrock_server_manager.BedrockServerManager(settings: Settings)
Bases:
PlayerMixin
,WebProcessMixin
,WebServiceMixin
,ContentMixin
,SystemMixin
,DiscoveryMixin
Manages global application settings, server discovery, and application-wide data.
The
BedrockServerManager
serves as the primary high-level interface for operations that affect the Bedrock Server Manager application globally or span multiple server instances. It is distinct from theBedrockServer
class, which handles the specifics of individual server instances.Key Responsibilities:
Providing access to and management of global application settings through an aggregated
Settings
object.Discovering server instances within the configured base directory and validating their installations.
Managing a central player database (
players.json
), including parsing player data and consolidating information from server logs.Controlling the Web UI application’s lifecycle, including managing its system service (Systemd for Linux, Windows Service for Windows).
Listing globally available content files (e.g.,
.mcworld
templates,.mcaddon
/.mcpack
addons) from the content directory.Checking and reporting on system capabilities (e.g., availability of task schedulers or service managers).
An instance of this class is typically created once per application run. It initializes by loading or accepting a
Settings
instance and sets up paths based on this configuration. For operations that require interaction with a specific server (like scanning its logs), it will internally instantiate aBedrockServer
object.- capabilities
A dictionary indicating the availability of system features like ‘scheduler’ and ‘service_manager’.
- Type:
Dict[str, bool]
- _config_dir
Absolute path to the application’s configuration directory.
- Type:
str
- _app_data_dir
Absolute path to the application’s data directory.
- Type:
str
- _base_dir
Absolute path to the base directory where server installations are stored. Based on
settings['paths.servers']
.- Type:
Optional[str]
- _content_dir
Absolute path to the directory for global content like world templates and addons. Based on
settings['paths.content']
.- Type:
Optional[str]
- _expath
Path to the main BSM executable/script.
- Type:
str
- _app_version
The application’s version string.
- Type:
str
- _WEB_SERVER_PID_FILENAME
Filename for the Web UI PID file.
- Type:
str
- _WEB_SERVICE_SYSTEMD_NAME
Name for the Web UI systemd service.
- Type:
str
- _WEB_SERVICE_WINDOWS_NAME_INTERNAL
Internal name for the Web UI Windows service.
- Type:
str
- _WEB_SERVICE_WINDOWS_DISPLAY_NAME
Display name for the Web UI Windows service.
- Type:
str
- __init__(settings: Settings) None
Initializes the BedrockServerManager instance.
This constructor sets up the manager by:
Accepting an instance of the
Settings
class, which provides access to all application configurations.Performing a check for system capabilities (e.g., availability of
crontab
,systemctl
) via_check_system_capabilities()
and logging warnings for missing dependencies via_log_capability_warnings()
.Caching essential paths (configuration directory, application data directory, servers base directory, content directory) and constants from the settings and application constants.
Defining constants for Web UI process/service management (PID filename, service names for Systemd and Windows).
Validating that critical directory paths (servers base directory, content directory) are configured in settings, raising a
ConfigurationError
if not.
- Parameters:
settings (Settings) – An instance of the application’s
Settings
object.- Raises:
ConfigurationError – If the provided
Settings
object is misconfigured (e.g., missing critical path definitions likepaths.servers
orpaths.content
), or if core application constants cannot be accessed.
- load()
Loads the manager’s settings and capabilities.
- get_setting(key: str, default: Any = None) Any
Retrieves a configuration value by its key from the global settings.
This method acts as a proxy to the
get()
method of the underlyingSettings
object.- Parameters:
key (str) – The dot-separated key of the setting to retrieve (e.g.,
"web.port"
,"paths.servers"
).default (Any) – The value to return if the key is not found. Defaults to
None
.
- Returns:
The value of the setting, or the
default
value if the key is not found. The actual type depends on the setting being retrieved.- Return type:
Any
- set_setting(key: str, value: Any) None
Sets a configuration value by its key in the global settings and saves it.
This method acts as a proxy to the
set()
method of the underlyingSettings
object. Changes made through this method are typically persisted to the application’s configuration file.- Parameters:
key (str) – The dot-separated key of the setting to set (e.g.,
"web.port"
,"logging.level"
).value (Any) – The new value for the setting.
:raises Various (from
Settings
): PotentiallyFileOperationError
if saving the settings file fails.