Add a resource to handle config changes
This commit is contained in:
parent
48b3534fd8
commit
3f81310109
@ -11,7 +11,9 @@ It currently only supports 64bit platforms
|
||||
|
||||
### 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
|
||||
|
||||
@ -41,6 +43,18 @@ site (64bit)
|
||||
connect to. This will stop platforms like Hetzner to block your server
|
||||
(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
|
||||
|
||||
Authors: Kosmos
|
||||
|
@ -73,17 +73,6 @@ else
|
||||
end
|
||||
|
||||
# Configure ipfs to not contact local network addresses
|
||||
execute "ipfs config --json Swarm.AddrFilters '#{node['ipfs']['config']['swarm']['addr_filter'].to_json}'" do
|
||||
environment "IPFS_PATH" => "/home/ipfs/.ipfs"
|
||||
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
|
||||
ipfs_config "Swarm.AddrFilters" do
|
||||
value node['ipfs']['config']['swarm']['addr_filter']
|
||||
end
|
||||
|
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
|
Loading…
x
Reference in New Issue
Block a user