From 8b6de41be6559243332ba13970f7504ada539cef Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Fri, 10 Nov 2023 21:47:14 +0000 Subject: [PATCH] Provision a miner --- compute.tf | 10 ++++++++ miners.tf | 19 ++++++++++++++++ setup-miner.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 miners.tf create mode 100644 setup-miner.sh diff --git a/compute.tf b/compute.tf index bcfe4d5..1f87a75 100644 --- a/compute.tf +++ b/compute.tf @@ -44,6 +44,16 @@ resource "openstack_networking_secgroup_rule_v2" "inbound_ipv6_p2pmini_p2p" { security_group_id = openstack_networking_secgroup_v2.p2pool_mini.id } +resource "openstack_networking_secgroup_rule_v2" "inbound_ipv4_stratum" { + direction = "ingress" + ethertype = "IPv4" + protocol = "tcp" + port_range_min = 3333 + port_range_max = 3333 + remote_group_id = openstack_networking_secgroup_v2.xmrig.id + security_group_id = openstack_networking_secgroup_v2.p2pool_mini.id +} + # monerod needs <1GiB to run once synced, but >2GiB to sync # from scratch. P2Pool needs 2.6 GiB RAM to run properly. resource "openstack_compute_instance_v2" "p2pool_node" { diff --git a/miners.tf b/miners.tf new file mode 100644 index 0000000..180b719 --- /dev/null +++ b/miners.tf @@ -0,0 +1,19 @@ +resource "openstack_networking_secgroup_v2" "xmrig" { + name = "xmrig" + description = "Security group for XMRig nodes" +} + +resource "openstack_compute_instance_v2" "miner1" { + name = "miner1" + key_pair = openstack_compute_keypair_v2.keypair.id + security_groups = ["default", "xmrig"] + flavor_name = "gp1.lightspeed" + image_name = "Ubuntu-22.04" + user_data = file("setup-miner.sh") +} + +resource "dreamhost_dns_record" "miner1" { + record = "miner1.gbenson.net" + type = "A" + value = openstack_compute_instance_v2.miner1.access_ip_v4 +} diff --git a/setup-miner.sh b/setup-miner.sh new file mode 100644 index 0000000..579f802 --- /dev/null +++ b/setup-miner.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +export PS4='setup-miner.sh: ' +set -ex + +name=xmrig +version=6.20.0 +package=$name-$version +arch=linux-static-x64 +tarball=$package-$arch.tar.gz +download=https://github.com/xmrig/$name/releases/download +hash=ff6e67d725ee64b4607dc6490a706dc9234c708cff814477de52d3beb781c6a1 + +if [ -d /opt/xmrig ]; then + SKIP_SETUP=yes +else + for snap in lxd core20 snapd; do + snap remove $snap + done + systemctl stop snapd.{service,socket} snapd.{seeded,apparmor}.service + apt-get autoremove -y --purge snapd + rm -rf /root/snap + + apt-get autoremove -y --purge modemmanager + + #apt-get update + #apt-get upgrade -y + #apt-get dist-upgrade -y +fi + +mkdir -p /opt/xmrig/bin && cd /opt/xmrig +curl -Lo $tarball $download/v$version/$tarball +echo $hash $tarball > $tarball.SHA256SUM +sha256sum -c $tarball.SHA256SUM +tar xf $tarball +mv $name-$version $version +cd $version +sha256sum -c SHA256SUMS +ln -sf $(pwd)/xmrig /opt/xmrig/bin + +if [ ! -f /lib/systemd/system/xmrig.service ]; then + cat </lib/systemd/system/xmrig.service +[Unit] +Description=XMRig Monero miner +Documentation=https://github.com/gbenson/monero-node +After=network.target + +[Service] +Type=simple +ExecStart=/opt/xmrig/bin/xmrig -o p2pool.gbenson.net:3333 +Restart=always +RestartSec=30s + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable xmrig +fi + +[ -n "$SKIP_SETUP" ] || reboot