Class: Pvectl::Commands::Shutdown

Inherits:
Object
  • Object
show all
Includes:
VmLifecycleCommand
Defined in:
lib/pvectl/commands/shutdown.rb

Overview

Handler for the ‘pvectl shutdown` command.

Shuts down one or more virtual machines gracefully (ACPI).

Examples:

Shutdown a single VM

pvectl shutdown vm 100

Shutdown with sync mode

pvectl shutdown vm 100 --wait

Constant Summary collapse

OPERATION =
:shutdown

Class Method Summary collapse

Methods included from VmLifecycleCommand

included

Methods included from ResourceLifecycleCommand

#execute, included, #initialize

Class Method Details

.register(cli) ⇒ void

This method returns an undefined value.

Registers the shutdown command with the CLI.

Parameters:

  • cli (GLI::App)

    the CLI application object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pvectl/commands/shutdown.rb', line 22

def self.register(cli)
  cli.desc "Shutdown virtual machines or containers gracefully"
  cli.long_desc <<~HELP
    Gracefully shut down one or more virtual machines or containers.
    Sends an ACPI shutdown signal to VMs or a clean shutdown to containers,
    allowing the guest OS to shut down properly.

    This is the recommended way to stop production workloads. For
    immediate termination, use 'pvectl stop' instead.

    EXAMPLES
      Graceful shutdown of a VM:
        $ pvectl shutdown vm 100

      Shutdown with wait and timeout:
        $ pvectl shutdown vm 100 --wait --timeout 120

      Shutdown all running VMs on a node:
        $ pvectl shutdown vm --all --node pve1 -l status=running --yes

    NOTES
      Requires QEMU Guest Agent or ACPI support in the VM for graceful
      shutdown. If the guest doesn't respond, the shutdown may time out.

      Use --timeout with --wait to set a maximum wait time.

    SEE ALSO
      pvectl help stop            Hard stop (immediate, may cause data loss)
      pvectl help restart         Reboot resources
  HELP
  cli.arg_name "RESOURCE_TYPE [ID...]"
  cli.command :shutdown do |c|
    SharedFlags.lifecycle(c)

    c.action do |global_options, options, args|
      resource_type = args.shift
      resource_ids = args
      exit_code = case resource_type
      when "container", "ct"
        ShutdownContainer.execute(resource_type, resource_ids, options, global_options)
      else
        execute(resource_type, resource_ids, options, global_options)
      end
      exit exit_code if exit_code != 0
    end
  end
end