Skip to content

Commit bc69174

Browse files
author
Till Brehm
committed
Merge branch 'xfs-quota' into 'stable-3.1'
Feat: enable xfs-quotas. This feature-request added a long time ago by @ftimme and also reasked again by other user @alienn With this few lines it should solve issue #1948 for ispconfig-3.1 See merge request !317
2 parents 76d6d3c + e14c6ea commit bc69174

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
@@ -876,11 +876,29 @@ function update($event_name, $data) {
876876
if($data['new']['hd_quota'] > 0) {
877877
$blocks_soft = $data['new']['hd_quota'] * 1024;
878878
$blocks_hard = $blocks_soft + 1024;
879+
$mb_hard = $mb_soft + 1;
879880
} else {
880-
$blocks_soft = $blocks_hard = 0;
881+
$mb_soft = $mb_hard = $blocks_soft = $blocks_hard = 0;
881882
}
882-
exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
883-
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
883+
884+
// get the primitive folder for document_root and the filesystem, will need it later.
885+
$df_output=exec("df -T $document_root|awk 'END{print \$2,\$NF}'");
886+
$file_system = explode(" ", $df_output)[0];
887+
$primitive_root = explode(" ", $df_output)[1];
888+
889+
if ( $file_system , array('ext2','ext3','ext4') ) {
890+
exec('setquota -u '. $username . ' ' . $blocks_soft . ' ' . $blocks_hard . ' 0 0 -a &> /dev/null');
891+
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
892+
} elseif ($file_system == 'xfs') {
893+
894+
exec("xfs_quota -x -c 'limit -g bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username' $primitive_root");
895+
896+
// xfs only supports timers globally, not per user.
897+
exec("xfs_quota -x -c 'timer -bir -i 604800'");
898+
899+
unset($project_uid, $username_position, $xfs_projects);
900+
unset($primitive_root, $df_output, $mb_hard, $mb_soft);
901+
}
884902
}
885903

886904
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
@@ -731,15 +731,33 @@ function update($event_name, $data) {
731731
} // end copy error docs
732732

733733
// Set the quota for the user, but only for vhosts, not vhostsubdomains or vhostalias
734-
if($username != '' && $app->system->is_user($username) && $data['new']['type'] == 'vhost') {
734+
if($username != '' && $app->system->is_user($username) && $data['new']['type'] == 'vhost') {
735735
if($data['new']['hd_quota'] > 0) {
736736
$blocks_soft = $data['new']['hd_quota'] * 1024;
737737
$blocks_hard = $blocks_soft + 1024;
738+
$mb_hard = $mb_soft + 1;
738739
} else {
739-
$blocks_soft = $blocks_hard = 0;
740+
$mb_soft = $mb_hard = $blocks_soft = $blocks_hard = 0;
740741
}
741-
exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
742-
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
742+
743+
// get the primitive folder for document_root and the filesystem, will need it later.
744+
$df_output=exec("df -T $document_root|awk 'END{print \$2,\$NF}'");
745+
$file_system = explode(" ", $df_output)[0];
746+
$primitive_root = explode(" ", $df_output)[1];
747+
748+
if ( $file_system , array('ext2','ext3','ext4') ) {
749+
exec('setquota -u '. $username . ' ' . $blocks_soft . ' ' . $blocks_hard . ' 0 0 -a &> /dev/null');
750+
exec('setquota -T -u '.$username.' 604800 604800 -a &> /dev/null');
751+
} elseif ($file_system == 'xfs') {
752+
753+
exec("xfs_quota -x -c 'limit -g bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username' $primitive_root");
754+
755+
// xfs only supports timers globally, not per user.
756+
exec("xfs_quota -x -c 'timer -bir -i 604800'");
757+
758+
unset($project_uid, $username_position, $xfs_projects);
759+
unset($primitive_root, $df_output, $mb_hard, $mb_soft);
760+
}
743761
}
744762

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

0 commit comments

Comments
 (0)