-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.rb
50 lines (40 loc) · 899 Bytes
/
init.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
require 'rubygems'
require 'mongrel'
require 'thread'
require './lib/rss'
require './lib/get_site'
host = ARGV[0] || "127.0.0.1"
port = ARGV[1] || 80
docroot = ARGV[2] || "html/"
# Configure Mongrel and handlers
config = Mongrel::Configurator.new :host => host, :port => port do
listener do
redirect("/", "/rss")
uri "/", :handler => Mongrel::DirHandler.new(docroot)
uri "/rss", :handler => Makerss.new, :in_front => true
end
# CTRL+C to stop server
trap("INT") do
puts "server is going down..."
$server_on = false
stop
end
run
end
# Start Mongrel
puts "Mongrel listening on '#{host}:#{port}', serving documents from '#{docroot}'."
get = Getsite.new 1
get.crawl
t = Thread.new do
$server_on = true
start = Time.now
while $server_on do
if Time.now - start >= 3600
get.crawl
start = Time.now
end
sleep(10)
end
end
config.join
t.join