Added passenger_manager commands
This commit is contained in:
@@ -246,3 +246,52 @@ def hestia_read_config_with_lock(config_file)
|
||||
end
|
||||
arr
|
||||
end
|
||||
|
||||
def hestia_get_file_key_pair(file, key)
|
||||
value = ""
|
||||
if File.exist?(file)
|
||||
File.open(file, File::RDONLY) do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
f.each do |line|
|
||||
result = line.strip.split("=", 2)
|
||||
if result.length > 1
|
||||
k = result[0].strip
|
||||
v = result[1].strip
|
||||
if k == key
|
||||
value = v
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
def hestia_save_file_key_pair(file, key, value)
|
||||
File.open(file, File::RDWR | File::CREAT, 0600) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
f.rewind
|
||||
storage = {}
|
||||
f.each do |line|
|
||||
result = line.strip.split("=", 2)
|
||||
if result.length > 1
|
||||
k = result[0].strip
|
||||
v = result[1].strip
|
||||
storage[k] = v
|
||||
end
|
||||
end
|
||||
if value.strip == ""
|
||||
if storage.key?(key.strip)
|
||||
storage.delete(key.strip)
|
||||
end
|
||||
else
|
||||
storage[key.strip] = value.strip
|
||||
end
|
||||
f.rewind
|
||||
f.truncate(0)
|
||||
storage.each do |k, v|
|
||||
f.puts("#{k}=#{v}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user