WIP install-v2

This commit is contained in:
Michele Marcucci 2024-01-27 10:16:00 +01:00
parent 07bc3747d5
commit feca08e75c
14 changed files with 1365 additions and 2457 deletions

5
.gitignore vendored
View File

@ -30,6 +30,9 @@ bower_components
# node-waf configuration
.lock-wscript
# Dev files
dev-*.js
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/
@ -56,7 +59,7 @@ typings/
.yarn-integrity
# dotenv environment variables file
.env
.env*.local
# next.js build output
.next

3
.gitmodules vendored
View File

@ -0,0 +1,3 @@
[submodule "apolloui-v2"]
path = apolloui-v2
url = git@github.com:jstefanop/apolloui-v2.git

2
.nvmrc
View File

@ -1 +1 @@
14
21

1
apolloui-v2 Submodule

@ -0,0 +1 @@
Subproject commit 5ee3a36ea30bbc1b23091d3f35cea04f6c41096f

View File

@ -2,6 +2,6 @@
iptables -A INPUT -p tcp --dport 80 -j ACCEPT && \
iptables -A INPUT -p tcp --dport 5000 -j ACCEPT && \
iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 5000
iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 3000
iptables -A INPUT -p tcp --dport 8333 -j ACCEPT
iptables -A INPUT -p udp --dport 8333 -j ACCEPT

118
backend/install-v2 Normal file
View File

@ -0,0 +1,118 @@
#!/bin/bash
# Install Ubuntu packages needed
sudo apt-get update
sudo apt-get install build-essential yasm libzmq3-dev
echo "Ubuntu packages installed."
# Define the NVM_DIR variable
NVM_DIR_LINE='export NVM_DIR="/usr/local/nvm"'
# Define the NVM sourcing line
NVM_SOURCE_LINE='[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'
# Add the lines to the user's ~/.bashrc file
echo "$NVM_DIR_LINE" >> ~/.bashrc
echo "$NVM_SOURCE_LINE" >> ~/.bashrc
echo "Lines added to ~/.bashrc."
# Enable nvm for the current shell session
eval "$NVM_DIR_LINE"
eval "$NVM_SOURCE_LINE"
# Change ownership of /usr/local/nvm to user "futurebit"
sudo chown -R futurebit /usr/local/nvm
echo "Changed ownership of /usr/local/nvm to futurebit."
# Install Node.js version 21 using nvm
nvm install 21.6.1
echo "Node.js version 21 installed."
# Clone the Git repository into /opt/apolloapi
sudo git clone -b dev git@github.com:jstefanop/apolloapi-v2.git /opt/apolloapi
# Clone the Git repository into /opt/apolloapi/apolloui-v2
sudo git clone -b dev git@github.com:jstefanop/apolloui-v2.git /opt/apolloapi/apolloui-v2
echo "Git repository cloned into /opt/apolloapi."
# Change ownership of apolloui-v2 to user "futurebit"
sudo chown -R futurebit /opt/apolloapi
echo "Changed ownership of /opt/apolloapi to futurebit."
# Install yarn globally
nvm use 21.6.1
npm i -g yarn
echo "Yarn installed globally."
# Navigate to the /opt/apolloapi directory
cd /opt/apolloapi/apolloui-v2
# Generate a random string for NEXTAUTH_SECRET
NEXTAUTH_SECRET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
# Create the .env file with the specified content
echo "NEXT_PUBLIC_POLLING_TIME=5000" >> .env
echo "NEXT_PUBLIC_POLLING_TIME_NODE=30000" >> .env
echo "NEXTAUTH_SECRET='$NEXTAUTH_SECRET'" >> .env
echo ".env file created with random NEXTAUTH_SECRET."
# Install project dependencies using yarn
yarn
echo "Project dependencies installed using yarn."
# Build the project
yarn build
echo "Project built using yarn."
# Remove the existing iptables rule
sudo iptables -D PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 5000
echo "Removed existing iptables rule."
# Add a new iptables rule
sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-port 3000
echo "Added new iptables rule."
##### TODO #####
# Pull API updates from TEMP branch dev-BTC
cd /opt/apolloapi
git checkout -b dev-BTC
git pull origin dev-BTC
# Rename apollo-ui.service to apollo-api.service
sudo systemctl stop apollo-ui.service
sudo systemctl disable apollo-ui.service
sudo cp /opt/apolloapi/backend/systemd/apollo-api.service /etc/systemd/system/
echo "Renamed apollo-ui.service to apollo-api.service."
# Copy the apollo.service file to /etc/systemd/system
sudo cp /opt/apolloapi/backend/systemd/apollo-ui-v2.service /etc/systemd/system/
# Copy the ckpool.service file to /etc/systemd/system
sudo cp /opt/apolloapi/backend/systemd/ckpool.service /etc/systemd/system/
echo "Copied apollo.service and ckpool.service to /etc/systemd/system."
# Reload systemd daemon to recognize the new service
sudo systemctl daemon-reload
echo "Reloaded systemd daemon."
# Stop and disable the apollo-ui.service and ckpool.service
sudo systemctl enable apollo-api.service
sudo systemctl enable ckpool.service
sudo systemctl start apollo-api.service
echo "Restart apollo-api.service."
# Enable and start the apollo-ui-v2.service
sudo systemctl enable apollo-ui-v2.service
sudo systemctl start apollo-ui-v2.service
echo "Enabled and started apollo-ui-v2.service."
echo "Installation complete."

View File

@ -1,241 +0,0 @@
const fs = require('fs');
const moment = require('moment');
function getData() {
const hashrate = getRandomFloat(3700, 4000).toFixed(1);
return {
"date": moment().format('YYYY-MM-DD HH:mm:ss'), //"2021-01-26 15:54:19"
"statVersion": "1.2",
"versions": {
"miner": "v13.16.1",
"minerDate": "2019-08-08",
"minerDebug": "0",
"mspVer": "0xd163"
},
"master": {
"upTime": 591230,
"diff": getRandomArbitrary(4000, 4500),
"boards": 1,
"errorSpi": 0,
"osc": 62,
"hwAddr": "00:00:00:00:00:00",
"boardsI": "32.7",
"boardsW": "277.0",
"wattPerGHs": "0.073",
"intervals": {
"30": {
"name": "30 sec",
"interval": 10,
"bySol": "4118.9",
"byDiff": "7715.5",
"byPool": "7715.5",
"byJobs": "4198.6",
"solutions": "9590",
"errors": "107",
"errorRate": "1.1",
"chipSpeed": "93.61",
"chipRestarts": "0"
},
"300": {
"name": "5 min",
"interval": 103,
"bySol": "3804.5",
"byDiff": "4307.2",
"byPool": "3932.7",
"byJobs": "3883.1",
"solutions": "91237",
"errors": "1155",
"errorRate": "1.3",
"chipSpeed": "86.47",
"chipRestarts": "44"
},
"900": {
"name": "15 min",
"interval": 309,
"bySol": "3786.6",
"byDiff": "4244.8",
"byPool": "4057.5",
"byJobs": "3852.0",
"solutions": "272427",
"errors": "3320",
"errorRate": "1.2",
"chipSpeed": "86.06",
"chipRestarts": "132"
},
"3600": {
"name": "1 hour",
"interval": 1234,
"bySol": "3795.0",
"byDiff": "3751.5",
"byPool": "3657.7",
"byJobs": "3853.4",
"solutions": "1090341",
"errors": "13839",
"errorRate": "1.3",
"chipSpeed": "86.25",
"chipRestarts": "528"
},
"0": {
"name": "total",
"interval": 591202,
"bySol": hashrate,
"byDiff": "3799.1",
"byPool": "3750.3",
"byJobs": "3852.6",
"solutions": "522341986",
"errors": "6728977",
"errorRate": "1.3",
"chipSpeed": "86.24",
"chipRestarts": "254952"
}
}
},
"pool": {
"host": "us-east.stratum.slushpool.com",
"port": "3333",
"userName": "jstefanop.worker1",
"diff": 4491,
"intervals": {
"0": {
"name": "total",
"interval": 591202,
"jobs": 21681,
"cleanFlags": 1040,
"sharesSent": getRandomArbitrary(4000, 45000),
"sharesAccepted": 121988,
"sharesRejected": 89,
"solutionsAccepted": "516223196",
"minRespTime": "18446743115130962",
"avgRespTime": "150444149418",
"maxRespTime": "18446743706350111",
"shareLoss": "0.000000",
"poolTotal": 591202,
"inService": 591202,
"subscribeError": 0,
"diffChanges": 46,
"reconnections": 0,
"reconnectionsOnErrors": 0,
"defaultJobShares": 0,
"staleJobShares": 565,
"duplicateShares": 0,
"lowDifficultyShares": 1,
"pwcSharesSent": 123591,
"pwcSharesDropped": 0,
"bigDiffShares": 0,
"belowTargetShare": 0,
"pwcRestart": 0,
"statOverflow": 0
}
}
},
"fans": {
"0": {
"rpm": [
3720
]
}
},
"temperature": {
"count": 2,
"min": 0,
"avr": 34,
"max": 69
},
"slots": {
"0": {
"revision": 20,
"spiNum": 1,
"spiLen": 4,
"pwrNum": 2,
"pwrLen": 2,
"btcNum": 11,
"specVoltage": 12,
"chips": 44,
"pwrOn": 1,
"pwrOnTarget": 1,
"revAdc": 4007,
"temperature": 69,
"temperature1": 0,
"ocp": 0,
"heaterErr": 0,
"heaterErrNum": 0,
"inOHOsc": 0,
"ohOscNum": 0,
"ohOscTime": 0,
"overheats": 0,
"overheatsTime": 0,
"lowCurrRst": 0,
"currents": [
16325,
16333
],
"brokenPwc": 0,
"solutions": "9590",
"errors": "107",
"ghs": hashrate,
"errorRate": "1.1",
"chipRestarts": "0",
"wattPerGHs": "0.067251",
"tmpAlert": [
{
"alertLo": 0,
"alertHi": 0,
"numWrite": 0
},
{
"alertLo": 0,
"alertHi": 0,
"numWrite": 0
}
],
"osc": 62,
"oscStopChip": "N/A"
}
},
"slaves": [
{
"id": 0,
"uid": "4A003D0008504E3943303320",
"ver": "0x13160100",
"rx": 1022976,
"err": 0,
"time": 582575,
"ping": 854
}
],
"slavePingMin": 854,
"slavePingMax": 854,
"slavePingAvg": 854
}
}
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomFloat(min, max) {
return parseFloat(Math.random() * (max - min) + min);
}
class Server {
constructor(port, address) {
this.init();
}
init() {
setInterval(() => {
const data = JSON.stringify(getData(), null, 4);
fs.writeFile('backend/apollo-miner/apollo-miner.12A2C9', data, function (err) {
if (err) console.log(err)
console.log('Writing stat file')
const data2 = JSON.stringify(getData(), null, 4);
fs.writeFile('backend/apollo-miner/apollo-miner.FC614E3E', data2, function (err) {
if (err) console.log(err)
console.log('Writing stat file')
});
});
}, 3000)
}
}
new Server();

View File

@ -1,9 +0,0 @@
const jwt = require('jsonwebtoken')
const config = require('config')
const accessToken = jwt.sign({}, config.get('server.secret'), {
subject: 'apollouser',
audience: 'auth'
})
console.log(accessToken)

View File

@ -1,227 +0,0 @@
'use strict';
function getData() {
return {
"summary": [
{
"STATUS": [
{
"STATUS": "S",
"When": 1541144892,
"Code": 11,
"Msg": "Summary",
"Description": "bfgminer 5.4.2"
}
],
"SUMMARY": [
{
"Elapsed": 847,
"MHS av": getRandomFloat(3.00, 4.00),
"MHS 20s": 3.324,
"Found Blocks": 0,
"Getworks": 30,
"Accepted": 168,
"Rejected": 0,
"Hardware Errors": 2,
"Utility": 11.9,
"Discarded": 78,
"Stale": 0,
"Get Failures": 0,
"Local Work": 138,
"Remote Failures": 0,
"Network Blocks": 5,
"Total MH": 2849.3488,
"Diff1 Work": 0.67822266,
"Work Utility": 0.048,
"Difficulty Accepted": 0.65625,
"Difficulty Rejected": 0,
"Difficulty Stale": 0,
"Best Share": 1.03726997,
"Device Hardware%": 0.1438,
"Device Rejected%": 0,
"Pool Rejected%": 0,
"Pool Stale%": 0,
"Last getwork": 1541144888
}
],
"id": 1
}
],
"devs": [
{
"STATUS": [
{
"STATUS": "S",
"When": 1541144892,
"Code": 9,
"Msg": "1 PGA(s)",
"Description": "bfgminer 5.4.2"
}
],
"DEVS": [
{
"PGA": 0,
"Name": "MLD",
"ID": 0,
"Enabled": "Y",
"Status": "Alive",
"Device Elapsed": 847,
"MHS av": 3.363,
"MHS 20s": 3.373,
"MHS rolling": 3.373,
"Accepted": 168,
"Rejected": 0,
"Hardware Errors": 2,
"Utility": 11.897,
"Stale": 0,
"Last Share Pool": 1,
"Last Share Time": 1541144887,
"Total MH": 2849.3488,
"Diff1 Work": 0.67822266,
"Work Utility": 0.048,
"Difficulty Accepted": 0.65625,
"Difficulty Rejected": 0,
"Difficulty Stale": 0,
"Last Share Difficulty": 0.00390625,
"Last Valid Work": 1541144891,
"Device Hardware%": 0.1438,
"Device Rejected%": 0
}
],
"id": 1
}
],
"pools": [
{
"STATUS": [
{
"STATUS": "S",
"When": 1541144892,
"Code": 7,
"Msg": "2 Pool(s)",
"Description": "bfgminer 5.4.2"
}
],
"POOLS": [
{
"POOL": 0,
"URL": "stratum+tcp://us.litecoinpool.org:3333",
"Status": "Alive",
"Priority": 1,
"Quota": 1,
"Mining Goal": "default",
"Long Poll": "N",
"Getworks": 3,
"Accepted": 0,
"Rejected": 0,
"Works": 0,
"Discarded": 0,
"Stale": 0,
"Get Failures": 0,
"Remote Failures": 0,
"User": "jstefanop.a1",
"Last Share Time": 0,
"Diff1 Shares": 0,
"Proxy": "",
"Difficulty Accepted": 0,
"Difficulty Rejected": 0,
"Difficulty Stale": 0,
"Last Share Difficulty": 0,
"Has Stratum": true,
"Stratum Active": true,
"Stratum URL": "",
"Best Share": 0,
"Pool Rejected%": 0,
"Pool Stale%": 0
},
{
"POOL": 1,
"URL": "stratum+tcp://us.litecoinpool.org:3333",
"Status": "Alive",
"Priority": 0,
"Quota": 99,
"Mining Goal": "default",
"Long Poll": "N",
"Getworks": 27,
"Accepted": 168,
"Rejected": 0,
"Works": 30,
"Discarded": 78,
"Stale": 0,
"Get Failures": 0,
"Remote Failures": 0,
"User": "jstefanop.1",
"Last Share Time": 1541144887,
"Diff1 Shares": 0.67822266,
"Proxy": "",
"Difficulty Accepted": 0.65625,
"Difficulty Rejected": 0,
"Difficulty Stale": 0,
"Last Share Difficulty": 0.00390625,
"Has Stratum": true,
"Stratum Active": true,
"Stratum URL": "us.litecoinpool.org",
"Best Share": 1.03726997,
"Pool Rejected%": 0,
"Pool Stale%": 0
}
],
"id": 1
}
],
"id": 1
}
}
const net = require('net');
const PORT = 4028;
const HOST = 'localhost';
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomFloat(min, max) {
return parseFloat(Math.random() * (max - min) + min);
}
class Server {
constructor(port, address) {
this.port = port || PORT;
this.address = address || HOST;
this.init();
}
init() {
let server = this;
let onClientConnected = (sock) => {
let clientName = `${sock.remoteAddress}:${sock.remotePort}`;
console.log(`new client connected: ${clientName}`);
sock.on('data', (data) => {
console.log(`${clientName} Says: ${data}`);
sock.write(JSON.stringify(getData()));
// sock.write('exit');
});
sock.on('close', () => {
console.log(`connection from ${clientName} closed`);
});
sock.on('error', (err) => {
console.log(`Connection ${clientName} error: ${err.message}`);
});
}
server.connection = net.createServer(onClientConnected);
server.connection.listen(PORT, HOST, function() {
console.log(`Server started at: ${HOST}:${PORT}`);
});
}
}
new Server();

View File

@ -15,24 +15,24 @@
"run-container": "docker run --rm -it -v \"$(pwd)\":/hostdir --entrypoint=/bin/bash orange"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^1.6.5",
"backend-helpers": "^0.5.0",
"backend-store": "^0.7.0",
"bcryptjs": "^2.4.3",
"config": "^2.0.1",
"diskusage": "^1.1",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"generate-password": "^1.7.0",
"ip": "^1.1.5",
"knex": "^0.95",
"config": "^3.3.10",
"diskusage": "^1.2.0",
"dotenv": "^16.3.2",
"express": "^4.18.2",
"generate-password": "^1.7.1",
"ip": "^1.1.8",
"knex": "^3.1.0",
"litecoin": "github:jstefanop/node-litecoin",
"luxon": "^1.26",
"normalize-object": "^2.0.3",
"sqlite3": "^5.0"
"luxon": "^3.4.4",
"normalize-object": "^2.0.6",
"sqlite3": "^5.1.7"
},
"devDependencies": {
"nodemon": "^1.18.5",
"pkg": "^4.3.4"
"nodemon": "^3.0.3",
"pkg": "^5.8.1"
}
}

3188
yarn.lock

File diff suppressed because it is too large Load Diff