scout 5.6.8 → 5.6.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +5 -1
- data/Gemfile +2 -1
- data/lib/scout.rb +1 -0
- data/lib/scout/command/install.rb +70 -21
- data/lib/scout/environment.rb +15 -0
- data/lib/scout/version.rb +2 -2
- data/test/scout_test.rb +37 -9
- metadata +3 -2
data/CHANGELOG.markdown
CHANGED
data/Gemfile
CHANGED
data/lib/scout.rb
CHANGED
@@ -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
|
-
|
14
|
+
|
15
|
+
key = @args.first || get_key_from_stdin
|
19
16
|
|
20
17
|
puts "\nAttempting to contact the server..."
|
21
18
|
begin
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
-
|
40
|
-
(using crontab -e to edit):
|
30
|
+
Run `crontab -e`, pasting the line below into your Crontab file:
|
41
31
|
|
42
|
-
|
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.
|
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
|
-
|
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(
|
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.
|
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-
|
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
|