basic pid file

This commit is contained in:
Thomas Reynolds 2012-02-18 10:00:54 -08:00
parent 3cabbcf5a4
commit 4e4e835bf5
2 changed files with 17 additions and 0 deletions

View file

@ -25,6 +25,7 @@
* Serve purely static folders directly (without source/ and config.rb) * Serve purely static folders directly (without source/ and config.rb)
* Set ignored files and disable directory_indexes from YAML frontmatter * Set ignored files and disable directory_indexes from YAML frontmatter
* Automatically load helper modules in helpers/ directory * Automatically load helper modules in helpers/ directory
* Add pid for cleanup
2.0.14 2.0.14
==== ====

View file

@ -3,6 +3,8 @@ require "net/http"
require "win32/process" if ::Middleman::WINDOWS require "win32/process" if ::Middleman::WINDOWS
require "fileutils"
module Middleman module Middleman
class Watcher class Watcher
class << self class << self
@ -63,12 +65,26 @@ module Middleman
if @options[:"disable-watcher"] if @options[:"disable-watcher"]
bootup bootup
else else
pid_name = ".mm-pid-#{@options[:port]||4567}"
if File.exists?(pid_name)
current_pid = File.open(pid_name, 'rb') { |f| f.read }
begin
Process.kill("INT", -current_pid.to_i)
rescue
ensure
FileUtils.rm(pid_name)
end
end
@server_job = fork { @server_job = fork {
trap("INT") { exit(0) } trap("INT") { exit(0) }
trap("TERM") { exit(0) } trap("TERM") { exit(0) }
trap("QUIT") { exit(0) } trap("QUIT") { exit(0) }
bootup bootup
} }
File.open(pid_name, "w+") { |f| f.write(Process.getpgrp) }
end end
end end