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