Greg Karékinian d0f2275ebb Fix the ipfs config
The whole thing was inconsistent and didn't work when creating a server
from scratch
2018-08-06 12:14:20 +02:00

27 lines
783 B
Ruby

require 'json'
require 'mixlib/shellout'
property :key, String, name_property: true
property :value, [String, Hash, Array, TrueClass, FalseClass], required: true
action :create do
include_recipe "ipfs"
execute "ipfs config --json #{key} '#{JSON.generate(value)}'" do
environment "IPFS_PATH" => "/home/ipfs/.ipfs"
user "ipfs"
not_if do
cmd = Mixlib::ShellOut.new("ipfs", "config", key,
user: 'ipfs',
env: { "IPFS_PATH" => "/home/ipfs/.ipfs" })
cmd.run_command
begin
JSON.parse(cmd.stdout) == JSON.parse(JSON.generate(value))
rescue JSON::ParserError
cmd.stdout.include?("#{value}")
end
end
notifies :restart, "service[ipfs]", :delayed
end
end