Class: Pvectl::Repositories::Service
- Defined in:
- lib/pvectl/repositories/service.rb
Overview
Repository for systemd services on Proxmox nodes.
Wraps the ‘/nodes/node/services` API endpoints. Provides listing of services on a node and lifecycle operations (start/stop/restart/reload) which return Proxmox task UPIDs.
Instance Method Summary collapse
-
#list(node: nil) ⇒ Array<Models::Service>
Lists systemd services on a node.
-
#reload(node, service) ⇒ String
Reloads a service (falls back to restart if unsupported).
-
#restart(node, service) ⇒ String
Hard-restarts a service.
-
#start(node, service) ⇒ String
Starts a service.
-
#state(node, service) ⇒ Models::Service?
Reads single service state.
-
#stop(node, service) ⇒ String
Stops a service.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Pvectl::Repositories::Base
Instance Method Details
#list(node: nil) ⇒ Array<Models::Service>
Lists systemd services on a node.
When node is nil, iterates over all online nodes in the cluster. When node is specified, queries only that node.
30 31 32 33 34 35 36 |
# File 'lib/pvectl/repositories/service.rb', line 30 def list(node: nil) if node services_for_node(node) else online_nodes.flat_map { |node_name| services_for_node(node_name) } end end |
#reload(node, service) ⇒ String
Reloads a service (falls back to restart if unsupported). Returns the task UPID.
85 86 87 |
# File 'lib/pvectl/repositories/service.rb', line 85 def reload(node, service) post_action(node, service, "reload") end |
#restart(node, service) ⇒ String
Hard-restarts a service. Returns the task UPID.
76 77 78 |
# File 'lib/pvectl/repositories/service.rb', line 76 def restart(node, service) post_action(node, service, "restart") end |
#start(node, service) ⇒ String
Starts a service. Returns the task UPID.
58 59 60 |
# File 'lib/pvectl/repositories/service.rb', line 58 def start(node, service) post_action(node, service, "start") end |
#state(node, service) ⇒ Models::Service?
Reads single service state.
43 44 45 46 47 48 49 50 51 |
# File 'lib/pvectl/repositories/service.rb', line 43 def state(node, service) resp = connection.client["nodes/#{node}/services/#{service}/state"].get data = extract_data(resp) return nil if data.nil? || data.empty? build_model(data.merge(node: node)) rescue StandardError nil end |
#stop(node, service) ⇒ String
Stops a service. Returns the task UPID.
67 68 69 |
# File 'lib/pvectl/repositories/service.rb', line 67 def stop(node, service) post_action(node, service, "stop") end |