The mainnet and testnet nodes use data from an encrypted data bag Also fix a bug with the resource (hardcoded "dev" name instead of the name attribute)
94 lines
2.5 KiB
Ruby
94 lines
2.5 KiB
Ruby
require 'toml'
|
|
|
|
provides :parity_node
|
|
|
|
property :name, String, name_property: true, required: true
|
|
property :config, Hash, required: true
|
|
property :password, String, required: true
|
|
|
|
action :enable do
|
|
include_recipe "kosmos-parity::default"
|
|
|
|
node_name = name
|
|
parity_service = "parity_#{node_name}"
|
|
base_path = "#{node['kosmos-parity']['home_path']}/.local/share/io.parity.ethereum/#{name}"
|
|
config_path = "#{base_path}/config.toml"
|
|
|
|
config[:parity][:base_path] = base_path
|
|
config[:account] = {}
|
|
config[:account][:password] = ["#{base_path}/password"]
|
|
|
|
directory base_path do
|
|
recursive true
|
|
owner "parity"
|
|
group "parity"
|
|
end
|
|
|
|
%w(chains keys).each do |subfolder|
|
|
directory "#{base_path}/#{subfolder}" do
|
|
recursive true
|
|
owner "parity"
|
|
group "parity"
|
|
end
|
|
end
|
|
|
|
node_path = "#{node['kosmos-parity']['home_path']}/.local/share/io.parity.ethereum/#{node_name}"
|
|
password_path = "#{node_path}/password"
|
|
|
|
file password_path do
|
|
content password
|
|
owner "parity"
|
|
group "parity"
|
|
mode 0640
|
|
end
|
|
|
|
ruby_block "generate config" do
|
|
block do
|
|
parity_account_list = Mixlib::ShellOut.new(
|
|
"parity account list --chain #{config[:parity][:chain]} --base-path #{base_path}",
|
|
user: "parity"
|
|
)
|
|
parity_account_list.run_command
|
|
|
|
parity_account = parity_account_list.stdout.strip.gsub(/[(\[|\])]/, '')
|
|
|
|
if parity_account.empty?
|
|
parity_account_create = Mixlib::ShellOut.new(
|
|
"parity account new --chain #{config[:parity][:chain]} --base-path #{base_path} --password #{base_path}/password",
|
|
user: "parity"
|
|
)
|
|
parity_account_create.run_command
|
|
|
|
parity_account = parity_account_create.stdout.strip
|
|
end
|
|
|
|
config[:account][:unlock] = [parity_account]
|
|
|
|
file "config" do
|
|
path config_path
|
|
content TOML::Generator.new(config).body
|
|
owner "parity"
|
|
group "parity"
|
|
mode 0640
|
|
notifies :restart, "service[#{parity_service}]", :delayed
|
|
end
|
|
end
|
|
end
|
|
|
|
execute "systemctl daemon-reload" do
|
|
command "systemctl daemon-reload"
|
|
action :nothing
|
|
end
|
|
|
|
template "/lib/systemd/system/#{parity_service}.service" do
|
|
source "parity.systemd.service.erb"
|
|
variables config_file: config_path
|
|
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
|
notifies :restart, "service[#{parity_service}]", :delayed
|
|
end
|
|
|
|
service parity_service do
|
|
action [:enable, :start]
|
|
end
|
|
end
|