Skip to content

Commit e14c6ea

Browse files
committed
Feat: enable xfs-quotas.
--- Daniel Ripoll I was a DevOps before it was cool. http://danielripoll.es +34 6688 27490
1 parent df8e423 commit e14c6ea

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,29 @@ function update($event_name, $data) {
860860
if($data['new']['hd_quota'] > 0) {
861861
$blocks_soft = $data['new']['hd_quota'] * 1024;
862862
$blocks_hard = $blocks_soft + 1024;
863+
$mb_hard = $mb_soft + 1;
863864
} else {
864-
$blocks_soft = $blocks_hard = 0;
865+
$mb_soft = $mb_hard = $blocks_soft = $blocks_hard = 0;
865866
}
866-
exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
867-
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
867+
868+
// get the primitive folder for document_root and the filesystem, will need it later.
869+
$df_output=exec("df -T $document_root|awk 'END{print \$2,\$NF}'");
870+
$file_system = explode(" ", $df_output)[0];
871+
$primitive_root = explode(" ", $df_output)[1];
872+
873+
if ( $file_system , array('ext2','ext3','ext4') ) {
874+
exec('setquota -u '. $username . ' ' . $blocks_soft . ' ' . $blocks_hard . ' 0 0 -a &> /dev/null');
875+
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
876+
} elseif ($file_system == 'xfs') {
877+
878+
exec("xfs_quota -x -c 'limit -g bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username' $primitive_root");
879+
880+
// xfs only supports timers globally, not per user.
881+
exec("xfs_quota -x -c 'timer -bir -i 604800'");
882+
883+
unset($project_uid, $username_position, $xfs_projects);
884+
unset($primitive_root, $df_output, $mb_hard, $mb_soft);
885+
}
868886
}
869887

870888
if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) {

server/plugins-available/cron_plugin.inc.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,37 @@ function update($event_name, $data) {
123123
exec("useradd -d ".escapeshellcmd($parent_domain["document_root"])." -g $groupname $username -s /bin/false");
124124
$app->log("Adding the user: $username", LOGLEVEL_DEBUG);
125125
}
126-
127-
// Set the quota for the user
128-
if($username != '' && $app->system->is_user($username)) {
129-
if($parent_domain["hd_quota"] > 0){
130-
$blocks_soft = $parent_domain["hd_quota"] * 1024;
131-
$blocks_hard = $blocks_soft + 1024;
132-
} else {
133-
$blocks_soft = $blocks_hard = 0;
134-
}
135-
exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
136-
exec("setquota -T -u $username 604800 604800 -a &> /dev/null");
137-
}
126+
127+
// Set the quota for the user
128+
if($username != '' && $app->system->is_user($username)) {
129+
if($parent_domain['hd_quota'] > 0) {
130+
$blocks_soft = $parent_domain['hd_quota'] * 1024;
131+
$mb_soft = $parent_domain['hd_quota'];
132+
$blocks_hard = $blocks_soft + 1024;
133+
$mb_hard = $mb_soft + 1;
134+
} else {
135+
$mb_soft = $mb_hard = $blocks_soft = $blocks_hard = 0;
136+
}
137+
138+
// get the primitive folder for document_root and the filesystem, will need it later.
139+
$df_output=exec("df -T $document_root|awk 'END{print \$2,\$NF}'");
140+
$file_system = explode(" ", $df_output)[0];
141+
$primitive_root = explode(" ", $df_output)[1];
142+
143+
if ( $file_system , array('ext2','ext3','ext4') ) {
144+
exec('setquota -u '. $username . ' ' . $blocks_soft . ' ' . $blocks_hard . ' 0 0 -a &> /dev/null');
145+
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
146+
} elseif ($file_system == 'xfs') {
147+
148+
exec("xfs_quota -x -c 'limit -g bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username' $primitive_root");
149+
150+
// xfs only supports timers globally, not per user.
151+
exec("xfs_quota -x -c 'timer -bir -i 604800'");
152+
153+
unset($project_uid, $username_position, $xfs_projects);
154+
unset($primitive_root, $df_output, $mb_hard, $mb_soft);
155+
}
156+
}
138157

139158
//TODO : change this when distribution information has been integrated into server record
140159
//* Gentoo requires a user to be part of the crontab group.

server/plugins-available/nginx_plugin.inc.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,33 @@ function update($event_name, $data) {
715715
} // end copy error docs
716716

717717
// Set the quota for the user, but only for vhosts, not vhostsubdomains or vhostalias
718-
if($username != '' && $app->system->is_user($username) && $data['new']['type'] == 'vhost') {
718+
if($username != '' && $app->system->is_user($username) && $data['new']['type'] == 'vhost') {
719719
if($data['new']['hd_quota'] > 0) {
720720
$blocks_soft = $data['new']['hd_quota'] * 1024;
721721
$blocks_hard = $blocks_soft + 1024;
722+
$mb_hard = $mb_soft + 1;
722723
} else {
723-
$blocks_soft = $blocks_hard = 0;
724+
$mb_soft = $mb_hard = $blocks_soft = $blocks_hard = 0;
724725
}
725-
exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
726-
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
726+
727+
// get the primitive folder for document_root and the filesystem, will need it later.
728+
$df_output=exec("df -T $document_root|awk 'END{print \$2,\$NF}'");
729+
$file_system = explode(" ", $df_output)[0];
730+
$primitive_root = explode(" ", $df_output)[1];
731+
732+
if ( $file_system , array('ext2','ext3','ext4') ) {
733+
exec('setquota -u '. $username . ' ' . $blocks_soft . ' ' . $blocks_hard . ' 0 0 -a &> /dev/null');
734+
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
735+
} elseif ($file_system == 'xfs') {
736+
737+
exec("xfs_quota -x -c 'limit -g bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username' $primitive_root");
738+
739+
// xfs only supports timers globally, not per user.
740+
exec("xfs_quota -x -c 'timer -bir -i 604800'");
741+
742+
unset($project_uid, $username_position, $xfs_projects);
743+
unset($primitive_root, $df_output, $mb_hard, $mb_soft);
744+
}
727745
}
728746

729747
if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) {

0 commit comments

Comments
 (0)