-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
65 lines (55 loc) · 1.5 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
58
59
60
61
62
63
64
65
#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
RSpec::Core::RakeTask.new
RuboCop::RakeTask.new
task default: :spec
#
# Tokyo Tyrant rake tasks
#
namespace :tyrant do
TYRANT_DB_FILE = File.join('tyrant.tct')
TYRANT_PID_FILE = File.join('tyrant.pid')
TYRANT_LOG_FILE = File.join('tyrant.log')
desc 'Start Tyrant server'
task :start do
fail RuntimeError, 'Tyrant is already running.' if tyrant_running?
system "ttserver -pid #{TYRANT_PID_FILE} -log #{TYRANT_LOG_FILE} #{TYRANT_DB_FILE}&"
sleep(2)
if tyrant_running?
puts "Tyrant started successfully (pid #{tyrant_pid})."
else
puts 'Failed to start tyrant push server. Check logs.'
end
end
desc 'Stop Tyrant server'
task :stop do
fail RuntimeError, "Tyrant isn't running." unless tyrant_running?
system "kill #{tyrant_pid}"
sleep(2)
if tyrant_running?
puts "Tyrant didn't stopped. Check the logs."
else
puts 'Tyrant stopped.'
end
end
desc 'Restart Tyrant server'
task restart: [:stop, :start]
desc 'Get Tyrant Server Status'
task :status do
puts tyrant_running? ? "Tyrant running. (#{tyrant_pid})" : 'Tyrant not running.'
end
end
def tyrant_pid
`cat #{TYRANT_PID_FILE}`.to_i
end
def tyrant_running?
return false unless File.exist?(TYRANT_PID_FILE)
process_check = `ps -p #{tyrant_pid} | wc -l`
if process_check.to_i < 2
puts 'Erasing pidfile...'
`rm #{TYRANT_PID_FILE}`
end
tyrant_pid
end