Small improvements related to packet quota handling.
This commit is contained in:
parent
5637091ea2
commit
b05ce2184e
@ -1,9 +1,10 @@
|
|||||||
package de.hsadmin.hostsharing;
|
package de.hsadmin.hostsharing;
|
||||||
|
|
||||||
public class QuotaLimit {
|
public class QuotaLimit {
|
||||||
|
|
||||||
public static final double USER_HARD_FACTOR = 1.50;
|
public static final double BLOCK_QUOTA_FACTOR = 1.00;
|
||||||
public static final double GROUP_HARD_FACTOR = 1.50;
|
public static final double BLOCK_LIMIT_FACTOR = 1.50;
|
||||||
public static final double INODE_LIMIT_FACTOR = 0.25;
|
public static final double FILE_QUOTA_FACTOR = 0.10;
|
||||||
|
public static final double FILE_LIMIT_FACTOR = 0.15;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
UnixUser unixUser = getPacAdminUser(pac);
|
UnixUser unixUser = getPacAdminUser(pac);
|
||||||
String password = PasswordTool.generatePassword();
|
String password = PasswordTool.generatePassword();
|
||||||
return new CompoundProcessor(
|
return new CompoundProcessor(
|
||||||
createAddUserProc(pacName, unixUser, password),
|
createAddUserProc(pacName, unixUser, password),
|
||||||
createSetQuotaProc(pac),
|
createSetQuotaProc(pac),
|
||||||
createEtcHostsProc(hive),
|
createEtcHostsProc(hive),
|
||||||
createNetworkInterfacesProc(hive),
|
createNetworkInterfacesProc(hive),
|
||||||
createIPTablesProc(),
|
createIPTablesProc(),
|
||||||
createSudouersProc(hive),
|
createSudouersProc(hive),
|
||||||
createProftpdConfProc(hive),
|
createProftpdConfProc(hive),
|
||||||
createMakePacDirectoryStructure(unixUser),
|
createMakePacDirectoryStructure(unixUser),
|
||||||
createIfUp(pacName),
|
createIfUp(pacName),
|
||||||
createHttpdVirtualProc(hive),
|
createHttpdVirtualProc(hive),
|
||||||
@ -55,7 +55,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
|
|
||||||
private Processor createHttpdVirtualProc(Hive hive) throws ProcessorException {
|
private Processor createHttpdVirtualProc(Hive hive) throws ProcessorException {
|
||||||
Processor domSetupProcessor = new CompoundProcessor(
|
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),
|
"/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 " +
|
new ShellProcessor("for PEM in $( cat /etc/apache2/virtual.conf.tmp | grep SSLCertificateFile | cut -c24- ); do " +
|
||||||
"ls $PEM >/dev/null 2>&1 || ( " +
|
"ls $PEM >/dev/null 2>&1 || ( " +
|
||||||
@ -71,13 +71,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
"done"),
|
"done"),
|
||||||
new ShellProcessor("(diff -q /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf"
|
new ShellProcessor("(diff -q /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf"
|
||||||
+ " && rm /etc/apache2/virtual.conf.tmp )"
|
+ " && 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 ) "));
|
+ " && invoke-rc.d apache2 reload >/dev/null 2>&1 ) "));
|
||||||
return domSetupProcessor;
|
return domSetupProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity)
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity)
|
||||||
throws ProcessorException {
|
throws ProcessorException {
|
||||||
Pac pac = (Pac) entity;
|
Pac pac = (Pac) entity;
|
||||||
String basepacName = pac.getBasepac().getName();
|
String basepacName = pac.getBasepac().getName();
|
||||||
@ -85,7 +85,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
return createSetQuotaProc(pac);
|
return createSetQuotaProc(pac);
|
||||||
} else {
|
} else {
|
||||||
return new NullProcessor();
|
return new NullProcessor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,16 +97,16 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName()));
|
WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName()));
|
||||||
waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor(
|
waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor(
|
||||||
createIfDown(pac.getName()),
|
createIfDown(pac.getName()),
|
||||||
createEtcHostsProc(hive),
|
createEtcHostsProc(hive),
|
||||||
createNetworkInterfacesProc(hive),
|
createNetworkInterfacesProc(hive),
|
||||||
createSudouersProc(hive),
|
createSudouersProc(hive),
|
||||||
createProftpdConfProc(hive),
|
createProftpdConfProc(hive),
|
||||||
createHttpdVirtualProc(hive),
|
createHttpdVirtualProc(hive),
|
||||||
createAccountingRulesProc()), "remove packet");
|
createAccountingRulesProc()), "remove packet");
|
||||||
return waiting;
|
return waiting;
|
||||||
} else {
|
} else {
|
||||||
return new NullProcessor();
|
return new NullProcessor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Processor createEtcHostsProc(Hive hive) throws ProcessorException {
|
private Processor createEtcHostsProc(Hive hive) throws ProcessorException {
|
||||||
@ -147,12 +147,12 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
quota = pacComponent.getQuantity() * 1024;
|
quota = pacComponent.getQuantity() * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int blocksSoft = quota;
|
int blocksSoft = ((Double) (quota * QuotaLimit.BLOCK_QUOTA_FACTOR)).intValue();
|
||||||
int blocksHard = ((Double) (quota * QuotaLimit.GROUP_HARD_FACTOR)).intValue();
|
int blocksHard = ((Double) (quota * QuotaLimit.BLOCK_LIMIT_FACTOR)).intValue();
|
||||||
int inodesSoft = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
|
int inodesSoft = ((Double) (quota * QuotaLimit.FILE_QUOTA_FACTOR)).intValue();
|
||||||
int inodesHard = ((Double) (quota * QuotaLimit.INODE_LIMIT_FACTOR)).intValue();
|
int inodesHard = ((Double) (quota * QuotaLimit.FILE_QUOTA_FACTOR)).intValue();
|
||||||
return new ShellProcessor("setquota -g " + pac.getName() + " "
|
return new ShellProcessor("setquota -g " + pac.getName() + " "
|
||||||
+ blocksSoft + " " + blocksHard + " "
|
+ blocksSoft + " " + blocksHard + " "
|
||||||
+ inodesSoft + " " + inodesHard + " "
|
+ inodesSoft + " " + inodesHard + " "
|
||||||
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`");
|
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`");
|
||||||
}
|
}
|
||||||
@ -167,10 +167,10 @@ public class PacProcessorFactory implements EntityProcessorFactory {
|
|||||||
return new ShellProcessor("chmod 711 " + homedir + " && " +
|
return new ShellProcessor("chmod 711 " + homedir + " && " +
|
||||||
"su -l " + username + " -s \"/bin/bash\" -c \"mkdir -p " +
|
"su -l " + username + " -s \"/bin/bash\" -c \"mkdir -p " +
|
||||||
homedir + "/.bak " +
|
homedir + "/.bak " +
|
||||||
homedir + "/doms " +
|
homedir + "/doms " +
|
||||||
homedir + "/etc " +
|
homedir + "/etc " +
|
||||||
homedir + "/users " +
|
homedir + "/users " +
|
||||||
homedir + "/var " +
|
homedir + "/var " +
|
||||||
"\" && " +
|
"\" && " +
|
||||||
"chmod 0700 " + homedir + "/.bak && " +
|
"chmod 0700 " + homedir + "/.bak && " +
|
||||||
"chown httpd " + homedir + "/doms && " +
|
"chown httpd " + homedir + "/doms && " +
|
||||||
|
@ -90,10 +90,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
quotaHard = new Integer(0);
|
quotaHard = new Integer(0);
|
||||||
} else {
|
} else {
|
||||||
quotaHard = quotaHard * 1024;
|
quotaHard = quotaHard * 1024;
|
||||||
}
|
}
|
||||||
if (quotaHard.intValue() < quotaSoft.intValue()) {
|
|
||||||
quotaHard = ((Double) (quotaSoft * QuotaLimit.USER_HARD_FACTOR)).intValue();
|
|
||||||
}
|
|
||||||
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
aCP.appendProcessor(new ShellProcessor("setquota -u "
|
||||||
+ user.getName() + " " + quotaSoft + " "
|
+ user.getName() + " " + quotaSoft + " "
|
||||||
+ quotaHard + " 0 0 "
|
+ quotaHard + " 0 0 "
|
||||||
|
Loading…
Reference in New Issue
Block a user