Example #1
0
function build()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        writelogs("Already process exists pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
        echo "Already process exists pid {$pid}\n";
        return;
    }
    $mysqld = $unix->find_program("mysqld");
    if (!is_file($mysqld)) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $sql = "SELECT * FROM loop_disks ORDER BY `size` DESC";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "Starting......: " . date("H:i:s") . " Loop disks {$q->mysql_error}\n";
        $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__);
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $path = trim($ligne["path"]);
        if (is_dir($path)) {
            $oldpath = $path;
            $path = $path . "/" . time() . ".disk";
            $sql = "UPDATE loop_disks SET path='{$path}' WHERE `path`='{$oldpath}'";
            $q->QUERY_SQL($sql, 'artica_backup');
        }
        $size = $ligne["size"];
        $maxfds = $ligne["maxfds"];
        $label = $ligne["disk_name"];
        writelogs("check {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__);
        if (!stat_system($path)) {
            writelogs("buil_dd {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__);
            if (!build_dd($path, $size)) {
                continue;
            }
        }
        $GetLoops = GetLoops();
        if (!stat_system($path)) {
            writelogs("{$path} no such file", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if ($GetLoops[$path] == null) {
            writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__);
            if (!build_loop($path)) {
                writelogs("`{$path}` unable to create loop", __FUNCTION__, __FILE__, __LINE__);
                continue;
            }
            writelogs("Re-check the loop list...", __FUNCTION__, __FILE__, __LINE__);
            $GetLoops = GetLoops();
            if ($GetLoops[$path] == null) {
                writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__);
                continue;
            }
        }
        writelogs("{$path} loop={$GetLoops[$path]}", __FUNCTION__, __FILE__, __LINE__);
        $sql = "UPDATE loop_disks SET loop_dev='{$GetLoops[$path]}' WHERE `path`='{$path}'";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo "{$q->mysql_error}\n";
            continue;
        }
        $dev = $GetLoops[$path];
        echo "Starting......: " . date("H:i:s") . " {$path} is {$dev}\n";
        if (!ifFileSystem($dev)) {
            if (!mke2fs($dev, $label, $maxfds)) {
                continue;
            }
        }
        $uuid = Getuuid($dev);
        echo "Starting......: " . date("H:i:s") . " {$dev} uuid={$uuid}\n";
        if ($uuid == null) {
            continue;
        }
        $autofs = new autofs();
        $autofs->uuid = $uuid;
        $autofs->by_uuid_addmedia($ligne["disk_name"], "auto");
        $nohup = $unix->find_program("nohup");
        shell_exec("{$nohup} /etc/init.d/artica-postfix autofs restart >/dev/null 2>&1 &");
    }
}
Example #2
0
    exit;
}
if (isset($_GET["vgdisplay"])) {
    vgdisplay();
    exit;
}
if (isset($_GET["lvcreate"])) {
    lvcreate();
    exit;
}
if (isset($_GET["lvdisplay"])) {
    lvdisplay();
    exit;
}
if (isset($_GET["mke2fs"])) {
    mke2fs();
    exit;
}
if (isset($_GET["lvremove"])) {
    lvremove();
    exit;
}
if (isset($_GET["lvresize"])) {
    lvresize();
    exit;
}
if (isset($_GET["loop-del"])) {
    loopdel();
    exit;
}
if (isset($_GET["loopcheck"])) {
Example #3
0
function build()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Already process exists pid {$pid}\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $php = $unix->LOCATE_PHP5_BIN();
    if (system_is_overloaded()) {
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --build");
        return;
    }
    patch_grub_default();
    $sock = new sockets();
    $q = new mysql();
    $sql = "SELECT * FROM users_containers WHERE created=0 AND onerror=0";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $count = mysql_num_rows($results);
    if (!$q->ok) {
        echo "Starting......: " . date("H:i:s") . " users_containers {$q->mysql_error}\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " {$count} containers to build\n";
    if ($count > 0) {
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $directory = trim($ligne["directory"]);
            $ID = $ligne["container_id"];
            if ($directory == null) {
                users_containers_error($ID, "No specified main directory...");
                continue;
            }
            $directory_size_avai = $unix->DIRECTORY_FREEM($directory);
            if ($directory_size_avai == 0) {
                users_containers_error($ID, "no space left on specified directory");
                continue;
            }
            @mkdir($directory, 0755, true);
            if (!is_dir($directory)) {
                users_containers_error($ID, "Permission denied on specified directory");
                continue;
            }
            $ContainerFullPath = $directory . "/{$ID}.disk";
            $size = $ligne["container_size"];
            if ($size > $directory_size_avai) {
                users_containers_error($ID, "{$size}MB will exceed space on main storage");
                continue;
            }
            $label = "{$ID}_disk";
            echo "Starting......: " . date("H:i:s") . " Verify {$ContainerFullPath} with a size of {$size}MB\n";
            if (!stat_system($ContainerFullPath)) {
                echo "Starting......: " . date("H:i:s") . " buil_dd {$ContainerFullPath} {$size}MB\n";
                if (!build_dd($ContainerFullPath, $size)) {
                    users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")");
                    continue;
                }
            }
            $GetLoops = GetLoops();
            if (!stat_system($ContainerFullPath)) {
                users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")");
                continue;
            }
            if ($GetLoops[$ContainerFullPath] == null) {
                echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such loop\n";
                if (!build_loop($ContainerFullPath)) {
                    echo "`{$ContainerFullPath}` unable to create loop\n";
                    echo "Starting......: " . date("H:i:s") . " Re-check the loop list...\n";
                    $GetLoops = GetLoops();
                    if ($GetLoops[$ContainerFullPath] == null) {
                        users_containers_error($ID, "Loop error (ERR." . __LINE__ . ")");
                        continue;
                    }
                }
            }
            echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} loop={$GetLoops[$ContainerFullPath]}\n";
            $sql = "UPDATE users_containers SET loop_dev='{$GetLoops[$ContainerFullPath]}' WHERE `container_id`='{$ID}'";
            $q->QUERY_SQL($sql, 'artica_backup');
            if (!$q->ok) {
                echo "{$q->mysql_error}\n";
                continue;
            }
            $dev = $GetLoops[$ContainerFullPath];
            echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} is {$dev}\n";
            if (!ifFileSystem($dev)) {
                if (!mke2fs($dev, $label)) {
                    users_containers_error($ID, "mke2fs error (ERR." . __LINE__ . ")");
                    continue;
                }
            }
            $uuid = Getuuid($dev);
            echo "Starting......: " . date("H:i:s") . " {$dev} uuid={$uuid}\n";
            $q->QUERY_SQL("UPDATE users_containers SET uuid='{$uuid}' WHERE `container_id`='{$ID}'", 'artica_backup');
            if ($uuid == null) {
                continue;
            }
            $q->QUERY_SQL("UPDATE users_containers SET created='1' WHERE `container_id`='{$ID}'", 'artica_backup');
        }
    }
    @mkdir("/media/artica_containers/membersdisks", 0755, true);
    $q = new mysql();
    $sql = "SELECT * FROM users_containers WHERE created=1 AND onerror=0";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $count = mysql_num_rows($results);
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $directory = trim($ligne["directory"]);
        $mkfs_ext4 = $unix->find_program("mkfs.ext4");
        $typ = "ext4";
        if (!is_file($mkfs_ext4)) {
            $typ = "ext3";
        }
        $ID = $ligne["container_id"];
        $ContainerFullPath = $directory . "/{$ID}.disk";
        if (!is_file($ContainerFullPath)) {
            echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such file\n";
        }
        $autofs[] = "disk{$ID}\t-fstype={$typ},loop\t:{$ContainerFullPath}";
    }
    echo "Starting......: " . date("H:i:s") . " Saving /etc/auto.members\n";
    @file_put_contents("/etc/auto.members", implode("\n", $autofs) . "\n");
    @unlink("/etc/init.d/artica-containers");
    patch_auto_master();
    shell_exec("/etc/init.d/autofs reload");
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --iscsi");
    if (is_file("/etc/init.d/iscsitarget")) {
        $unix->THREAD_COMMAND_SET("/etc/init.d/iscsitarget restart");
    }
    Checks(true);
}
Example #4
0
function build()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $oldpid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($oldpid)) {
        writelogs("Already process exists pid {$oldpid}", __FUNCTION__, __FILE__, __LINE__);
        echo "Already process exists pid {$oldpid}\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $sql = "SELECT * FROM loop_disks ORDER BY `size` DESC";
    $sql = "SELECT * FROM loop_disks ORDER BY `size` DESC";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n";
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $path = $ligne["path"];
        $size = $ligne["size"];
        writelogs("check {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__);
        if (!stat_system($path)) {
            writelogs("buil_dd {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__);
            if (!build_dd($path, $size)) {
                continue;
            }
        }
        $GetLoops = GetLoops();
        if (!stat_system($path)) {
            writelogs("{$path} no such file", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if ($GetLoops[$path] == null) {
            writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__);
            if (!build_loop($path)) {
                writelogs("{$path} unable to create loop", __FUNCTION__, __FILE__, __LINE__);
                continue;
            }
            $GetLoops = GetLoops();
            if ($GetLoops[$path] == null) {
                writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__);
                continue;
            }
        }
        writelogs("{$path} loop={$GetLoops[$path]}", __FUNCTION__, __FILE__, __LINE__);
        $sql = "UPDATE loop_disks SET loop_dev='{$GetLoops[$path]}' WHERE `path`='{$path}'";
        $q = new mysql();
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo "{$q->mysql_error}\n";
            continue;
        }
        $dev = $GetLoops[$path];
        echo "Starting......: {$path} is {$dev}\n";
        if (!ifFileSystem($dev)) {
            if (!mke2fs($dev)) {
                continue;
            }
        }
        $uuid = Getuuid($dev);
        echo "Starting......: {$dev} uuid={$uuid}\n";
        if ($uuid == null) {
            continue;
        }
        $autofs = new autofs();
        $autofs->uuid = $uuid;
        $autofs->by_uuid_addmedia($ligne["disk_name"], "auto");
        shell_exec("/etc/init.d/autofs reload");
    }
}