Skip to content

@nofxx /tyrant.rake
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tokyo Tyrant rake tasks
#
# Tokyo Tyrant rake tasks
#
# rake tyrant:restart # Restart Tyrant server
# rake tyrant:start # Start Tyrant server
# rake tyrant:stop # Stop Tyrant server
#
namespace :tyrant do
desc "Start Tyrant server"
task :start do
raise 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
raise 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]
end
def tyrant_db_file
File.join(RAILS_ROOT, "db", "tyrant.tch")
end
def tyrant_pid_file
File.join(RAILS_ROOT, "tmp", "pids", "tyrant.pid")
end
def tyrant_log_file
File.join(RAILS_ROOT, "log", "tyrant.log")
end
def tyrant_pid
`cat #{tyrant_pid_file}`.to_i
end
def tyrant_running?
if File.exist?(tyrant_pid_file)
process_check = `ps -p #{tyrant_pid} | wc -l`
tyrant_pid && process_check.to_i > 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.