Add a resource to handle config changes
This commit is contained in:
29
site-cookbooks/ipfs/resources/config.rb
Normal file
29
site-cookbooks/ipfs/resources/config.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
property :key, String, name_property: true
|
||||
property :value, [String, Hash, Array, TrueClass, FalseClass], default: nil, required: true
|
||||
|
||||
load_current_value do
|
||||
# some Ruby
|
||||
end
|
||||
|
||||
action :create do
|
||||
include_recipe "ipfs"
|
||||
|
||||
json_value = JSON.generate(value)
|
||||
execute "ipfs config --json #{key} #{json_value}" do
|
||||
environment "IPFS_PATH" => "/home/ipfs/.ipfs"
|
||||
user "ipfs"
|
||||
not_if do
|
||||
require 'json'
|
||||
require 'mixlib/shellout'
|
||||
cmd = Mixlib::ShellOut.new("ipfs", "config", key, user: 'ipfs',
|
||||
env: {"IPFS_PATH" => "/home/ipfs/.ipfs"})
|
||||
cmd.run_command
|
||||
begin
|
||||
JSON.parse(cmd.stdout) == value
|
||||
rescue JSON::ParserError
|
||||
cmd.stdout.include?(value)
|
||||
end
|
||||
end
|
||||
notifies :restart, "service[ipfs]", :delayed
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user