From 826b008fc0948f2c328413e0824b6504764a27a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 3 May 2017 18:24:57 +0200 Subject: [PATCH] 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) --- .../kosmos-parity/recipes/default.rb | 54 ------------------ .../kosmos-parity/recipes/node_dev.rb | 34 +++++++++++ .../kosmos-parity/recipes/node_mainnet.rb | 26 +++++++++ .../kosmos-parity/recipes/node_testnet.rb | 27 +++++++++ .../kosmos-parity/resources/node.rb | 56 ++++++++++++++++--- 5 files changed, 135 insertions(+), 62 deletions(-) create mode 100644 site-cookbooks/kosmos-parity/recipes/node_dev.rb create mode 100644 site-cookbooks/kosmos-parity/recipes/node_mainnet.rb create mode 100644 site-cookbooks/kosmos-parity/recipes/node_testnet.rb diff --git a/site-cookbooks/kosmos-parity/recipes/default.rb b/site-cookbooks/kosmos-parity/recipes/default.rb index d70226f..865440e 100644 --- a/site-cookbooks/kosmos-parity/recipes/default.rb +++ b/site-cookbooks/kosmos-parity/recipes/default.rb @@ -31,57 +31,3 @@ end dpkg_package "parity" do source parity_package_path end - -parity_node "dev" do - config parity: { - chain: "dev", - }, - network: { - port: 30303, - }, - rpc: { - port: 8545, - }, - dapps: { - port: 8090, - }, - ui: { - port: 8180, - } -end - -parity_node "testnet" do - config parity: { - chain: "ropsten", - }, - network: { - port: 30304, - }, - rpc: { - port: 8546, - }, - dapps: { - port: 8091, - }, - ui: { - port: 8181, - } -end - -parity_node "mainnet" do - config parity: { - chain: "homestead", - }, - network: { - port: 30305, - }, - rpc: { - port: 8547, - }, - dapps: { - port: 8092, - }, - ui: { - port: 8182, - } -end diff --git a/site-cookbooks/kosmos-parity/recipes/node_dev.rb b/site-cookbooks/kosmos-parity/recipes/node_dev.rb new file mode 100644 index 0000000..d05ddd2 --- /dev/null +++ b/site-cookbooks/kosmos-parity/recipes/node_dev.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: kosmos-parity +# Recipe:: node_dev +# +# Copyright 2017, Kosmos +# +# All rights reserved - Do Not Redistribute +# + +parity_node "dev" do + config parity: { + chain: "dev", + no_download: true, # Don't Download Updates + }, + network: { + port: 30303, + warp: true, + }, + rpc: { + port: 8545, + cors: "*", + }, + dapps: { + port: 8090, + }, + ui: { + port: 8180, + force: true, + }, + mining: { + reseal_min_period: 0, + } +end + diff --git a/site-cookbooks/kosmos-parity/recipes/node_mainnet.rb b/site-cookbooks/kosmos-parity/recipes/node_mainnet.rb new file mode 100644 index 0000000..1dbd33d --- /dev/null +++ b/site-cookbooks/kosmos-parity/recipes/node_mainnet.rb @@ -0,0 +1,26 @@ +# +# Cookbook Name:: kosmos-parity +# Recipe:: node_mainnet +# +# Copyright 2017, Kosmos +# +# All rights reserved - Do Not Redistribute +# + +parity_node "mainnet" do + config parity: { + chain: "homestead", + }, + network: { + port: 30305, + }, + rpc: { + port: 8547, + }, + dapps: { + port: 8092, + }, + ui: { + port: 8182, + } +end diff --git a/site-cookbooks/kosmos-parity/recipes/node_testnet.rb b/site-cookbooks/kosmos-parity/recipes/node_testnet.rb new file mode 100644 index 0000000..9fb08b0 --- /dev/null +++ b/site-cookbooks/kosmos-parity/recipes/node_testnet.rb @@ -0,0 +1,27 @@ +# +# Cookbook Name:: kosmos-parity +# Recipe:: node_testnet +# +# Copyright 2017, Kosmos +# +# All rights reserved - Do Not Redistribute +# + +parity_node "testnet" do + config parity: { + chain: "ropsten", + }, + network: { + port: 30304, + }, + rpc: { + port: 8546, + }, + dapps: { + port: 8091, + }, + ui: { + port: 8181, + } +end + diff --git a/site-cookbooks/kosmos-parity/resources/node.rb b/site-cookbooks/kosmos-parity/resources/node.rb index 8b6fb68..d7ac731 100644 --- a/site-cookbooks/kosmos-parity/resources/node.rb +++ b/site-cookbooks/kosmos-parity/resources/node.rb @@ -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