From b05ce2184e734a3c98ed2bbd0b3077b8d472109d Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Mon, 15 Jul 2013 18:23:46 +0200 Subject: [PATCH] Small improvements related to packet quota handling. --- .../de/hsadmin/hostsharing/QuotaLimit.java | 9 ++-- .../hsadmin/mods/pac/PacProcessorFactory.java | 42 +++++++++---------- .../mods/user/UnixUserProcessorFactory.java | 5 +-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java b/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java index f11b1ad..74f2541 100644 --- a/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java +++ b/hsarback/src/de/hsadmin/hostsharing/QuotaLimit.java @@ -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; } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index 223fc5a..a517e2c 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -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 Processor createUpdateProcessor(EntityManager em, T entity) + public 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 && " + diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java b/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java index 6621287..e03a227 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUserProcessorFactory.java @@ -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 "