]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.support/src/org/argeo/slc/lib/linux/RedhatHostManager.java
8b1c5e5053f60f42fa4a1f07a09de67fbeff95d1
[gpl/argeo-slc.git] / legacy / org.argeo.slc.support / src / org / argeo / slc / lib / linux / RedhatHostManager.java
1 package org.argeo.slc.lib.linux;
2
3 import org.argeo.slc.SlcException;
4 import org.argeo.slc.core.deploy.LocalFilesDeployment;
5 import org.argeo.slc.core.deploy.ResourceSet;
6 import org.argeo.slc.core.execution.tasks.SystemCall;
7 import org.argeo.slc.jsch.RemoteExec;
8 import org.argeo.slc.jsch.SshFilesDeployment;
9 import org.argeo.slc.jsch.SshTarget;
10
11 public class RedhatHostManager {
12
13 private SimpleLinuxHost host;
14
15 // SSH
16 private Boolean useSsh = true;
17 private SshTarget sshTarget = null;
18
19 public void installPackages() {
20 StringBuffer cmd = new StringBuffer("yum --nogpgcheck -y install");
21 for (String pkg : ((RpmDistribution) host.getDistribution())
22 .getAdditionalPackages()) {
23 cmd.append(' ').append(pkg);
24 }
25 executeCommand(cmd.toString());
26
27 RedhatDeploymentData rdd = (RedhatDeploymentData) host
28 .getDeploymentData();
29 executeCommand(rdd.getRunlevelsScript());
30 }
31
32 public void deployConfig() {
33 RedhatDeploymentData rdd = (RedhatDeploymentData) host
34 .getDeploymentData();
35 deploy(rdd.getConfigurationFiles());
36 executeCommand(rdd.getPermissionsScript());
37 }
38
39 // GENERIC?
40 protected void deploy(ResourceSet resourceSet) {
41 if (useSsh)
42 new SshFilesDeployment(getSshTarget(), resourceSet).run();
43 else
44 new LocalFilesDeployment(resourceSet).run();
45
46 }
47
48 protected void executeCommand(String command) {
49 if (command == null)
50 return;
51
52 if (useSsh) {
53 RemoteExec rExec = new RemoteExec(getSshTarget(), command);
54 rExec.setFailOnBadExitStatus(false);
55 rExec.run();
56 } else
57 new SystemCall(command).run();
58 }
59
60 protected SshTarget getSshTarget() {
61 if (sshTarget == null)
62 throw new SlcException("No SSH target defined");
63 return sshTarget;
64 }
65
66 public void setHost(SimpleLinuxHost host) {
67 this.host = host;
68 }
69
70 public void setUseSsh(Boolean useSsh) {
71 this.useSsh = useSsh;
72 }
73
74 public void setSshTarget(SshTarget sshTarget) {
75 this.sshTarget = sshTarget;
76 }
77
78 }