Exemplo n.º 1
0
function mimedefang_tmpfs_mount($size)
{
    $sock = new sockets();
    $unix = new unix();
    $TMPDIR = "/var/spool/MIMEDefang";
    if (!is_dir($TMPDIR)) {
        @mkdir($TMPDIR, 0755, true);
    }
    @chown($TMPDIR, "postfix");
    @chgrp($TMPDIR, "postfix");
    $idbin = $unix->find_program("id");
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    $rm = $unix->find_program("rm");
    if (strlen($idbin) < 3) {
        echo "Starting mimedefang: tmpfs `id` no such binary\n";
        return;
    }
    if (strlen($mount) < 3) {
        echo "Starting mimedefang: tmpfs `mount` no such binary\n";
        return;
    }
    exec("{$idbin} postfix 2>&1", $results);
    if (!preg_match("#uid=([0-9]+).*?gid=([0-9]+)#", @implode("", $results), $re)) {
        echo "Starting......: " . date("H:i:s") . "MySQL mysql no such user...\n";
        return;
    }
    $uid = $re[1];
    $gid = $re[2];
    echo "Starting mimedefang: tmpfs uid/gid ={$uid}:{$gid} for {$size}M\n";
    mimedefang_tmpfs_umount();
    shell_exec("{$rm} -rf {$TMPDIR}/* >/dev/null 2>&1");
    $cmd = "{$mount} -t tmpfs -o rw,uid={$uid},gid={$gid},size={$size}M,nr_inodes=10k,mode=0700 tmpfs \"{$TMPDIR}\"";
    shell_exec($cmd);
    $mounted = mysql_tmpfs_ismounted($uid);
    if (mysql_tmpfs_ismounted()) {
        echo "Starting mimedefang: {$TMPDIR}(tmpfs) for {$size}M success\n";
    } else {
        echo "Starting mimedefang: tmpfs for {$size}M failed, it will return back to disk\n";
    }
}
Exemplo n.º 2
0
function mysql_tmpfs_umount($uid)
{
    $unix = new unix();
    $idbin = $unix->find_program("id");
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    $rm = $unix->find_program("rm");
    exec("{$idbin} mysql 2>&1", $results);
    if (!preg_match("#uid=([0-9]+).*?gid=([0-9]+)#", @implode("", $results), $re)) {
        echo "Starting......: " . date("H:i:s") . "MySQL mysql no such user...\n";
        return;
    }
    $uid = $re[1];
    $gid = $re[2];
    if (!is_numeric($uid)) {
        echo "Starting......: " . date("H:i:s") . " MySQL tmpfs uid is not a numeric, aborting umounting task\n";
        return;
    }
    $mounted = mysql_tmpfs_ismounted($uid);
    $c = 0;
    while (strlen($mounted) > 3) {
        if (strlen($mounted) > 3) {
            echo "Starting......: " . date("H:i:s") . "MySQL umount({$uid}) {$mounted}\n";
            shell_exec("{$umount} -l \"{$mounted}\"");
            $c++;
        }
        if ($c > 20) {
            break;
        }
        $mounted = mysql_tmpfs_ismounted($uid);
    }
}