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