forked from adamwiggins/scanty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
56 lines (46 loc) · 1.01 KB
/
Rakefile
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
port = 3030
desc "Start the app server"
task :start => :stop do
puts "Starting the blog"
system "ruby main.rb -p #{port} > access.log 2>&1 &"
end
# code lifted from rush
def process_alive(pid)
::Process.kill(0, pid)
true
rescue Errno::ESRCH
false
end
def kill_process(pid)
::Process.kill('TERM', pid)
5.times do
return if !process_alive(pid)
sleep 0.5
::Process.kill('TERM', pid) rescue nil
end
::Process.kill('KILL', pid) rescue nil
rescue Errno::ESRCH
end
desc "Stop the app server"
task :stop do
m = `netstat -lptn | grep 0.0.0.0:#{port}`.match(/LISTEN\s*(\d+)/)
if m
pid = m[1].to_i
puts "Killing old server #{pid}"
kill_process(pid)
end
end
task :environment do
require 'sequel'
DB = Sequel.connect('sqlite://blog.db')
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')
require 'post'
end
task :import => :environment do
url = ENV['URL'] or raise "No url specified, use URL="
require 'rest_client'
posts = YAML.load RestClient.get(url)
posts.each do |post|
DB[:posts] << post
end
end