Skip to content

Commit

Permalink
Provision a miner
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Nov 10, 2023
1 parent 4e282ad commit 8b6de41
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
10 changes: 10 additions & 0 deletions compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
19 changes: 19 additions & 0 deletions miners.tf
Original file line number Diff line number Diff line change
@@ -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
}
62 changes: 62 additions & 0 deletions setup-miner.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >/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

0 comments on commit 8b6de41

Please sign in to comment.