diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index e61fe0f..f87ed71 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -37,6 +37,17 @@ node.default['c-lightning']['public_ip'] = '148.251.237.73' node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' node.default['lnd']['revision'] = 'v0.11.1-beta' node.default['lnd']['source_dir'] = '/opt/lnd' +node.default['lnd']['lnd_dir'] = "/home/#{node['bitcoin']['username']}/.lnd" +node.default['lnd']['alias'] = 'ln4.kosmos.org' +node.default['lnd']['color'] = '#5e0c99' +node.default['lnd']['log_level'] = 'info' +node.default['lnd']['public_ip'] = '148.251.237.111' +node.default['lnd']['port'] = '9736' +node.default['lnd']['minchansize'] = '1000000' +node.default['lnd']['basefee'] = '500' +node.default['lnd']['feerate'] = '1' +# node.default['lnd']['rpclisten'] = '127.0.0.1:10002' +# node.default['lnd']['restlisten'] = '127.0.0.1:8002' node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index cb9f14d..1dd72e5 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -71,10 +71,10 @@ systemd_unit 'lightningd.service' do After: 'bitcoind.service' }, Service: { - User: node['bitcoin']['username'], - Group: node['bitcoin']['usergroup'], + User: bitcoin_user, + Group: bitcoin_group, Type: 'simple', - ExecStart: "/usr/local/bin/lightningd", + ExecStart: '/usr/local/bin/lightningd', Restart: 'always', RestartSec: '30', TimeoutSec: '240', diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index b730a8e..b114e49 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -6,11 +6,6 @@ include_recipe "git" include_recipe "golang" -# bitcoin_user = node['bitcoin']['username'] -# bitcoin_group = node['bitcoin']['usergroup'] -# bitcoin_datadir = node['bitcoin']['datadir'] -# bitcoin_conf_path = node['bitcoin']['conf_path'] - git node['lnd']['source_dir'] do repository node['lnd']['repo'] revision node['lnd']['revision'] @@ -26,3 +21,72 @@ bash "compile_lnd" do EOH action :nothing end + +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +lnd_dir = node['lnd']['lnd_dir'] + +bitcoin_credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') + +directory lnd_dir do + owner bitcoin_user + group bitcoin_group + mode '0750' + action :create +end + +template "#{lnd_dir}/lnd.conf" do + source "lnd.conf.erb" + owner bitcoin_user + group bitcoin_group + mode '0640' + variables lnd_alias: node['lnd']['alias'], + lnd_color: node['lnd']['color'], + lnd_log_level: node['lnd']['log_level'], + lnd_public_ip: node['lnd']['public_ip'], + lnd_port: node['lnd']['port'], + lnd_minchansize: node['lnd']['minchansize'], + lnd_basefee: node['lnd']['basefee'], + lnd_feerate: node['lnd']['feerate'], + bitcoin_datadir: node['bitcoin']['datadir'], + bitcoin_rpc_user: node['bitcoin']['conf']['rpcuser'], + bitcoin_rpc_password: bitcoin_credentials["rpcpassword"], + bitcoin_rpc_host: node['bitcoin']['conf']['rpcbind'], + bitcoin_zmqpubrawblock: node['bitcoin']['conf']['zmqpubrawblock'], + bitcoin_zmqpubrawtx: node['bitcoin']['conf']['zmqpubrawtx'] + notifies :restart, "systemd_unit[lnd.service]", :delayed +end + +systemd_unit 'lnd.service' do + content({ + Unit: { + Description: 'Lightning Network Daemon', + Documentation: ['https://github.com/lightningnetwork/lnd/tree/master/docs'], + Requires: 'bitcoind.service', + After: 'bitcoind.service' + }, + Service: { + User: bitcoin_user, + Group: bitcoin_group, + Type: 'simple', + ExecStart: '/opt/go/bin/lnd', + Restart: 'always', + RestartSec: '30', + TimeoutSec: '240', + LimitNOFILE: '128000', + RuntimeDirectory: 'lnd', # /run/lnd + RuntimeDirectoryMode: '0710', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true, + MemoryDenyWriteExecute: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] +end diff --git a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb new file mode 100644 index 0000000..ae9c29f --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb @@ -0,0 +1,28 @@ +[Application Options] +debuglevel=<%= @lnd_log_level %> +listen=0.0.0.0:<%= @lnd_port %> +; rpclisten=127.0.0.1:10002 +; restlisten=127.0.0.1:8002 +externalip=<%= @lnd_public_ip %>:<%= @lnd_port %> +alias=<%= @lnd_alias %> +color=<%= @lnd_color %> +maxpendingchannels=2 +minchansize=<%= @lnd_minchansize %> + +[autopilot] +autopilot.active=0 + +[Bitcoin] +bitcoin.active=1 +bitcoin.mainnet=1 +bitcoin.node=bitcoind +bitcoin.basefee=<%= @lnd_basefee %> +bitcoin.feerate=<%= @lnd_feerate %> + +[bitcoind] +bitcoind.dir=<%= @bitcoin_datadir %> +bitcoind.rpchost=<%= @bitcoin_rpc_host %> +bitcoind.rpcuser=<%= @bitcoin_rpc_user %> +bitcoind.rpcpass=<%= @bitcoin_rpc_password %> +bitcoind.zmqpubrawblock=<%= @bitcoin_zmqpubrawblock %> +bitcoind.zmqpubrawtx=<%= @bitcoin_zmqpubrawtx %>