Created
April 7, 2011 04:08
-
-
Save pier-oliviert/907021 to your computer and use it in GitHub Desktop.
Rakefile to launch/stop postgres process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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