Exemple #1
0
function clear_server()
{
    global $conf_base_path, $users, $is_compute_node, $is_control_node;
    if (!$is_control_node && !$is_compute_node) {
        return;
    }
    //print "Čekam 1s...\n";
    sleep(1);
    // Just a compute node
    if (!$is_control_node && $is_compute_node) {
        // This just kills node processes, not very efective...
        foreach ($users as $username => $options) {
            if ($options['status'] == "active") {
                deactivate_user($username);
            }
        }
        write_files();
        exec("killall node");
        exec("killall nodejs");
        exec("killall tmux");
        exec("killall inotifywait");
        exec("killall gdb");
        return;
    }
    if (!$is_control_node && $is_svn_node) {
        foreach ($users as $username => $options) {
            if ($options['status'] == "active") {
                deactivate_user($username);
            }
        }
        write_files();
        exec("killall php");
        exec("killall inotifywait");
        exec("killall gdb");
        return;
    }
    // Kill webidectl processes waiting to login
    $mypid = getmypid();
    foreach (ps_ax("127.0.0.1") as $process) {
        if ($process['pid'] != $mypid && strstr($process['cmd'], "webidectl") && strstr($process['cmd'], "php")) {
            exec("kill " . $process['pid']);
        }
    }
    // Logout all users
    foreach ($users as $username => $options) {
        if ($options['status'] == "active") {
            deactivate_user($username);
        }
    }
    // Force restart, since deactivate will just reload... this kills some hanging connections
    exec("service nginx restart");
    // Again, someone somehow reached the login page and tried to login
    foreach (ps_ax("127.0.0.1") as $process) {
        if ($process['pid'] != $mypid && strstr($process['cmd'], "webidectl") && strstr($process['cmd'], "php")) {
            exec("kill " . $process['pid']);
        }
        if (strstr($process['cmd'], "syncsvn.php")) {
            exec("kill " . $process['pid']);
        }
    }
    exec("killall node");
    exec("killall nodejs");
    exec("killall tmux");
    exec("killall inotifywait");
    exec("killall gdb");
    // Again write files, to nuke someone who managed to login
    write_files();
    // Again, someone cheated the race condition
    exec("service nginx restart");
}
Exemple #2
0
$lastfile = $conf_base_path . "/bin/webidectl last-update " . $userdata['esa'];
$fifo_file = $userdata['workspace'] . "/.svn.fifo";
$inotify_pid_file = $userdata['workspace'] . "/.inotify_pid";
if (!file_exists($userdata['workspace'])) {
    die("ERROR: {$username} doesn't exist\n");
}
// Avoid multiple instances
if (file_exists($userdata['svn_watch'])) {
    $pid = trim(file_get_contents($userdata['svn_watch']));
    if (file_exists("/proc/{$pid}")) {
        die("ERROR: syncsvn already running {$pid}");
    }
}
// REALLY avoid multiple instances :)
$mypid = getmypid();
foreach (ps_ax("localhost") as $process) {
    if (strstr($process['cmd'], "syncsvn.php {$username}") && $process['pid'] != $mypid) {
        exec("kill " . $process['pid']);
    }
}
exec("echo {$mypid} > " . $userdata['svn_watch']);
// SVN cleanup - not really neccessary because of fixsvn, but not a bad precaution
exec("cd " . $userdata['workspace'] . "; svn add *; svn add .login; svn add .logout; svn ci -m syncsvn_starting .");
if (file_exists($fifo_file)) {
    unlink($fifo_file);
}
$success = posix_mkfifo($fifo_file, 0755);
if (!$success) {
    die('Error: Could not create a named pipe: ' . posix_strerror(posix_errno()) . "\n");
}
// Main loop ensures that inotifywait is always running