function dmn_restartfrozen($dmnpid)
{
    xecho("Dealing with ");
    echo count($dmnpid) . " frozen nodes:\n";
    $commands = array();
    $commands2 = array();
    foreach ($dmnpid as $nodenum => $node) {
        $uname = $node['uname'];
        if (file_exists("/tmp/dmnctl-NR-{$uname}-counter")) {
            $counter = intval(file_get_contents("/tmp/dmnctl-NR-{$uname}-counter"));
            $counter++;
        } else {
            $counter = 1;
        }
        xechoToFile(DMN_NRCOUNTLOG, "Unresponsive " . $uname . " counter " . $counter);
        if ($node["testnet"]) {
            $maxcount = DMN_NRCOUNT_TEST;
        } else {
            $maxcount = DMN_NRCOUNT;
        }
        if ($counter >= $maxcount) {
            unlink("/tmp/dmnctl-NR-{$uname}-counter", $counter);
            $commands[] = array("status" => 0, "nodenum" => $nodenum, "cmd" => "{$uname} stop " . $node['dashd'], "exitcode" => -1, "output" => '');
            if ($node["keeprunning"]) {
                $commands2[] = array("status" => 0, "nodenum" => $nodenum, "cmd" => "{$uname} start " . $node['dashd'], "exitcode" => -1, "output" => '');
                xechoToFile(DMN_NRCOUNTLOG, "Restarting unresponsive " . $uname);
            } else {
                xechoToFile(DMN_NRCOUNTLOG, "Stopping unresponsive " . $uname);
            }
        } else {
            file_put_contents("/tmp/dmnctl-NR-{$uname}-counter", $counter);
        }
    }
    dmn_ctlstartstop($commands);
    foreach ($commands as $command) {
        echo $command['output'];
    }
    if (count($commands2) > 0) {
        dmn_ctlstartstop($commands2);
        foreach ($commands2 as $command) {
            echo $command['output'];
        }
    }
}
function dmn_startstop($dmnpid, $todo, $testnet = false, $nodetype = 'masternode', $withreindex = false)
{
    $nodes = array();
    foreach ($dmnpid as $node) {
        if ($node['testnet'] == $testnet && $node['type'] == $nodetype) {
            $nodes[] = $node;
        }
    }
    if ($todo == 'start') {
        xecho("Starting ");
    } elseif ($todo == 'stop') {
        xecho("Stopping ");
    } elseif ($todo == 'restart') {
        xecho("Restarting ");
    } else {
        xecho("Unknown command {$todo}. Terminated.\n");
        die;
    }
    $extra = "";
    if ($withreindex) {
        echo "with -reindex ";
        $extra = " -reindex";
    }
    echo count($nodes) . " nodes:\n";
    $commands = array();
    foreach ($nodes as $nodenum => $node) {
        $uname = $node['uname'];
        $commands[] = array("status" => 0, "nodenum" => $nodenum, "cmd" => "{$uname} {$todo} " . $node['dashd'] . $extra, "exitcode" => -1, "output" => '');
    }
    dmn_ctlstartstop($commands);
    foreach ($commands as $command) {
        echo $command['output'];
    }
}