Class: ScoutAgent::Assignment::Reset

Inherits:
ScoutAgent::Assignment show all
Defined in:
lib/scout_agent/assignment/reset.rb

Overview

Invoke with:

sudo scout_agent reset

This command removes all saved configuration and data from the agent. After this is run it’s basically like the agent has been reset to the way it was after being intalled. This is a dangerous command that destroys data and cannot be undone.

Instance Attribute Summary

Attributes inherited from ScoutAgent::Assignment

#group, #other_args, #switches, #user

Instance Method Summary collapse

Methods inherited from ScoutAgent::Assignment

choose_group, choose_user, #initialize, plan, #prepare_and_execute

Methods included from Tracked

#clear_status, #force_status_database_reload, #status, #status_database, #status_log

Constructor Details

This class inherits a constructor from ScoutAgent::Assignment

Instance Method Details

#executeObject

Runs the reset command.



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/scout_agent/assignment/reset.rb', line 18

def execute
  # make sure the agent isn't running
  agent = IDCard.new(:lifeline)
  if agent.pid_file.exist?
    abort_with_agent_running
  end
  
  puts "Reset Your Agent"
  puts "================"
  puts
  
  # get confirmation from the user
  print <<-END_WARNING.trim.to_question
  This is a dangerous operation that will remove configuration
  and data files.  Are you absolutely sure you wish to remove
  this data (yes/no)?
  END_WARNING
  unless gets.to_s.strip.downcase == "yes"
    abort_with_cancel
  end
  
  puts
  puts "Resetting..."
  # remove configuration file
  if not Plan.config_file.exist?
    puts <<-END_CONFIG_FILE
    Identification file '#{Plan.config_file}' doesn't exist.  Skipped.
    END_CONFIG_FILE
  else
    begin
      Plan.config_file.unlink
      puts "Identification file '#{Plan.config_file}' removed."
    rescue Errno::EACCES  # don't have permission
      abort_with_insufficient_permissions(Plan.config_file)
    end
  end
  # remove directories and the data they contain
  %w[db_dir pid_dir log_dir].each do |path|
    dir = Plan.send(path)
    if not dir.exist?
      puts "Directory '#{dir}' doesn't exist.  Skipped."
    else
      begin
        dir.rmtree
        puts "Directory '#{dir}' removed."
      rescue Errno::EACCES  # don't have permission
        abort_with_insufficient_permissions(dir)
      end
    end
  end
  puts "Done."
  puts
  
  # show next steps
  puts <<-END_START_INSTRUCTIONS.trim
  This agent is reset.  You can prepare it for use again
  at anytime with:
  
      sudo #{$PROGRAM_NAME} identify
  
  END_START_INSTRUCTIONS
end