Skip to content

Commit

Permalink
Remote update of Miners via Dashboard (#4) (#239) (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendr0id authored Mar 11, 2022
1 parent 6324152 commit 12c9f4f
Show file tree
Hide file tree
Showing 29 changed files with 1,537 additions and 1,120 deletions.
157 changes: 80 additions & 77 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
'colvis',
{
text: '<i class="fa fa-upload"> Push miner config</i>',
className: 'btn-primary',
className: 'btn-info',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
Expand All @@ -242,7 +242,7 @@
},
{
text: '<i class="fa fa-download"> Pull miner config</i>',
className: 'btn-info',
className: 'btn-primary',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
Expand All @@ -254,73 +254,18 @@
}
},
{
text: '<i class="fa fa-play"> Start</i>',
className: 'btn-success',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("START", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-pause"> Pause</i>',
className: 'btn-warning',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("STOP", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-repeat"> Restart</i>',
className: 'btn-info',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("RESTART", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-sign-out"> Stop</i>',
text: '<i class="fa fa-recycle"> Update miner</i>',
className: 'btn-danger',
enabled: false,
action: function () {
$('#commandDialogStop').modal('show');
}
},
{
text: '<i class="fa fa-refresh"> Reboot</i>',
className: 'btn-warning',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("REBOOT", data.client_status.client_id);
sendAction("UPDATE", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-rocket"> Execute</i>',
className: 'btn-success',
enabled: false,
action: function () {
$('#commandExecuteDialog').modal('show');
}
},
{
text: '<i class="fa fa-table"> Assign template</i>',
className: 'btn-info',
Expand Down Expand Up @@ -391,6 +336,74 @@
}
});
}
},
{
text: '<i class="fa fa-play"> Start</i>',
className: 'btn-success',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("START", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-pause"> Pause</i>',
className: 'btn-warning',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("STOP", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-sign-out"> Stop</i>',
className: 'btn-danger',
enabled: false,
action: function () {
$('#commandDialogStop').modal('show');
}
},
{
text: '<i class="fa fa-repeat"> Restart</i>',
className: 'btn-info',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("RESTART", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-refresh"> Reboot</i>',
className: 'btn-danger',
enabled: false,
action: function () {
table.rows({selected: true}).eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();

sendAction("REBOOT", data.client_status.client_id);
});
}
},
{
text: '<i class="fa fa-rocket"> Execute</i>',
className: 'btn-primary',
enabled: false,
action: function () {
$('#commandExecuteDialog').modal('show');
}
}
],

Expand Down Expand Up @@ -521,29 +534,19 @@
table.on('select', function () {
var selectedRows = table.rows({selected: true}).count();

table.button(1).enable(selectedRows > 0);
table.button(2).enable(selectedRows > 0);
table.button(3).enable(selectedRows > 0);
table.button(4).enable(selectedRows > 0);
table.button(5).enable(selectedRows > 0);
table.button(6).enable(selectedRows > 0);
table.button(7).enable(selectedRows > 0);
table.button(8).enable(selectedRows > 0);
table.button(9).enable(selectedRows > 0);
for (var i=1; i < 11; i++)
{
table.button(i).enable(selectedRows > 0 || i === 5);
}
});

table.on('deselect', function () {
var selectedRows = table.rows({selected: true}).count();

table.button(1).enable(selectedRows > 0);
table.button(2).enable(selectedRows > 0);
table.button(3).enable(selectedRows > 0);
table.button(4).enable(selectedRows > 0);
table.button(5).enable(selectedRows > 0);
table.button(6).enable(selectedRows > 0);
table.button(7).enable(selectedRows > 0);
table.button(8).enable(selectedRows > 0);
table.button(9).enable(selectedRows > 0);
for (var i=1; i < 11; i++)
{
table.button(i).enable(selectedRows > 0 || i === 5);
}
});

table.buttons().container().appendTo('#clientStatusList_wrapper .col-sm-6:eq(0)');
Expand Down
18 changes: 10 additions & 8 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "core/config/Config.h"
#include "core/Controller.h"
#include "cc/ControlCommand.h"
#include "cc/XMRigd.h"
#include "Summary.h"
#include "version.h"

Expand Down Expand Up @@ -102,15 +103,15 @@ int xmrig::App::exec()
rc = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_loop_close(uv_default_loop());

return m_restart ? EINTR : rc;
return m_rc > 0 ? m_rc : rc;
}


void xmrig::App::onConsoleCommand(char command)
{
if (command == 3) {
LOG_WARN("%s " YELLOW("Ctrl+C received, exiting"), Tags::signal());
close(false);
close(RC_OK);
}
else {
m_controller->execCommand(command);
Expand All @@ -125,7 +126,7 @@ void xmrig::App::onSignal(int signum)
case SIGHUP:
case SIGTERM:
case SIGINT:
return close(false);
return close(RC_OK);

default:
break;
Expand All @@ -143,11 +144,12 @@ void xmrig::App::onCommandReceived(ControlCommand& command)
case ControlCommand::STOP:
m_controller->execCommand('p');
break;
case ControlCommand::UPDATE:
case ControlCommand::RESTART:
close(true);
close(RC_RESTART);
break;
case ControlCommand::SHUTDOWN:
close(false);
close(RC_OK);
break;
case ControlCommand::REBOOT:
reboot();
Expand All @@ -163,9 +165,9 @@ void xmrig::App::onCommandReceived(ControlCommand& command)
}


void xmrig::App::close(bool restart)
void xmrig::App::close(int rc)
{
m_restart = restart;
m_rc = rc;

m_controller->stop();
m_controller.reset();
Expand All @@ -186,7 +188,7 @@ void xmrig::App::reboot()
auto rebootCmd = m_controller->config()->ccClient().rebootCmd();
if (rebootCmd) {
system(rebootCmd);
close(false);
close(RC_OK);
}
# else
LOG_EMERG("Shell execute disabled. Skipping REBOOT.");
Expand Down
5 changes: 3 additions & 2 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "base/cc/interfaces/ICommandListener.h"
#include "base/tools/Object.h"
#include "cc/ControlCommand.h"
#include "cc/XMRigd.h"

#if XMRIG_FEATURE_CC_CLIENT
#include "cc/CCClient.h"
Expand Down Expand Up @@ -67,14 +68,14 @@ class App : public IConsoleListener, public ISignalListener, public ICommandList

private:
bool background(int &rc);
void close(bool restart);
void close(int rc);

# ifdef XMRIG_FEATURE_CC_CLIENT
void reboot();
void execute(const std::string& command);
# endif

bool m_restart = false;
int m_rc {RC_OK};

std::shared_ptr<Console> m_console;
std::shared_ptr<Controller> m_controller;
Expand Down
3 changes: 3 additions & 0 deletions src/base/kernel/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
namespace xmrig {

String Platform::m_userAgent;
String Platform::m_updatePath;

thread_local int64_t Platform::m_threadTimeToSleep = {0};
thread_local int64_t Platform::m_threadUsageTime = {0};
Expand All @@ -58,4 +59,6 @@ void xmrig::Platform::init(const char *userAgent)
else {
m_userAgent = createUserAgent();
}

m_updatePath = createUpdatePath();
}
3 changes: 3 additions & 0 deletions src/base/kernel/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ class Platform

static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
static inline const String &userAgent() { return m_userAgent; }
static inline const String &updatePath() { return m_updatePath; }

static bool isOnBatteryPower();
static uint64_t idleTime();

private:
static char *createUserAgent();
static char *createUpdatePath();

static String m_userAgent;
static String m_updatePath;

static thread_local int64_t m_threadTimeToSleep;
static thread_local int64_t m_threadUsageTime;
Expand Down
2 changes: 1 addition & 1 deletion src/base/kernel/Platform_hwloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#ifndef XMRIG_OS_APPLE
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(cpu_id));

if (pu == nullptr) {
Expand Down
20 changes: 20 additions & 0 deletions src/base/kernel/Platform_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ char *xmrig::Platform::createUserAgent()
}


char *xmrig::Platform::createUpdatePath()
{
constexpr const size_t max = 256;

char *buf = new char[max]();

int length = snprintf(buf, max, "macos");

# ifdef XMRIG_ARM
length += snprintf(buf + length, max - length, "-arm64");
# else
length += snprintf(buf + length, max - length, "-x64_64");
# endif

snprintf(buf + length, max - length, "/xmrigMiner");

return buf;
}


bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
return true;
Expand Down
Loading

0 comments on commit 12c9f4f

Please sign in to comment.