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 "    I need your Agent Key displayed in the Agent Settings tab\n    to communicate with the server.  It looks like:\n\n        a7349498-bec3-4ddf-963c-149a666433a4\n\n    Enter the Agent Key:\n    END_KEY_DESCRIPTION\n    Plan.agent_key = gets.to_s.strip\n    puts\n    if test_server_connection\n      puts\n    else\n      puts\n      abort_with_bad_key\n    end\n  end\n  \n  # write the configuration file\n  puts \"Saving identification...\"\n  if Plan.write_default_config_file\n    puts \"Identification file '\#{Plan.config_file}' created.\"\n  else\n    if Plan.config_file.exist?\n      puts \"Identification file '\#{Plan.config_file}' exists.  Skipped.\"\n    else\n      abort_with_insufficient_permissions(Plan.config_file)\n    end\n  end\n  # create directories and global databases\n  %w[db_dir log_dir].each do |path|\n    dir = Plan.send(path)\n    if dir.exist?\n      puts \"Directory '\#{dir}' exists.  Skipped.\"\n    elsif Plan.send(\"build_\#{path}\", group.gid)\n      puts \"Directory '\#{dir}' created.\"\n    else\n      abort_with_insufficient_permissions(dir)\n    end\n    if path == \"db_dir\"\n      %w[statuses queue snapshots].each do |name|\n        db = Database.path(name)\n        if db.exist?\n          puts \"Database '\#{db}' exists.  Skipped.\"\n        elsif Plan.prepare_global_database(name)\n          puts \"Database '\#{db}' created.\"\n        else\n          abort_with_insufficient_permissions(db)\n        end\n      end\n    end\n  end\n  puts \"Done.\"\n  puts\n  \n  # show next steps\n  puts <<-END_START_INSTRUCTIONS.trim\n  You are now identified.  You can start the agent with:\n  \n      sudo \#{$PROGRAM_NAME} start\n  \n  END_START_INSTRUCTIONS\nend\n".trim.to_question