basic pid file
This commit is contained in:
parent
3cabbcf5a4
commit
4e4e835bf5
2 changed files with 17 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
|||
* Serve purely static folders directly (without source/ and config.rb)
|
||||
* Set ignored files and disable directory_indexes from YAML frontmatter
|
||||
* Automatically load helper modules in helpers/ directory
|
||||
* Add pid for cleanup
|
||||
|
||||
2.0.14
|
||||
====
|
||||
|
|
|
@ -3,6 +3,8 @@ require "net/http"
|
|||
|
||||
require "win32/process" if ::Middleman::WINDOWS
|
||||
|
||||
require "fileutils"
|
||||
|
||||
module Middleman
|
||||
class Watcher
|
||||
class << self
|
||||
|
@ -63,12 +65,26 @@ module Middleman
|
|||
if @options[:"disable-watcher"]
|
||||
bootup
|
||||
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 {
|
||||
trap("INT") { exit(0) }
|
||||
trap("TERM") { exit(0) }
|
||||
trap("QUIT") { exit(0) }
|
||||
bootup
|
||||
}
|
||||
|
||||
File.open(pid_name, "w+") { |f| f.write(Process.getpgrp) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue