Class: ScoutAgent::Assignment::Identify

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

Overview

Invoke with:

sudo scout_agent id

This command prepares the agent for use by recording your key and settings into a configuration file. This file is then loaded by all other commands to configure the agent for use. Have a look at scout_agent -h for other options you may wish to set, like proxy.

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 identify command.



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/scout_agent/assignment/identify.rb', line 21

def execute
  puts "Identifying Your Agent"
  puts "======================"
  puts
  
  # make sure we can access the needed directories
  %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
  
  # get a key and test the server connection with that key
  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
  
  # write the configuration file
  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
  # create directories and global databases
  %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
  
  # show next steps
  puts <<-END_START_INSTRUCTIONS.trim
  You are now identified.  You can start the agent with:
  
      sudo #{$PROGRAM_NAME} start
  
  END_START_INSTRUCTIONS
end