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:

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 BedrockServer instantiation if core application settings are misconfigured, or by get_process_info if psutil is 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 either enable_service() or disable_service(). Triggers before_service_change and after_service_change plugin 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. If False, it will be created but left disabled (or set to manual start). Defaults to False.

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:
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(). Triggers before_autoupdate_change and after_autoupdate_change plugin 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:
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(). Triggers before_service_change and after_service_change plugin 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:
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(). Triggers before_service_change and after_service_change plugin 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: