App-WordPressTools

 view release on metacpan or  search on metacpan

script/wp-tools  view on Meta::CPAN


### check defunct process count
if ($args->{max_dproc} && !$args->{force}) {
    #my $dproc = `ps -o state | grep D | wc -l`;
    my $dproc = `awk '/procs_blocked/ {print \$2}' /proc/stat`;
    if ($dproc > $args->{'max_dproc'}) {
        die 'Process queue full, please try again later.';
    }
}

my ($uid, $gid, $home_dir);
### determine who we are or should be running as
if ($< == 0) {
    if (!$args->{'username'}) {
        help(1, "You cannot $command a WordPress installation as a root user");
    }
    ($uid, $gid, $home_dir) = (getpwnam $args->{'username'})[2, 3, 7];
}
else {
    my $username;
    ($username, $uid, $gid, $home_dir) = (getpwuid $<)[0, 2, 3, 7];
    $args->{'username'} = $username if !$args->{'username'};
}

### check space and average IO wait time of the home partition
if (my ($homeslash) = $home_dir =~ m{^(/home\d+)/} and !$args->{force}) {
    #get available space on /home for the user in question in POSIX standard
    my $df = `df -P $homeslash | tail -1`;
    my ($device,undef,undef,$available) = split(/\s+/, $df);
    #convert to MB
    my $mbavail  = $available / 1024;

script/wp-tools  view on Meta::CPAN

        }
        die "Average IO wait time ($await) is too high on $homeslash" if $args->{'max_await'} < $await;
    }
}

### drop permissions
if ($< == 0) {
    #dmother
    #added use English; equivalent statements for clarity
    #keeping punctuation variables for speed
    #$REAL_GROUP_ID = $EFFECTIVE_GROUP_ID = "$gid $gid";
    $( = $) = "$gid $gid";
    #$REAL_USER_ID = $EFFECTIVE_USER_ID = $uid;
    $< = $> = $uid;
    #cannot perform this action as root
    if ($< == 0) {
        die "Failed to relinquish privileges to user $args->{'username'}: $!";
    }
}
chdir($home_dir);

### prevent too many concurrent executions



( run in 0.558 second using v1.01-cache-2.11-cpan-5735350b133 )