slashport 0.15.10
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/Rakefile +35 -0
- data/app/controllers/application.rb +2 -0
- data/app/controllers/cfg.rb +8 -0
- data/app/controllers/exceptions.rb +13 -0
- data/app/controllers/var.rb +27 -0
- data/app/controllers/vardoc.rb +7 -0
- data/app/helpers/cfg_helper.rb +5 -0
- data/app/helpers/global_helpers.rb +5 -0
- data/app/helpers/var_helper.rb +5 -0
- data/app/helpers/vardoc_helper.rb +5 -0
- data/app/models/base/attribute.rb +13 -0
- data/app/models/base/component.rb +206 -0
- data/app/models/base/exec.rb +40 -0
- data/app/models/base/registry.rb +4 -0
- data/app/models/base/tuple.rb +31 -0
- data/app/models/components/linuxhost.rb +125 -0
- data/app/models/components/linuxprocess.rb +55 -0
- data/app/models/components/mysql.rb +110 -0
- data/app/models/components/puppet.rb +20 -0
- data/app/views/cfg/index.html.erb +1 -0
- data/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/app/views/exceptions/not_found.html.erb +47 -0
- data/app/views/layout/application.html.erb +12 -0
- data/app/views/var/index.json.erb +1 -0
- data/app/views/var/index.pp.erb +10 -0
- data/app/views/var/index.text.erb +18 -0
- data/app/views/vardoc/index.html.erb +1 -0
- data/autotest/discover.rb +1 -0
- data/autotest/merb.rb +149 -0
- data/autotest/merb_rspec.rb +165 -0
- data/bin/slashport +130 -0
- data/bin/slashportfetch +103 -0
- data/config/environments/development.rb +15 -0
- data/config/environments/production.rb +10 -0
- data/config/environments/rake.rb +11 -0
- data/config/environments/staging.rb +10 -0
- data/config/environments/test.rb +12 -0
- data/config/init.rb +26 -0
- data/config/rack.rb +11 -0
- data/config/router.rb +41 -0
- data/config/test.conf +2 -0
- data/doc/rdoc/generators/merb_generator.rb +1362 -0
- data/doc/rdoc/generators/template/merb/api_grease.js +640 -0
- data/doc/rdoc/generators/template/merb/index.html.erb +37 -0
- data/doc/rdoc/generators/template/merb/merb.css +252 -0
- data/doc/rdoc/generators/template/merb/merb.rb +351 -0
- data/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
- data/doc/rdoc/generators/template/merb/prototype.js +2515 -0
- data/lib/slashport.rb +93 -0
- data/public/favicon.ico +0 -0
- data/public/images/merb.jpg +0 -0
- data/public/javascripts/application.js +1 -0
- data/public/merb.fcgi +22 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/master.css +119 -0
- data/spec/requests/cfg_spec.rb +7 -0
- data/spec/requests/config_spec.rb +7 -0
- data/spec/requests/configdoc_spec.rb +7 -0
- data/spec/requests/var_spec.rb +7 -0
- data/spec/requests/vardoc_spec.rb +7 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +20 -0
- metadata +156 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
# Adapted from Autotest::Rails, RSpec's autotest class, as well as merb-core's.
|
2
|
+
require 'autotest'
|
3
|
+
|
4
|
+
class RspecCommandError < StandardError; end
|
5
|
+
|
6
|
+
# This class maps your application's structure so Autotest can understand what
|
7
|
+
# specs to run when files change.
|
8
|
+
#
|
9
|
+
# Fixtures are _not_ covered by this class. If you change a fixture file, you
|
10
|
+
# will have to run your spec suite manually, or, better yet, provide your own
|
11
|
+
# Autotest map explaining how your fixtures are set up.
|
12
|
+
class Autotest::MerbRspec < Autotest
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
|
16
|
+
# Ignore any happenings in these directories
|
17
|
+
add_exception %r%^\./(?:doc|log|public|tmp|\.git|\.hg|\.svn|framework|gems|schema|\.DS_Store|autotest|bin|.*\.sqlite3)%
|
18
|
+
# Ignore SCM directories and custom Autotest mappings
|
19
|
+
%w[.svn .hg .git .autotest].each { |exception| add_exception(exception) }
|
20
|
+
|
21
|
+
# Ignore any mappings that Autotest may have already set up
|
22
|
+
clear_mappings
|
23
|
+
|
24
|
+
# Anything in /lib could have a spec anywhere, if at all. So, look for
|
25
|
+
# files with roughly the same name as the file in /lib
|
26
|
+
add_mapping %r%^lib\/(.*)\.rb% do |_, m|
|
27
|
+
files_matching %r%^spec\/#{m[1]}%
|
28
|
+
end
|
29
|
+
|
30
|
+
add_mapping %r%^spec/(spec_helper|shared/.*)\.rb$% do
|
31
|
+
all_specs
|
32
|
+
end
|
33
|
+
|
34
|
+
# Changing a spec will cause it to run itself
|
35
|
+
add_mapping %r%^spec/.*\.rb$% do |filename, _|
|
36
|
+
filename
|
37
|
+
end
|
38
|
+
|
39
|
+
# Any change to a model will cause it's corresponding test to be run
|
40
|
+
add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
|
41
|
+
spec_for(m[1], 'model')
|
42
|
+
end
|
43
|
+
|
44
|
+
# Any change to global_helpers will result in all view and controller
|
45
|
+
# tests being run
|
46
|
+
add_mapping %r%^app/helpers/global_helpers\.rb% do
|
47
|
+
files_matching %r%^spec/(views|controllers|helpers)/.*_spec\.rb$%
|
48
|
+
end
|
49
|
+
|
50
|
+
# Any change to a helper will cause its spec to be run
|
51
|
+
add_mapping %r%^app/helpers/((.*)_helper(s)?)\.rb% do |_, m|
|
52
|
+
spec_for(m[1], 'helper')
|
53
|
+
end
|
54
|
+
|
55
|
+
# Changes to a view cause its spec to be run
|
56
|
+
add_mapping %r%^app/views/(.*)/% do |_, m|
|
57
|
+
spec_for(m[1], 'view')
|
58
|
+
end
|
59
|
+
|
60
|
+
# Changes to a controller result in its corresponding spec being run. If
|
61
|
+
# the controller is the exception or application controller, all
|
62
|
+
# controller specs are run.
|
63
|
+
add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
|
64
|
+
if ["application", "exception"].include?(m[1])
|
65
|
+
files_matching %r%^spec/controllers/.*_spec\.rb$%
|
66
|
+
else
|
67
|
+
spec_for(m[1], 'controller')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# If a change is made to the router, run controller, view and helper specs
|
72
|
+
add_mapping %r%^config/router.rb$% do
|
73
|
+
files_matching %r%^spec/(controllers|views|helpers)/.*_spec\.rb$%
|
74
|
+
end
|
75
|
+
|
76
|
+
# If any of the major files governing the environment are altered, run
|
77
|
+
# everything
|
78
|
+
add_mapping %r%^config/(init|rack|environments/test).*\.rb|database\.yml% do
|
79
|
+
all_specs
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def failed_results(results)
|
84
|
+
results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
|
85
|
+
end
|
86
|
+
|
87
|
+
def handle_results(results)
|
88
|
+
@failures = failed_results(results)
|
89
|
+
@files_to_test = consolidate_failures(@failures)
|
90
|
+
@files_to_test.empty? && !$TESTING ? hook(:green) : hook(:red)
|
91
|
+
@tainted = !@files_to_test.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
def consolidate_failures(failed)
|
95
|
+
filters = Hash.new { |h,k| h[k] = [] }
|
96
|
+
failed.each do |spec, failed_trace|
|
97
|
+
if f = test_files_for(failed).find { |f| f =~ /spec\// }
|
98
|
+
filters[f] << spec
|
99
|
+
break
|
100
|
+
end
|
101
|
+
end
|
102
|
+
filters
|
103
|
+
end
|
104
|
+
|
105
|
+
def make_test_cmd(specs_to_runs)
|
106
|
+
[
|
107
|
+
ruby,
|
108
|
+
"-S",
|
109
|
+
spec_command,
|
110
|
+
add_options_if_present,
|
111
|
+
files_to_test.keys.flatten.join(' ')
|
112
|
+
].join(' ')
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_options_if_present
|
116
|
+
File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
|
117
|
+
end
|
118
|
+
|
119
|
+
# Finds the proper spec command to use. Precendence is set in the
|
120
|
+
# lazily-evaluated method spec_commands. Alias + Override that in
|
121
|
+
# ~/.autotest to provide a different spec command then the default
|
122
|
+
# paths provided.
|
123
|
+
def spec_command(separator=File::ALT_SEPARATOR)
|
124
|
+
unless defined?(@spec_command)
|
125
|
+
@spec_command = spec_commands.find { |cmd| File.exists?(cmd) }
|
126
|
+
|
127
|
+
raise RspecCommandError, "No spec command could be found" unless @spec_command
|
128
|
+
|
129
|
+
@spec_command.gsub!(File::SEPARATOR, separator) if separator
|
130
|
+
end
|
131
|
+
@spec_command
|
132
|
+
end
|
133
|
+
|
134
|
+
# Autotest will look for spec commands in the following
|
135
|
+
# locations, in this order:
|
136
|
+
#
|
137
|
+
# * default spec bin/loader installed in Rubygems
|
138
|
+
# * any spec command found in PATH
|
139
|
+
def spec_commands
|
140
|
+
[File.join(Config::CONFIG['bindir'], 'spec'), 'spec']
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# Runs +files_matching+ for all specs
|
146
|
+
def all_specs
|
147
|
+
files_matching %r%^spec/.*_spec\.rb$%
|
148
|
+
end
|
149
|
+
|
150
|
+
# Generates a path to some spec given its kind and the match from a mapping
|
151
|
+
#
|
152
|
+
# ==== Arguments
|
153
|
+
# match<String>:: the match from a mapping
|
154
|
+
# kind<String>:: the kind of spec that the match represents
|
155
|
+
#
|
156
|
+
# ==== Returns
|
157
|
+
# String
|
158
|
+
#
|
159
|
+
# ==== Example
|
160
|
+
# > spec_for('post', :view')
|
161
|
+
# => "spec/views/post_spec.rb"
|
162
|
+
def spec_for(match, kind)
|
163
|
+
File.join("spec", kind + 's', "#{match}_spec.rb")
|
164
|
+
end
|
165
|
+
end
|
data/bin/slashport
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "merb-core"
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
class Options < Struct.new(:host, :port, :components, :configs, :logfile, :pidfile)
|
8
|
+
# empty
|
9
|
+
end # class Options
|
10
|
+
|
11
|
+
options = Options.new
|
12
|
+
options.host = "0.0.0.0"
|
13
|
+
options.port = 4000
|
14
|
+
options.components = []
|
15
|
+
options.configs = []
|
16
|
+
options.logfile = "-"
|
17
|
+
options.pidfile = "/tmp/slashport.pid"
|
18
|
+
|
19
|
+
parser = OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage; #{$0} [options}"
|
21
|
+
|
22
|
+
opts.on("-l HOST[:PORT]", "--listen HOST[:PORT]",
|
23
|
+
"Listen on specific host:port") do |v|
|
24
|
+
|
25
|
+
options.host, options.port = v.split(":")
|
26
|
+
|
27
|
+
if options.host == ""
|
28
|
+
options.host = "0.0.0.0"
|
29
|
+
end
|
30
|
+
options.port ||= 4000
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-c COMPONENT", "--component COMPONENT",
|
34
|
+
"Load specific component") do |v|
|
35
|
+
options.components << v
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-C COMPONENT_DIRECTORY", "--component-directory COMPONENT_DIRECTORY",
|
39
|
+
"Load components from a directory. All components must end in '.rb'") do |v|
|
40
|
+
if !File.directory?(v) or !File.readable?(v)
|
41
|
+
$stderr.puts "Path '#{v}' is not a directory or is not readable."
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
Dir["#{v}/*.rb"].each do |file|
|
46
|
+
options.components << file
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on("-f CONFIG", "--config CONFIG",
|
51
|
+
"Read a config file") do |v|
|
52
|
+
options.configs << v
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-o LOGFILE", "--log LOGFILE", "Logfile to write to") do |v|
|
56
|
+
options.logfile = v
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("-p PIDFILE", "--pidfile PIDFILE", "Pid file to write") do |v|
|
60
|
+
options.pidfile = v
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
parser.parse!
|
65
|
+
|
66
|
+
merbdir = "#{File::dirname(__FILE__)}/../"
|
67
|
+
Merb::Config.use do |c|
|
68
|
+
c[:host] = options.host
|
69
|
+
c[:port] = options.port
|
70
|
+
c[:adapter] = "mongrel"
|
71
|
+
c[:reload_classes] = false
|
72
|
+
c[:merb_root] = merbdir
|
73
|
+
c[:log_level] = :info
|
74
|
+
c[:name] = "slashport"
|
75
|
+
c[:environment] = nil
|
76
|
+
c[:exception_details] = true
|
77
|
+
c[:pid_file] = options.pidfile
|
78
|
+
|
79
|
+
if options.logfile == "-"
|
80
|
+
c[:log_stream] = STDOUT
|
81
|
+
c[:log_file] = nil
|
82
|
+
else
|
83
|
+
c[:log_file] = options.logfile
|
84
|
+
c[:log_stream] = nil
|
85
|
+
end
|
86
|
+
end # Merb::Config.use
|
87
|
+
|
88
|
+
Merb::BootLoader.after_app_loads do
|
89
|
+
options.components.each do |name|
|
90
|
+
require name
|
91
|
+
end
|
92
|
+
|
93
|
+
count = 0
|
94
|
+
options.configs.each do |name|
|
95
|
+
File.open(name).each do |line|
|
96
|
+
line.chomp!
|
97
|
+
puts "Config: #{line}"
|
98
|
+
next unless line =~ /^exec ([A-z0-9_-]+) ([A-z0-9_-]+) (.+)/
|
99
|
+
# format: exec <component> <section> <command ...>
|
100
|
+
|
101
|
+
component = $1
|
102
|
+
section = $2
|
103
|
+
cmd = $3
|
104
|
+
func = "#{component}_#{section}".tr("-", "_")
|
105
|
+
puts "Func: #{func}"
|
106
|
+
eval %{
|
107
|
+
module SlashPort
|
108
|
+
module ConfigGenerated
|
109
|
+
class #{component.upcase} < SlashPort::Component
|
110
|
+
attribute :name => "#{section}",
|
111
|
+
:handler => :#{func},
|
112
|
+
:doc => "#{func}"
|
113
|
+
|
114
|
+
def #{func}
|
115
|
+
return SlashPort::Exec.new("#{cmd}").to_tuple
|
116
|
+
end
|
117
|
+
end # class #{component.upcase}
|
118
|
+
end # module ConfigGenerated
|
119
|
+
end # module SlashPort
|
120
|
+
}
|
121
|
+
|
122
|
+
count += 1
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end # BootLoader.after_app_loads
|
126
|
+
|
127
|
+
puts "Starting server"
|
128
|
+
puts options.inspect
|
129
|
+
|
130
|
+
Merb.start(Merb::Config.to_hash)
|
data/bin/slashportfetch
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "json"
|
5
|
+
require "optparse"
|
6
|
+
require "ostruct"
|
7
|
+
require "net/http"
|
8
|
+
require "uri"
|
9
|
+
|
10
|
+
$: << "#{File::dirname(__FILE__)}/../lib"
|
11
|
+
require "slashport"
|
12
|
+
|
13
|
+
WARNING = 1
|
14
|
+
CRITICAL = 2
|
15
|
+
|
16
|
+
checks = []
|
17
|
+
ignores = []
|
18
|
+
options = OpenStruct.new
|
19
|
+
options.filters = []
|
20
|
+
options.port = 4000
|
21
|
+
options.empty_results_is_ok = false
|
22
|
+
argstr = ARGV.join(" ")
|
23
|
+
parser = OptionParser.new do |opts|
|
24
|
+
opts.banner = "Usage: #{$0} [options]"
|
25
|
+
opts.on("-f FILTER", "--filter FILTER", "Add a filter") do |v|
|
26
|
+
name, value = v.split("=", 2)
|
27
|
+
options.filters << [ name, value ]
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-i FILTER", "--ignore FILTER", "Ignore things matching a check") do |v|
|
31
|
+
check = SlashPort::Check.new_from_string(v)
|
32
|
+
if check == nil
|
33
|
+
puts "Invalid check #{v}"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
ignores << check
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-h HOST[:PORT]", "--host HOST[:PORT]", "Host to query") do |v|
|
40
|
+
host, port = v.split(":",2)
|
41
|
+
port ||= 4000
|
42
|
+
options.host = host
|
43
|
+
options.port = port
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-c CHECK", "--check CHECK", "Output if CHECK succeeds") do |v|
|
47
|
+
check = SlashPort::Check.new_from_string(v)
|
48
|
+
if check == nil
|
49
|
+
puts "Invalid check #{v}"
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
checks << check
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-r", "--empty-results-is-ok",
|
56
|
+
"Declare that having no matches to filters (after ignores are " \
|
57
|
+
"applied) is not an error") do |v|
|
58
|
+
options.empty_results_is_ok = true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
parser.parse!
|
62
|
+
|
63
|
+
if options.host == nil
|
64
|
+
puts "No --host specified."
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
exitcode = 0
|
69
|
+
fetcher = SlashPort::Fetcher.new(options.host, options.port)
|
70
|
+
options.filters.each do |filter|
|
71
|
+
fetcher.add_filter(*filter)
|
72
|
+
end
|
73
|
+
|
74
|
+
matches = 0
|
75
|
+
entries = 0
|
76
|
+
fetcher.fetch.each do |entry|
|
77
|
+
# Skip if this entry matches any ignores
|
78
|
+
next if ignores.select { |check| check.match?(entry) }.length > 0
|
79
|
+
entries += 1
|
80
|
+
|
81
|
+
if checks.length == 0
|
82
|
+
puts entry.inspect
|
83
|
+
matches += 1
|
84
|
+
end
|
85
|
+
|
86
|
+
checks.each do |check|
|
87
|
+
if check.match?(entry)
|
88
|
+
puts "#{check} matches #{entry.inspect}"
|
89
|
+
exitcode = CRITICAL
|
90
|
+
matches += 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if !options.empty_results_is_ok and entries == 0
|
96
|
+
puts "No entries found matching your filters, so there weren't any checks attempted."
|
97
|
+
puts "This is an error. If this is OK, then run with --empty-results-is-ok"
|
98
|
+
exitcode = CRITICAL
|
99
|
+
end
|
100
|
+
|
101
|
+
puts "#{matches} matches to #{$0} #{argstr}"
|
102
|
+
|
103
|
+
exit exitcode
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Merb.logger.info("Loaded DEVELOPMENT Environment...")
|
2
|
+
Merb::Config.use { |c|
|
3
|
+
c[:exception_details] = true
|
4
|
+
c[:reload_templates] = true
|
5
|
+
c[:reload_classes] = true
|
6
|
+
c[:reload_time] = 0.5
|
7
|
+
c[:ignore_tampered_cookies] = true
|
8
|
+
c[:log_auto_flush ] = true
|
9
|
+
c[:log_level] = :debug
|
10
|
+
|
11
|
+
c[:log_stream] = STDOUT
|
12
|
+
c[:log_file] = nil
|
13
|
+
# Or redirect logging into a file:
|
14
|
+
# c[:log_file] = Merb.root / "log" / "development.log"
|
15
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Merb.logger.info("Loaded PRODUCTION Environment...")
|
2
|
+
Merb::Config.use { |c|
|
3
|
+
c[:exception_details] = false
|
4
|
+
c[:reload_classes] = false
|
5
|
+
c[:log_level] = :error
|
6
|
+
|
7
|
+
c[:log_file] = Merb.root / "log" / "production.log"
|
8
|
+
# or redirect logger using IO handle
|
9
|
+
# c[:log_stream] = STDOUT
|
10
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Merb.logger.info("Loaded RAKE Environment...")
|
2
|
+
Merb::Config.use { |c|
|
3
|
+
c[:exception_details] = true
|
4
|
+
c[:reload_classes] = false
|
5
|
+
c[:log_auto_flush ] = true
|
6
|
+
|
7
|
+
c[:log_stream] = STDOUT
|
8
|
+
c[:log_file] = nil
|
9
|
+
# Or redirect logging into a file:
|
10
|
+
# c[:log_file] = Merb.root / "log" / "development.log"
|
11
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Merb.logger.info("Loaded STAGING Environment...")
|
2
|
+
Merb::Config.use { |c|
|
3
|
+
c[:exception_details] = false
|
4
|
+
c[:reload_classes] = false
|
5
|
+
c[:log_level] = :error
|
6
|
+
|
7
|
+
c[:log_file] = Merb.root / "log" / "staging.log"
|
8
|
+
# or redirect logger using IO handle
|
9
|
+
# c[:log_stream] = STDOUT
|
10
|
+
}
|