Class: Pvectl::Services::ServiceLifecycle

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/services/service_lifecycle.rb

Overview

Orchestrates systemd service lifecycle operations (start/stop/restart/reload) on a Proxmox node.

Wraps Repositories::Service to provide a uniform return shape suitable for table/JSON/YAML formatting (Models::NodeOperationResult) and to convert API errors into structured results instead of raising.

Examples:

Restarting a service

service = ServiceLifecycle.new(service_repository: repo)
result = service.execute(operation: :restart, node: "pve1", service: "pveproxy")
result.successful? # => true

Constant Summary collapse

OPERATIONS =

Operations supported by the Proxmox services API.

%i[start stop restart reload].freeze

Instance Method Summary collapse

Constructor Details

#initialize(service_repository:) ⇒ ServiceLifecycle

Creates a new ServiceLifecycle orchestrator.

Parameters:



24
25
26
# File 'lib/pvectl/services/service_lifecycle.rb', line 24

def initialize(service_repository:)
  @service_repository = service_repository
end

Instance Method Details

#execute(operation:, node:, service:) ⇒ Models::NodeOperationResult

Executes a lifecycle operation on a single service.

Parameters:

  • operation (Symbol)

    one of :start, :stop, :restart, :reload

  • node (String)

    node name

  • service (String)

    service identifier (e.g., “pveproxy”)

Returns:

Raises:

  • (ArgumentError)

    when operation is unknown



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pvectl/services/service_lifecycle.rb', line 35

def execute(operation:, node:, service:)
  validate_operation!(operation)

  begin
    upid = @service_repository.public_send(operation, node, service)
    build_result(
      operation: operation,
      node: node,
      service: service,
      task_upid: upid,
      success: :pending
    )
  rescue StandardError => e
    build_result(
      operation: operation,
      node: node,
      service: service,
      success: false,
      error: e.message
    )
  end
end