Class: Nvoi::Cli::Unlock::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/cli/unlock/command.rb

Overview

Command removes deployment lock from remote server

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Command

Returns a new instance of Command.



8
9
10
11
# File 'lib/nvoi/cli/unlock/command.rb', line 8

def initialize(options)
  @options = options
  @log = Nvoi.logger
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
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
# File 'lib/nvoi/cli/unlock/command.rb', line 13

def run
  config_path = resolve_config_path
  @config = Utils::ConfigLoader.load(config_path)

  # Apply branch override if specified
  apply_branch_override if @options[:branch]

  # Initialize cloud provider
  @provider = External::Cloud.for(@config)

  # Find main server
  server = @provider.find_server(@config.server_name)
  raise Errors::ServiceError, "server not found: #{@config.server_name}" unless server

  ssh = External::Ssh.new(server.public_ipv4, @config.ssh_key_path)
  lock_file = @config.namer.deployment_lock_file_path

  # Check if lock exists and show info
  output = ssh.execute("test -f #{lock_file} && cat #{lock_file} || echo ''").strip

  if output.empty?
    @log.info "No lock file found: %s", lock_file
    return
  end

  timestamp = output.to_i
  if timestamp > 0
    lock_time = Time.at(timestamp)
    age = Time.now - lock_time
    @log.info "Lock file age: %ds (since %s)", age.round, lock_time.strftime("%H:%M:%S")
  end

  ssh.execute("rm -f #{lock_file}")
  @log.success "Removed lock file: %s", lock_file
end