function dmn_stop($uname, $conf) { $testnet = $conf->getconfig('testnet') == 1; if ($testnet) { $testinfo = '/testnet3'; } else { $testinfo = ''; } $rpc = new \elbereth\EasyDash($conf->getconfig('rpcuser'), $conf->getconfig('rpcpassword'), 'localhost', $conf->getconfig('rpcport')); $pid = dmn_getpid($uname, $testnet); if ($pid !== false) { $tmp = $rpc->stop(); if ($rpc->response['result'] != "DarkCoin server stopping" && $rpc->response['result'] != "Dash server stopping" && $rpc->response['result'] != "Dash Core server stopping") { echo "Unexpected daemon answer (" . $rpc->response['result'] . ") "; } usleep(250000); $waitcount = 0; while (dmn_checkpid($pid) && $waitcount < DMN_STOPWAIT) { usleep(1000000); $waitcount++; echo "."; } if (dmn_checkpid($pid)) { echo "Soft Stop Failed! Forcing Kill... "; exec('kill -s kill ' . $pid); $waitcount = 0; while (dmn_checkpid($pid) && $waitcount < DMN_STOPWAIT) { echo '.'; usleep(1000000); $waitcount++; } if (dmn_checkpid($pid)) { echo "Failed!"; $res = false; } else { if (file_exists('/home/' . $uname . "/.darkcoin{$testinfo}/darkcoind.pid")) { unlink('/home/' . $uname . "/.darkcoin{$testinfo}/darkcoind.pid"); } if (file_exists('/home/' . $uname . "/.dash{$testinfo}/dashd.pid")) { unlink('/home/' . $uname . "/.dash{$testinfo}/dashd.pid"); } echo "OK (Killed) "; $res = true; } } else { echo " OK (Soft Stop) "; $res = true; } } else { echo "NOT started "; $res = true; } return $res; }
function dmn_getpids($nodes, $isstatus = false) { if ($isstatus) { if (file_exists(DMN_CTLSTATUSAUTO_SEMAPHORE) && posix_getpgid(intval(file_get_contents(DMN_CTLSTATUSAUTO_SEMAPHORE))) !== false) { xecho("Already running (PID " . sprintf('%d', file_get_contents(DMN_CTLSTATUSAUTO_SEMAPHORE)) . ")\n"); die(10); } file_put_contents(DMN_CTLSTATUSAUTO_SEMAPHORE, sprintf('%s', getmypid())); } $dmnpid = array(); foreach ($nodes as $uname => $node) { if (is_dir(DMN_PID_PATH . $uname)) { $conf = new DashConfig($uname); if ($conf->isConfigLoaded()) { if ($node['NodeTestNet'] != $conf->getconfig('testnet')) { xecho("{$uname}: Configuration inconsistency (testnet/" . $node['NodeTestNet'] . "/" . $conf->getconfig('testnet') . ")\n"); } if ($node['NodeEnabled'] != $conf->getmnctlconfig('enable')) { xecho("{$uname}: Configuration inconsistency (enable/" . $node['NodeEnabled'] . "/" . $conf->getmnctlconfig('enable') . ")\n"); } $pid = dmn_getpid($uname, $conf->getconfig('testnet') == '1'); $dmnpiditem = array('pid' => $pid, 'uname' => $uname, 'conf' => $conf, 'type' => $node['NodeType'], 'enabled' => $node['NodeEnabled'] == 1, 'testnet' => $node['NodeTestNet'] == 1, 'dashd' => $node['VersionPath'], 'currentbin' => '', 'keeprunning' => $node['KeepRunning'] == 1, 'keepuptodate' => $node['KeepUpToDate'] == 1, 'versionraw' => $node['VersionRaw'], 'versiondisplay' => $node['VersionDisplay'], 'versionhandling' => $node['VersionHandling']); if ($pid !== false) { if (file_exists('/proc/' . $pid . '/exe')) { $currentbin = readlink('/proc/' . $pid . '/exe'); $dmnpiditem['currentbin'] = $currentbin; if ($currentbin != $node['VersionPath']) { xecho("{$uname}: Binary mismatch ({$currentbin} != " . $node['VersionPath'] . ")"); /* if ($dmnpiditem['keepuptodate']) { echo " [Restarting to fix]\n"; dmn_startstop(array($dmnpiditem),"restart",($node['NodeTestNet'] == 1),$node['NodeType']); sleep(3); $pid = dmn_getpid($uname,($conf->getconfig('testnet') == '1')); $dmnpiditem['pid'] = $pid; if (($pid !== false) && (file_exists('/proc/'.$pid.'/exe'))) { $currentbin = readlink('/proc/'.$pid.'/exe'); $dmnpiditem['currentbin'] = $currentbin; if ($currentbin != $node['VersionPath']) { xecho("$uname: Binary mismatch ($currentbin != ".$node['VersionPath'].") [Restart failed, need admin]\n"); } } } else { */ echo " [Restart to fix]\n"; // } } } else { xecho("{$uname}: process ID {$pid} has no binary information (crashed?)\n"); } } else { xecho("{$uname}: process ID not found\n"); } $dmnpid[] = $dmnpiditem; } } } usort($dmnpid, "dmnpidcmp"); return $dmnpid; }