Small improvements related to packet quota handling.

This commit is contained in:
Michael Hierweck 2013-07-15 18:23:46 +02:00
parent 5637091ea2
commit b05ce2184e
3 changed files with 27 additions and 29 deletions

View File

@ -1,9 +1,10 @@
package de.hsadmin.hostsharing;
public class QuotaLimit {
public static final double USER_HARD_FACTOR = 1.50;
public static final double GROUP_HARD_FACTOR = 1.50;
public static final double INODE_LIMIT_FACTOR = 0.25;
public static final double BLOCK_QUOTA_FACTOR = 1.00;
public static final double BLOCK_LIMIT_FACTOR = 1.50;
public static final double FILE_QUOTA_FACTOR = 0.10;
public static final double FILE_LIMIT_FACTOR = 0.15;
}

View File

@ -33,13 +33,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
UnixUser unixUser = getPacAdminUser(pac);
String password = PasswordTool.generatePassword();
return new CompoundProcessor(
createAddUserProc(pacName, unixUser, password),
createAddUserProc(pacName, unixUser, password),
createSetQuotaProc(pac),
createEtcHostsProc(hive),
createEtcHostsProc(hive),
createNetworkInterfacesProc(hive),
createIPTablesProc(),
createSudouersProc(hive),
createProftpdConfProc(hive),
createSudouersProc(hive),
createProftpdConfProc(hive),
createMakePacDirectoryStructure(unixUser),
createIfUp(pacName),
createHttpdVirtualProc(hive),
@ -55,7 +55,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
private Processor createHttpdVirtualProc(Hive hive) throws ProcessorException {
Processor domSetupProcessor = new CompoundProcessor(
new CreateFileProcessor("/de/hsadmin/mods/pac/httpd-virtual.vm", hive,
new CreateFileProcessor("/de/hsadmin/mods/pac/httpd-virtual.vm", hive,
"/etc/apache2/virtual.conf.tmp", "root", "root", "644", true),
new ShellProcessor("for PEM in $( cat /etc/apache2/virtual.conf.tmp | grep SSLCertificateFile | cut -c24- ); do " +
"ls $PEM >/dev/null 2>&1 || ( " +
@ -71,13 +71,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
"done"),
new ShellProcessor("(diff -q /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf"
+ " && rm /etc/apache2/virtual.conf.tmp )"
+ " || ( mv /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf "
+ " || ( mv /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf "
+ " && invoke-rc.d apache2 reload >/dev/null 2>&1 ) "));
return domSetupProcessor;
}
@Override
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity)
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity)
throws ProcessorException {
Pac pac = (Pac) entity;
String basepacName = pac.getBasepac().getName();
@ -85,7 +85,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
return createSetQuotaProc(pac);
} else {
return new NullProcessor();
}
}
}
@Override
@ -97,16 +97,16 @@ public class PacProcessorFactory implements EntityProcessorFactory {
WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName()));
waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor(
createIfDown(pac.getName()),
createEtcHostsProc(hive),
createNetworkInterfacesProc(hive),
createSudouersProc(hive),
createEtcHostsProc(hive),
createNetworkInterfacesProc(hive),
createSudouersProc(hive),
createProftpdConfProc(hive),
createHttpdVirtualProc(hive),
createAccountingRulesProc()), "remove packet");
return waiting;
} else {
return new NullProcessor();
}
}
}
private Processor createEtcHostsProc(Hive hive) throws ProcessorException {
@ -147,12 +147,12 @@ public class PacProcessorFactory implements EntityProcessorFactory {
quota = pacComponent.getQuantity() * 1024;
}
}
int blocksSoft = quota;
int blocksHard = ((Double) (quota * QuotaLimit.GROUP_HARD_FACTOR)).intValue();
int inodesSoft = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
int inodesHard = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
return new ShellProcessor("setquota -g " + pac.getName() + " "
+ blocksSoft + " " + blocksHard + " "
int blocksSoft = ((Double) (quota * QuotaLimit.BLOCK_QUOTA_FACTOR)).intValue();
int blocksHard = ((Double) (quota * QuotaLimit.BLOCK_LIMIT_FACTOR)).intValue();
int inodesSoft = ((Double) (quota * QuotaLimit.FILE_QUOTA_FACTOR)).intValue();
int inodesHard = ((Double) (quota * QuotaLimit.FILE_QUOTA_FACTOR)).intValue();
return new ShellProcessor("setquota -g " + pac.getName() + " "
+ blocksSoft + " " + blocksHard + " "
+ inodesSoft + " " + inodesHard + " "
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`");
}
@ -167,10 +167,10 @@ public class PacProcessorFactory implements EntityProcessorFactory {
return new ShellProcessor("chmod 711 " + homedir + " && " +
"su -l " + username + " -s \"/bin/bash\" -c \"mkdir -p " +
homedir + "/.bak " +
homedir + "/doms " +
homedir + "/doms " +
homedir + "/etc " +
homedir + "/users " +
homedir + "/var " +
homedir + "/users " +
homedir + "/var " +
"\" && " +
"chmod 0700 " + homedir + "/.bak && " +
"chown httpd " + homedir + "/doms && " +

View File

@ -90,10 +90,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
quotaHard = new Integer(0);
} else {
quotaHard = quotaHard * 1024;
}
if (quotaHard.intValue() < quotaSoft.intValue()) {
quotaHard = ((Double) (quotaSoft * QuotaLimit.USER_HARD_FACTOR)).intValue();
}
}
aCP.appendProcessor(new ShellProcessor("setquota -u "
+ user.getName() + " " + quotaSoft + " "
+ quotaHard + " 0 0 "