Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Created April 7, 2011 04:08
Show Gist options
  • Select an option

  • Save pier-oliviert/907021 to your computer and use it in GitHub Desktop.

Select an option

Save pier-oliviert/907021 to your computer and use it in GitHub Desktop.
Rakefile to launch/stop postgres process
namespace :database do
task :start do
pid_file = File.open("#{Rails.root}/tmp/pids/postgres.pid", 'a+')
pid = pid_file.gets.to_i
begin
Process.kill('TERM', pid.to_i) unless pid.nil?
rescue
end
pid_file.truncate(0)
pid = IO.popen("postgres -D #{Rails.root}/db/postgresql/").pid
p "Database launched with PID: #{pid}"
pid_file.puts(pid)
pid_file.close
end
task :stop do
pid_file = File.open("#{Rails.root}/tmp/pids/postgres.pid", 'a+')
pid = pid_file.gets.to_i
unless pid.nil?
p "Killing process #{pid}"
begin
Process.kill('TERM', pid)
p "Process killed."
rescue
p "The process couldn't be killed."
ensure
end
end
end
task :restart => [:stop, :start] do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment