Add a resource to handle config changes

This commit is contained in:
Greg Karékinian 2017-03-20 19:38:12 +00:00
parent 48b3534fd8
commit 3f81310109
3 changed files with 46 additions and 14 deletions

View File

@ -11,7 +11,9 @@ It currently only supports 64bit platforms
### Chef ### Chef
- Chef 12.0 or later - Chef 12.5 or later (we are providing a
[https://docs.chef.io/custom_resources.html](Custom Resource) to configure
IPFS
### Cookbook dependencies ### Cookbook dependencies
@ -41,6 +43,18 @@ site (64bit)
connect to. This will stop platforms like Hetzner to block your server connect to. This will stop platforms like Hetzner to block your server
(https://github.com/ipfs/go-ipfs/issues/1226) (https://github.com/ipfs/go-ipfs/issues/1226)
## Resources
`ipfs_config` sets the config. Supports hashes, arrays, booleans and strings.
Does not change anything if the config already has that value, and restarts
the server automatically
```ruby
ipfs_config "Gateway.Writable" do
true
end
```
## License and Authors ## License and Authors
Authors: Kosmos Authors: Kosmos

View File

@ -73,17 +73,6 @@ else
end end
# Configure ipfs to not contact local network addresses # Configure ipfs to not contact local network addresses
execute "ipfs config --json Swarm.AddrFilters '#{node['ipfs']['config']['swarm']['addr_filter'].to_json}'" do ipfs_config "Swarm.AddrFilters" do
environment "IPFS_PATH" => "/home/ipfs/.ipfs" value node['ipfs']['config']['swarm']['addr_filter']
user "ipfs"
not_if do
require 'json'
swarm_filter_config = `su - ipfs -c "ipfs config Swarm.AddrFilters"`
begin
JSON.parse(swarm_filter_config) == node['ipfs']['config']['swarm']['addr_filter']
rescue JSON::ParserError
false
end
end
notifies :restart, "service[ipfs]", :delayed
end end

View 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