delegate setquota to salt

This commit is contained in:
Peter Hormanns 2021-08-17 19:59:11 +02:00
parent 673a3a484a
commit 2ded642fea
3 changed files with 9 additions and 59 deletions

View File

@ -1,10 +0,0 @@
package de.hsadmin.hostsharing;
public class QuotaLimit {
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 = 1.00;
public static final double FILE_LIMIT_FACTOR = 1.50;
}

View File

@ -24,7 +24,6 @@ import de.hsadmin.core.util.Config;
import de.hsadmin.core.util.HSAdminException;
import de.hsadmin.core.util.PasswordTool;
import de.hsadmin.hostsharing.BasePacType;
import de.hsadmin.hostsharing.QuotaLimit;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.user.UnixUser;
@ -43,7 +42,6 @@ public class PacProcessorFactory implements EntityProcessorFactory {
String password = PasswordTool.generatePassword();
WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(new CompoundProcessor(
createAddUserProc(pacName, unixUser, password),
createSetQuotaProc(pac),
createEtcHostsProc(hive),
createNetworkInterfacesProc(hive),
createIPTablesProc(),
@ -78,8 +76,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
createNetworkInterfacesProc(hive),
createProftpdConfProc(hive),
createHttpdVirtualProc(hive),
createSaltCallProc(),
createSetQuotaProc(pac)
createSaltCallProc()
));
final Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.dns").split(",")) {
@ -109,7 +106,8 @@ public class PacProcessorFactory implements EntityProcessorFactory {
createHttpdVirtualProc(hive),
createUnlinkSiteProc(pac.getName() + ".hostsharing.net"),
createHiveDNSRemoveProcessor(domainName),
createAccountingRulesProc()), "remove packet");
createAccountingRulesProc(),
new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1")), "remove packet");
final Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.dns").split(",")) {
waiting.appendProcessor(queueName, createDNSServerConfigProcessor(em), queueName + ".hostsharing.net");
@ -234,32 +232,13 @@ public class PacProcessorFactory implements EntityProcessorFactory {
+ ":" + unixUser.getShell() + "\n");
}
private Processor createSetQuotaProc(Pac pac) {
int quota = 1024;
Set<PacComponent> pacComponents = pac.getPacComponents();
for (PacComponent pacComponent : pacComponents) {
BaseComponent baseComponent = pacComponent.getBaseComponent();
String feature = baseComponent.getFeature();
if ("QUOTA".equals(feature)) {
quota = pacComponent.getQuantity() * 1024;
}
}
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_LIMIT_FACTOR)).intValue();
return new ShellProcessor("setquota -g " + pac.getName() + " "
+ blocksSoft + " " + blocksHard + " "
+ inodesSoft + " " + inodesHard + " "
+ "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`");
}
private Processor createDelUserProc(String pacName) {
Processor killProcessesProc = new ShellProcessor("killall -TERM -u " + pacName + " && sleep 5 && killall -KILL -u " + pacName + " && sleep 5 || true");
Processor userdelProc = new ShellProcessor("deluser --remove-home " + pacName);
CompoundProcessor proc = new CompoundProcessor(killProcessesProc, userdelProc);
proc.appendProcessor(new ShellProcessor("rm -f '/var/spool/cron/crontabs/" + pacName + "'"));
proc.appendProcessor(new ShellProcessor("rm -f '/var/mail/" + pacName + "'"));
proc.appendProcessor(new ShellProcessor("rm -rf '/home/storage/" + pacName + "/'"));
return proc;
}

View File

@ -28,8 +28,8 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
+ ":" + user.getComment() + ":" + user.getHomedir()
+ ":" + user.getShell() + "\n"));
appendSetHomeACLProcessor(aCP, user);
appendSetQuotaProcessor(aCP, user);
appendMakeMaildirProcessor(aCP, user);
aCP.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1"));
return aCP;
}
@ -46,7 +46,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
if (user.getPassword() != null && user.getPassword().length() > 0)
aCP.appendProcessor(new ShellProcessor("chpasswd ", user.getName()
+ ":" + user.getPassword() + "\n"));
appendSetQuotaProcessor(aCP, user);
aCP.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1"));
return aCP;
}
@ -56,6 +56,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
UnixUser user = (UnixUser) entity;
String uid = user.getName();
String pac = user.getPac().getName();
if (uid != null && uid.length() > 4) {
Processor killProcessesProc = new ShellProcessor("killall -TERM -u " + uid + " && sleep 5 && killall -KILL -u " + uid + " && sleep 5 || true");
Processor userdelProc = null;
@ -67,6 +68,8 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
CompoundProcessor proc = new CompoundProcessor(killProcessesProc, userdelProc);
proc.appendProcessor(new ShellProcessor("rm -f '/var/spool/cron/crontabs/" + uid + "'"));
proc.appendProcessor(new ShellProcessor("rm -f '/var/mail/" + uid + "'"));
proc.appendProcessor(new ShellProcessor("rm -rf '/home/storage/" + pac + "/users/" + uid + "/'"));
proc.appendProcessor(new ShellProcessor("salt-call state.sls pacs >/dev/null 2>&1"));
return proc;
}
return null;
@ -76,28 +79,6 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
aCP.appendProcessor(new ShellProcessor("chmod 700 " + user.getHomedir()));
}
private void appendSetQuotaProcessor(CompoundProcessor aCP, UnixUser user) {
Integer quotaSoft = user.getQuotaSoftlimit();
if (quotaSoft == null) {
quotaSoft = Integer.valueOf(0);
} else {
quotaSoft = quotaSoft * 1024;
}
if (quotaSoft.intValue() == 0) {
aCP.appendProcessor(new ShellProcessor(
"setquota -u " + user.getName() + " 0 0 0 0 " + "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
return;
}
Integer quotaHard = user.getQuotaHardlimit();
if (quotaHard == null) {
quotaHard = Integer.valueOf(0);
} else {
quotaHard = quotaHard * 1024;
}
aCP.appendProcessor(new ShellProcessor("setquota -u " + user.getName() + " " + quotaSoft + " " + quotaHard
+ " 0 0 " + "`df /home/pacs/ | tail -n1 | cut -d' ' -f1`"));
}
private void appendMakeMaildirProcessor(CompoundProcessor aCP, UnixUser user) {
aCP.appendProcessor(
new ShellProcessor(