Class: ScoutAgent::Assignment::Identify

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

Instance Attribute Summary

Attributes inherited from ScoutAgent::Assignment

#group, #other_args, #switches, #user

Instance Method Summary collapse

Methods inherited from ScoutAgent::Assignment

#initialize, #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



10
11
12
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
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
80
81
82
83
84
85
86
# File 'lib/scout_agent/assignment/identify.rb', line 10

def execute
  puts "Identifying Your Agent"
  puts "======================"
  puts
  
  %w[config_file db_dir log_dir].each do |path|
    full = dir = Plan.send(path)
    loop do
      dir = dir.dirname
      break if dir.exist?
    end
    unless dir.writable?
      abort_with_insufficient_permissions(full)
    end
  end
  
  unless Plan.config_file.exist?
    print <<-END_KEY_DESCRIPTION.trim.to_question
    I need your Agent Key displayed in the Agent Settings tab
    to communicate with the server.  It looks like:

        a7349498-bec3-4ddf-963c-149a666433a4

    Enter the Agent Key:
    END_KEY_DESCRIPTION
    Plan.agent_key = gets.to_s.strip
    puts
    if test_server_connection
      puts
    else
      puts
      abort_with_bad_key
    end
  end
  
  puts "Saving identification..."
  if Plan.write_default_config_file
    puts "Identification file '#{Plan.config_file}' created."
  else
    if Plan.config_file.exist?
      puts "Identification file '#{Plan.config_file}' exists.  Skipped."
    else
      abort_with_insufficient_permissions(Plan.config_file)
    end
  end
  %w[db_dir log_dir].each do |path|
    dir = Plan.send(path)
    if dir.exist?
      puts "Directory '#{dir}' exists.  Skipped."
    elsif Plan.send("build_#{path}", group.gid)
      puts "Directory '#{dir}' created."
    else
      abort_with_insufficient_permissions(dir)
    end
    if path == "db_dir"
      %w[statuses queue snapshots].each do |name|
        db = Database.path(name)
        if db.exist?
          puts "Database '#{db}' exists.  Skipped."
        elsif Plan.prepare_global_database(name)
          puts "Database '#{db}' created."
        else
          abort_with_insufficient_permissions(db)
        end
      end
    end
  end
  puts "Done."
  puts
  
  puts <<-END_START_INSTRUCTIONS.trim
  You are now identified.  You can start the agent with:
  
      sudo #{$PROGRAM_NAME} start
  
  END_START_INSTRUCTIONS
end