basic pid file
This commit is contained in:
parent
3cabbcf5a4
commit
4e4e835bf5
|
@ -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
|
||||||
====
|
====
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue