System API Documentation
Provides API functions for system-level server interactions and information.
This module serves as an interface for querying system-related information about
server processes and for managing their integration with the host operating system’s
service management capabilities. It primarily orchestrates calls to the
BedrockServer class.
- Key functionalities include:
Querying server process resource usage (e.g., PID, CPU, memory) via
get_bedrock_process_info().Managing OS-level services (systemd on Linux, Windows Services on Windows) for servers, including creation (
create_server_service()), enabling (enable_server_service()), and disabling (disable_server_service()) auto-start.Configuring server-specific settings like autoupdate behavior via
set_autoupdate().
These functions are designed for use by higher-level application components, such as the web UI or CLI, to provide system-level control and monitoring.
- bedrock_server_manager.api.system.get_bedrock_process_info(server_name: str) Dict[str, Any]
Retrieves resource usage for a running Bedrock server process.
This function queries the system for the server’s process by calling
get_process_info()and returns details like PID, CPU usage, memory consumption, and uptime.- Parameters:
server_name (str) – The name of the server to query.
- Returns:
A dictionary with the operation status and process information. On success with a running process:
{"status": "success", "process_info": {"pid": int, "cpu_percent": float, "memory_mb": float, "uptime": str}}. If the process is not found or inaccessible:{"status": "success", "process_info": None, "message": "Server process '<name>' not found..."}. On error during retrieval:{"status": "error", "message": "<error_message>"}.- Return type:
Dict[str, Any]
- Raises:
InvalidServerNameError – If server_name is not provided.
BSMError – Can be raised by
BedrockServerinstantiation if core application settings are misconfigured, or byget_process_infoifpsutilis unavailable or encounters issues.
- bedrock_server_manager.api.system.create_server_service(server_name: str, autostart: bool = False) Dict[str, str]
Creates (or updates) a system service for the server.
On Linux, this creates a systemd user service. On Windows, this creates a Windows Service (typically requires Administrator privileges).
This function calls
create_service()to generate and install the service definition. Based on the autostart flag, it then calls eitherenable_service()ordisable_service(). Triggersbefore_service_changeandafter_service_changeplugin events.- Parameters:
server_name (str) – The name of the server for which to create the service.
autostart (bool, optional) – If
True, the service will be enabled to start automatically on system boot/login. IfFalse, it will be created but left disabled (or set to manual start). Defaults toFalse.
- Returns:
A dictionary with the operation result. On success:
{"status": "success", "message": "System service created and <enabled/disabled> successfully."}On error:{"status": "error", "message": "<error_message>"}- Return type:
Dict[str, str]
- Raises:
InvalidServerNameError – If server_name is not provided.
BSMError – Can be raised by the underlying service management methods for various reasons, including: -
SystemErrorif the OS is unsupported or system commands fail. -PermissionsErrorif lacking necessary privileges (especially on Windows). -CommandNotFoundErrorif essential system utilities are missing. -FileOperationErrorif service file creation/modification fails.
- bedrock_server_manager.api.system.set_autoupdate(server_name: str, autoupdate_value: str) Dict[str, str]
Sets the ‘autoupdate’ flag in the server’s specific JSON configuration file.
This function modifies the server-specific JSON configuration file to enable or disable the automatic update check before the server starts, by calling
set_autoupdate(). Triggersbefore_autoupdate_changeandafter_autoupdate_changeplugin events.- Parameters:
server_name (str) – The name of the server.
autoupdate_value (str) – The desired state for autoupdate. Must be ‘true’ or ‘false’ (case-insensitive).
- Returns:
A dictionary with the operation result. On success:
{"status": "success", "message": "Autoupdate setting for '<name>' updated to <bool_value>."}On error:{"status": "error", "message": "<error_message>"}- Return type:
Dict[str, str]
- Raises:
InvalidServerNameError – If server_name is not provided.
MissingArgumentError – If autoupdate_value is not provided.
UserInputError – If autoupdate_value is not ‘true’ or ‘false’.
FileOperationError – If writing the server’s JSON configuration file fails.
ConfigParseError – If the server’s JSON configuration is malformed during load/save.
- bedrock_server_manager.api.system.enable_server_service(server_name: str) Dict[str, str]
Enables the system service for autostart.
On Linux, this enables the systemd user service. On Windows, this sets the Windows Service start type to ‘Automatic’ (typically requires Administrator privileges). This is achieved by calling
enable_service(). Triggersbefore_service_changeandafter_service_changeplugin events.- Parameters:
server_name (str) – The name of the server whose service is to be enabled.
- Returns:
A dictionary with the operation result. On success:
{"status": "success", "message": "Service for '<name>' enabled successfully."}On error:{"status": "error", "message": "<error_message>"}- Return type:
Dict[str, str]
- Raises:
InvalidServerNameError – If server_name is not provided.
BSMError – Can be raised by the underlying service management methods, e.g.,
SystemErrorif the service does not exist or OS commands fail, orPermissionsErroron Windows if not run with sufficient privileges.
- bedrock_server_manager.api.system.disable_server_service(server_name: str) Dict[str, str]
Disables the system service from autostarting.
On Linux, this disables the systemd user service. On Windows, this sets the Windows Service start type to ‘Disabled’ (typically requires Administrator privileges). This is achieved by calling
disable_service(). Triggersbefore_service_changeandafter_service_changeplugin events.- Parameters:
server_name (str) – The name of the server whose service is to be disabled.
- Returns:
A dictionary with the operation result. On success:
{"status": "success", "message": "Service for '<name>' disabled successfully."}On error:{"status": "error", "message": "<error_message>"}- Return type:
Dict[str, str]
- Raises:
InvalidServerNameError – If server_name is not provided.
BSMError – Can be raised by the underlying service management methods, e.g.,
SystemErrorif the service does not exist or OS commands fail, orPermissionsErroron Windows if not run with sufficient privileges.