Class: Guard::Processing::ProcessController
- Inherits:
-
Object
- Object
- Guard::Processing::ProcessController
- Defined in:
- lib/guard/processing.rb
Instance Method Summary collapse
-
#initialize(pid_dir, path) ⇒ ProcessController
constructor
A new instance of ProcessController.
- #kill ⇒ Object
- #pid ⇒ Object
- #pid_file_path ⇒ Object
- #run(command) ⇒ Object
- #save(pid) ⇒ Object
- #spawn(command) ⇒ Object
Constructor Details
#initialize(pid_dir, path) ⇒ ProcessController
Returns a new instance of ProcessController.
23 24 25 26 |
# File 'lib/guard/processing.rb', line 23 def initialize(pid_dir, path) @pid_dir = pid_dir @path = path end |
Instance Method Details
#kill ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/guard/processing.rb', line 38 def kill if pid begin Process.kill('KILL', -Process.getpgid(pid)) rescue Errno::ESRCH # Process does not exist ensure File.delete(pid_file_path) end end end |
#pid ⇒ Object
32 33 34 35 36 |
# File 'lib/guard/processing.rb', line 32 def pid if File.exists?(pid_file_path) File.read(pid_file_path).to_i end end |
#pid_file_path ⇒ Object
28 29 30 |
# File 'lib/guard/processing.rb', line 28 def pid_file_path @pid_fiie_path ||= File.join(@pid_dir, @path.basename) end |
#run(command) ⇒ Object
58 59 60 61 62 |
# File 'lib/guard/processing.rb', line 58 def run(command) kill pid = spawn(command) save(pid) end |
#save(pid) ⇒ Object
50 51 52 |
# File 'lib/guard/processing.rb', line 50 def save(pid) open(pid_file_path, 'w') {|f| f.print Process.getpgid(pid) } end |
#spawn(command) ⇒ Object
54 55 56 |
# File 'lib/guard/processing.rb', line 54 def spawn(command) Process.spawn({}, command, :pgroup => true) end |