Split node config into separate recipes, support account creation
The account is automatically created and added to the list of accounts that are unlocked (can send without a password)
This commit is contained in:
@@ -6,10 +6,16 @@ property :name, String, name_property: true
|
||||
property :config, Hash
|
||||
|
||||
action :enable do
|
||||
node_name = name
|
||||
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
|
||||
@@ -25,12 +31,47 @@ action :enable do
|
||||
end
|
||||
end
|
||||
|
||||
config_file = "#{base_path}/config.toml"
|
||||
node_path = "#{node['kosmos-parity']['home_path']}/.local/share/io.parity.ethereum/dev"
|
||||
password_path = "#{node_path}/password"
|
||||
|
||||
file config_file do
|
||||
content TOML::Generator.new(config).body
|
||||
owner "parity"
|
||||
group "parity"
|
||||
file password_path do
|
||||
content "parityparity"
|
||||
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
|
||||
@@ -38,10 +79,9 @@ action :enable do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
parity_service = "parity_#{node_name}"
|
||||
template "/lib/systemd/system/#{parity_service}.service" do
|
||||
source "parity.systemd.service.erb"
|
||||
variables config_file: config_file
|
||||
variables config_file: config_path
|
||||
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
||||
notifies :restart, "service[#{parity_service}]", :delayed
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user