Class: Vagrant::Node::ServerAPI::PidFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-node/pidfile.rb

Class Method Summary collapse

Class Method Details

.create(pid_file, pid) ⇒ Object

FIXME en realidad no haría falta pasar el pid ya que se puede coger el del hilo en curso con el Process.pid



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-node/pidfile.rb', line 9

def self.create(pid_file,pid)

	#Check first if pid_file exists
	if File.exists?(pid_file)										
		#Check if the stored pid belongs to a 
		#running process
		pidold = open(pid_file, 'r').read.to_i
		if process_exist?(pidold)
			raise 'Process #{pidold} is still alive and running'  
		else						
			#If it is not alive then remove the file
			delete(pid_file)
		end
	end			   
    
	lock = open(pid_file, "w")
				lock.flock(File::LOCK_EX | File::LOCK_NB) || raise				
				lock.puts pid
				lock.flush
				lock.rewind
end

.delete(pid_file) ⇒ Object



31
32
33
# File 'lib/vagrant-node/pidfile.rb', line 31

def self.delete(pid_file)				
	File.delete pid_file
end