Example #1
0
            echo "Server already running, checking if responding...\n";
            if (checkServer() === false) {
                echo "SERVER FAILED TO RESPOND!  #bad responses [{$bad_response}]\n";
                $bad_response++;
            } else {
                echo "Server responded with bin position {$bin_position}, last position {$last_bin_position}\n";
                $last_bin_position = $bin_position;
                if ($bad_response > 0) {
                    $bad_response--;
                }
            }
            if ($bad_response > 3) {
                $subject = "!! ALERT !! Socket Server {$_SERVER["HOSTNAME"]} is being restarted!";
                $message = "MORE THAN THREE BAD RESPONSES IN A ROW, RESTARTING SERVER!\n";
                echo $message;
                startServer();
                mailPeeps($subject, $message);
            }
        }
    }
    sleep(1);
}
function startServer()
{
    global $executable, $server_starting;
    $server_starting = true;
    exec("killall qserver");
    exec("killall curl");
    exec($executable);
}
function checkServer()
Example #2
0
<?php

include "databaseConnection/connection.php";
include "employeeSupportFunctions.php";
include "classes/employee.php";
include "classes/statusMessages.php";
startServer($HTTP_RAW_POST_DATA);
// ---------------------------------------- perform request
function perform($jsonObject)
{
    $action = $jsonObject->action;
    switch ($action) {
        case "load":
            return loadEmployee($jsonObject->id);
        case "blank":
            return loadBlank();
        case "save":
            return saveEmployee($jsonObject);
        case "create":
            return create($jsonObject);
        case "cut":
            return cut($jsonObject);
        case "delete":
            return delete($jsonObject);
    }
}
// ---------------------------------------- load blank
function loadBlank()
{
    // departments
    $departments = array();
<?php

namespace ViewComponents\TestingHelpers;

require_once __DIR__ . '/bootstrap.php';
startServer(getenv('WEB_SERVER_HOST'), getenv('WEB_SERVER_PORT'), getenv('WEB_SERVER_DOCROOT'), false);
Example #4
0
function runTest($testName, $testController)
{
    try {
        $serverPort = get_random_port();
        $adminPort = get_random_port();
        while ($adminPort === $serverPort) {
            $adminPort = get_random_port();
        }
        $debugPort = get_random_port();
        while ($debugPort === $serverPort || $debugPort === $adminPort) {
            $debugPort = get_random_port();
        }
        $pid = posix_getpid();
        $serverProc = null;
        $clientProcessId = 0;
        $serverProc = startServer($serverPort, $adminPort, $debugPort);
        waitForServerToGetGoing($serverPort);
        startDebuggerClient($debugPort, "/debugger/{$testName}.in", $pipes);
        $clientProcessId = getClientProcessId($pipes[1]);
        if (!$clientProcessId || ($clientProcessId = intval($clientProcessId)) <= 0) {
            tlog('Failed to communicate with the debugger client process');
            dumpLogFilesToStdoutAndDie();
        }
        tlog("Debugger client process id = {$clientProcessId}");
        $testController($pipes[1], $clientProcessId, $serverPort);
        // Echo stderr, just in case.
        // (It was redirected to stdout, so this should be empty).
        echo stream_get_contents($pipes[2]);
        stopServer($adminPort);
    } catch (Exception $e) {
        error_log("Caught exception, test failed, pid={$pid}");
        killChildren(posix_getpid());
        error_log('test failed');
    }
}
Example #5
0
    $pwd = $row['pwd'];
    $name = $row['name'];
    $owner = $row['user'];
    $hostname = $row['hostname'];
    $port = $row['port'];
    $hostip = $row['ip'];
    $srvId = $row['srvId'];
    $sshport = $row['sshport'];
    $startcmd = trim($row['startcmd']);
    $startcmd = str_replace("{port}", $port, $startcmd);
    $data = true;
    $task = "";
    if ($active) {
        //Before showing everything to the user, parse ALL servers which are active (not stopped) and check that are they running.
        if (!checkStatus($hostip, $sshport, $acc, $pwd)) {
            startServer($hostip, $sshport, $acc, $pwd, $startcmd);
        } else {
            if (!checkServer($hostip, $port)) {
                restartServer($hostip, $sshport, $acc, $pwd, $startcmd);
            }
        }
    }
}
$id = intval(trim($_SESSION['accid']));
?>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name=viewport content="width=device-width, initial-scale=1">
        <title><?php 
echo $user;
Example #6
0
function runTakeoverTest()
{
    global $test_run_id;
    $pid = posix_getpid();
    $takeoverFile = '/tmp/takeover.' . $test_run_id;
    $serverProc = $serverPort = $adminPort = null;
    $debugPort = false;
    $serverHome = __DIR__ . '/..';
    $serverRoot = __DIR__ . '/../server_root';
    $customArgs = " -vServer.TakeoverFilename={$takeoverFile}";
    try {
        $serverProc = startServer($serverPort, $adminPort, $debugPort, $serverHome, $serverRoot, $customArgs);
        if ($serverProc === null) {
            echo 'failed to start first server';
            return;
        }
        $takeoverid = 'new' . $test_run_id;
        $customArgs = '';
        $newServerProc = takeoverOldServer($serverPort, $adminPort, $serverHome, $serverRoot, $takeoverFile, $serverProc, $customArgs, $takeoverid);
        if ($newServerProc === null) {
            echo 'failed to start another server to takeover';
            return;
        }
        // Check and make sure that the server is always online, and old
        // server exits after a finite amount of time.  It is OK if both
        // servers are working at the same time.
        $testids = array($test_run_id, $takeoverid);
        for ($i = 1;; $i++) {
            if (!checkServerId($serverPort, $testids)) {
                return;
            }
            // Old server should die after a while
            $status = proc_get_status($serverProc);
            if ($status === false) {
                error_log('error retrieving old server status');
                proc_close($serverProc);
                return;
            }
            if (!$status['running']) {
                break;
            }
            // old server is gone
            if ($i > 300) {
                // Either the new process is initializing too slowly, or the
                // old server is stuck after takeover.  5 minutes should be
                // enough even for a debug build on a slow machine.
                error_log('old server still running after 300 seconds?');
                return;
            }
            sleep(1);
        }
        if (!checkServerId($serverPort, $takeoverid)) {
            return;
        }
        stopServer($adminPort, $newServerProc);
    } catch (Exception $e) {
        error_log("Caught exception, test failed, pid={$pid}, exn=" . $e->getMessage());
        killChildren($pid);
        if ($serverProc) {
            proc_close($serverProc);
        }
        if ($newServerProc) {
            proc_close($newServerProc);
        }
        error_log('test failed');
        return;
    }
    echo 'takeover successful';
}
Example #7
0
function restartServer($hostIp, $sshport, $account, $accpass, $startcmd)
{
    stopServer($hostIp, $sshport, $account, $accpass);
    startServer($hostIp, $sshport, $account, $accpass, $startcmd);
}