114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/volume_visualizer/cli.rb', line 114
def instaweb
if false && (ENV["USER"] != "root") STDERR.puts <<-EOF
ERROR: Sorry. Instaweb mode requires root privileges, or requires
input data to parse. Try one of these:
sudo vv instaweb
or
sudo `vv show-command` > /tmp/data
vv instaweb --parse-file /tmp/data
EOF
exit 1
end
port = nil
begin
port = rand(20000) + 20000
server = WEBrick::HTTPServer.new(
:AccessLog => [],
:Port => port,
:Logger => WEBrick::Log::new("/dev/null", 7)
)
rescue Errno::EADDRINUSE
puts "ERROR: port #{port} already in use -- retrying"
retry
end
server.mount_proc "/" do |req, res|
res.body = File.open(html_source).read
end
zfs_data = zfs.to_json
server.mount_proc "/volviz.json" do |req, res|
res.body = zfs_data
end
trap 'INT' do
server.shutdown
end
STDERR.puts "server running on http://#{Socket.gethostname}:#{port}"
server.start
end
|