-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdora.rb
78 lines (61 loc) · 1.66 KB
/
dora.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
ENV['RACK_ENV'] ||= 'development'
require 'rubygems'
require 'sinatra/base'
require 'json'
ID = ((ENV["VCAP_APPLICATION"] && JSON.parse(ENV["VCAP_APPLICATION"])["instance_id"]) || SecureRandom.uuid).freeze
require "instances"
require "stress_testers"
require "log_utils"
require 'bundler'
Bundler.require :default, ENV['RACK_ENV'].to_sym
$stdout.sync = true
$stderr.sync = true
class Dora < Sinatra::Base
use Instances
use StressTesters
use LogUtils
get '/' do
# "Hi I'm Dora!"
'<html><body><img width="100%" src="http://www.chillestmonkey.com/img/monkey.gif" /></body></html>'
end
get '/find/:filename' do
`find / -name #{params[:filename]}`
end
get '/sigterm' do
"Available sigterms #{`man -k signal | grep list`}"
end
get '/delay/:seconds' do
sleep params[:seconds].to_i
"YAWN! Slept so well for #{params[:seconds].to_i} seconds"
end
get '/sigterm/:signal' do
pid = Process.pid
signal = params[:signal]
puts "Killing process #{pid} with signal #{signal}"
Process.kill(signal, pid)
end
get '/logspew/:bytes' do
system "cat /dev/urandom | head -c #{params[:bytes].to_i}"
"Just wrote #{params[:bytes]} random bytes to the log"
end
get '/echo/:destination/:output' do
redirect =
case params[:destination]
when "stdout"
""
when "stderr"
" 1>&2"
else
" > #{params[:destination]}"
end
system "echo '#{params[:output]}'#{redirect}"
"Printed '#{params[:output]}' to #{params[:destination]}!"
end
get '/env/:name' do
ENV[params[:name]]
end
get '/env' do
ENV.to_hash.to_s
end
run! if app_file == $0
end