forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
57 lines (46 loc) · 1.56 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
57
require_relative 'src/env'
SECONDS_TO_WAIT = 60
TIMES_TO_TRY = 5
def check_pidfile(pidfile, tries)
if File.exist?(pidfile)
oldpid = File.read(pidfile).to_i
# does that process exist?
ps = `ps -p #{oldpid} -o pid,start,etime,args`
exists = true
begin
Process.kill(0, oldpid) # signal is 0, meaning, no signal is sent, but error checking is still performed.
rescue Errno::ESRCH # Invalid pid
File.delete(pidfile)
exists = false
rescue ::Exception # for example on EPERM (process exists but does not belong to us)
exists = true
raise
end
if tries <= 0
raise StandardError.new("There can be only one #{pidfile} (#{oldpid}) on #{CDO.name} (#{rack_env}) \n#{ps}") if exists
else
puts "found a competing rake, waiting #{SECONDS_TO_WAIT}s"
sleep(SECONDS_TO_WAIT)
check_pidfile(pidfile, tries - 1)
end
end
end
def there_can_be_only_one(pidfile)
check_pidfile(pidfile, TIMES_TO_TRY)
File.open(pidfile, "w") {|f| f.puts $$}
at_exit {File.unlink(pidfile) if File.exist?(pidfile)}
end
there_can_be_only_one("#{File.basename(__FILE__)}.pid") unless ENV['PEGASUS_RAKE_RECURSIVE'].to_s.downcase == 'true'
if ENV['PEGASUS_RAKE_LOGGER'].to_s.downcase != 'true'
$log = Logger.new STDOUT
$log.level = Logger::INFO
end
require src_dir 'database'
Dir.glob(pegasus_dir('rake/*.rake')) {|path| load path}
namespace :pegasus do
task setup_db: ['db:ensure_created', 'db:migrate', 'seed:migrate'] do
end
end
task :default do
puts 'Use `rake --tasks` for a full list of pegasus rake tasks.'
end