scout 5.6.8 → 5.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 5.6.9
2
+
3
+ * Install command generates a script for cron to run when using RVM or Bundler
4
+
1
5
  # 5.6.8
2
6
 
3
7
  * Updated JSON to 1.8.0
@@ -336,4 +340,4 @@
336
340
 
337
341
  # 1.0.0
338
342
 
339
- * Initial release
343
+ * Initial release
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ group :test do
7
7
  gem "newrelic_rpm"
8
8
  gem "activerecord", "2.2.2"
9
9
  gem "mysql"
10
- end
10
+ gem "mocha", :require => false
11
+ end
data/lib/scout.rb CHANGED
@@ -11,3 +11,4 @@ require "scout/streamer"
11
11
  require "scout/daemon_spawn"
12
12
  require "scout/streamer_daemon"
13
13
  require "scout/data_file"
14
+ require "scout/environment"
@@ -6,42 +6,30 @@ module Scout
6
6
  def run
7
7
  create_pid_file_or_exit
8
8
 
9
- abort usage unless $stdin.tty?
9
+ abort usage unless $stdin.tty? || @args.first
10
10
 
11
11
  puts <<-END_INTRO.gsub(/^ {8}/, "")
12
12
  === Scout Installation Wizard ===
13
-
14
- You need the 40-character alphanumeric key displayed on the account page.
15
-
16
- Enter the Key:
17
13
  END_INTRO
18
- key = gets.to_s.strip
14
+
15
+ key = @args.first || get_key_from_stdin
19
16
 
20
17
  puts "\nAttempting to contact the server..."
21
18
  begin
22
- Scout::Server.new(server, key, history, log, server_name, @http_proxy, @https_proxy, @roles, @hostname) do |scout|
23
- scout.fetch_plan
24
- scout.run_plugins_by_plan
25
- end
19
+ test_server_connection(key)
20
+
21
+ create_cron_script(key) if cron_script_required?
26
22
 
27
23
  puts <<-END_SUCCESS.gsub(/^ {10}/, "")
28
24
  Success!
29
25
 
30
26
  Now, you must setup Scout to run on a scheduled basis.
31
27
 
32
- If you are using the system crontab
33
- (usually located at /etc/crontab):
34
-
35
- ****** START CRONTAB SAMPLE ******
36
- * * * * * #{user} #{program_path} #{key}
37
- ****** END CRONTAB SAMPLE ******
28
+ #{special_cron_information}
38
29
 
39
- If you are using this current user's crontab
40
- (using crontab -e to edit):
30
+ Run `crontab -e`, pasting the line below into your Crontab file:
41
31
 
42
- ****** START CRONTAB SAMPLE ******
43
- * * * * * #{program_path} #{key}
44
- ****** END CRONTAB SAMPLE ******
32
+ * * * * * #{cron_command(key)}
45
33
 
46
34
  For help setting up Scout with crontab, please visit:
47
35
 
@@ -60,6 +48,67 @@ module Scout
60
48
  END_ERROR
61
49
  end
62
50
  end
51
+
52
+ private
53
+
54
+ def create_cron_script(key)
55
+ cron_script = File.join(config_dir, "scout_cron.sh")
56
+ File.open(cron_script, 'w') do |file|
57
+ file.puts '#! /usr/bin/env bash'
58
+ file.puts '# This shell script executes the scout command and was auto-generated by the "scout install" command.'
59
+ file.puts '# It\'s needed for environments that use RVM and/or Bundler.'
60
+ file.puts
61
+
62
+ if Environment.rvm?
63
+ file.puts '# Loading the RVM Environment files.'
64
+ file.puts "source #{Environment.rvm_path}\n"
65
+ end
66
+
67
+ if Environment.bundler?
68
+ file.puts '# Changing directories to your rails project.'
69
+ file.puts "cd #{`pwd`}\n"
70
+
71
+ file.puts '# Call Scout and pass your unique key.'
72
+ file.puts "bundle exec scout #{key}"
73
+ else
74
+ file.puts '# Call Scout and pass your unique key.'
75
+ file.puts "scout #{key}"
76
+ end
77
+ end
78
+ File.chmod(0774, cron_script)
79
+ end
80
+
81
+ def special_cron_information
82
+ "It looks like you've installed Scout under RVM and/or Bundler. We've generated a shell script for you." if cron_script_required?
83
+ end
84
+
85
+ def cron_command(key)
86
+ if cron_script_required?
87
+ "#{config_dir}/scout_cron.sh"
88
+ else
89
+ "#{`which scout`.strip} #{key}"
90
+ end
91
+ end
92
+
93
+ def cron_script_required?
94
+ Environment.rvm? || Environment.bundler?
95
+ end
96
+
97
+ def get_key_from_stdin
98
+ puts <<-END_GET_KEY.gsub(/^ {10}/, "")
99
+ You need the 40-character alphanumeric key displayed on the account page.
100
+
101
+ Enter the Key:
102
+ END_GET_KEY
103
+ key = gets.to_s.strip
104
+ end
105
+
106
+ def test_server_connection(key)
107
+ Scout::Server.new(server, key, history, log, server_name, @http_proxy, @https_proxy, @roles, @hostname) do |scout|
108
+ scout.fetch_plan
109
+ scout.run_plugins_by_plan
110
+ end
111
+ end
63
112
  end
64
113
  end
65
114
  end
@@ -0,0 +1,15 @@
1
+ module Scout
2
+ class Environment
3
+ def self.bundler?
4
+ ENV['BUNDLE_BIN_PATH'] && ENV['BUNDLE_GEMFILE']
5
+ end
6
+
7
+ def self.rvm?
8
+ ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
9
+ end
10
+
11
+ def self.rvm_path
12
+ `rvm env --path`
13
+ end
14
+ end
15
+ end
data/lib/scout/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scout
2
- VERSION = "5.6.8"
3
- end
2
+ VERSION = "5.6.9"
3
+ end
data/test/scout_test.rb CHANGED
@@ -19,6 +19,7 @@ require 'test/unit'
19
19
  $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
20
20
  $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/..' )
21
21
  require 'lib/scout'
22
+ require 'mocha'
22
23
 
23
24
 
24
25
  SCOUT_PATH = '../scout'
@@ -64,7 +65,13 @@ class ScoutTest < Test::Unit::TestCase
64
65
 
65
66
  def test_should_checkin_during_interactive_install
66
67
  Client.update_all "last_checkin=null"
67
- res=""
68
+ Scout::Command::Install.new({:server => 'http://localhost:4567', :history => PATH_TO_DATA_FILE},[@client.key]).run
69
+
70
+ assert_in_delta Time.now.utc.to_i, @client.reload.last_ping.to_i, 100
71
+ assert_in_delta Time.now.utc.to_i, @client.reload.last_checkin.to_i, 100
72
+ end
73
+
74
+ def test_prompts_the_user_for_a_key_if_none_is_provided
68
75
  PTY.spawn("bin/scout -s http://localhost:4567 -d #{PATH_TO_DATA_FILE} install ") do | stdin, stdout, pid |
69
76
  begin
70
77
  stdin.expect("Enter the Key:", 3) do |response|
@@ -76,11 +83,6 @@ class ScoutTest < Test::Unit::TestCase
76
83
  # don't care
77
84
  end
78
85
  end
79
-
80
- assert res.match(/Attempting to contact the server.+Success!/m), "Output from interactive install session isn't right"
81
-
82
- assert_in_delta Time.now.utc.to_i, @client.reload.last_ping.to_i, 100
83
- assert_in_delta Time.now.utc.to_i, @client.reload.last_checkin.to_i, 100
84
86
  end
85
87
 
86
88
  def test_should_run_first_time
@@ -575,6 +577,33 @@ mybar=100
575
577
  assert_equal hostname_override, client.hostname
576
578
  end
577
579
 
580
+ def test_create_cron_script
581
+ Scout::Environment.stubs(:rvm?).returns(true)
582
+ Scout::Environment.stubs(:bundler?).returns(true)
583
+ install = Scout::Command::Install.new({:history => PATH_TO_DATA_FILE},{})
584
+ install.send(:create_cron_script, @client.key)
585
+ cron_script = File.join(AGENT_DIR, 'scout_cron.sh')
586
+ assert File.exist?(cron_script)
587
+ assert File.executable?(cron_script)
588
+ File.delete(cron_script)
589
+ end
590
+
591
+ def test_generate_rvm_bundler_cron_command
592
+ Scout::Environment.stubs(:rvm?).returns(true)
593
+ Scout::Environment.stubs(:bundler?).returns(true)
594
+ install = Scout::Command::Install.new({},{})
595
+ cron_command = install.send(:cron_command, @client.key)
596
+ assert cron_command.include?('scout_cron.sh')
597
+ end
598
+
599
+ def test_generate_non_rvm_bundler_cron_command
600
+ Scout::Environment.stubs(:rvm?).returns(false)
601
+ Scout::Environment.stubs(:bundler?).returns(false)
602
+ install = Scout::Command::Install.new({},{})
603
+ cron_command = install.send(:cron_command, @client.key)
604
+ assert_equal cron_command, "#{`which scout`.strip} #{@client.key}"
605
+ end
606
+
578
607
 
579
608
  ######################
580
609
  ### Helper Methods ###
@@ -600,9 +629,8 @@ mybar=100
600
629
  # scout in the process, making debugging easier.
601
630
  # * The option handling is different in this method vs. #exec_scout: it takes an Array of options as Scout::Command.dispatch
602
631
  # uses ARGV.
603
- def scout(key, *opts)
604
- args = []
605
- args << key
632
+ def scout(args, *opts)
633
+ args = Array(args)
606
634
  args += ['-s','http://localhost:4567']
607
635
  args += ['-d', PATH_TO_DATA_FILE]
608
636
  args += opts if opts.any?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.8
4
+ version: 5.6.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-05-15 00:00:00.000000000 Z
14
+ date: 2013-05-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: elif
@@ -59,6 +59,7 @@ files:
59
59
  - lib/scout/command/troubleshoot.rb
60
60
  - lib/scout/daemon_spawn.rb
61
61
  - lib/scout/data_file.rb
62
+ - lib/scout/environment.rb
62
63
  - lib/scout/plugin.rb
63
64
  - lib/scout/plugin_options.rb
64
65
  - lib/scout/scout_logger.rb