more service commands
This commit is contained in:
parent
04e9442455
commit
ee4b71fc84
|
@ -1,6 +1,8 @@
|
||||||
package net.hyperic.sigar.cmd;
|
package net.hyperic.sigar.cmd;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.hyperic.sigar.SigarException;
|
import net.hyperic.sigar.SigarException;
|
||||||
import net.hyperic.sigar.win32.Service;
|
import net.hyperic.sigar.win32.Service;
|
||||||
|
@ -8,6 +10,14 @@ import net.hyperic.sigar.win32.Win32Exception;
|
||||||
|
|
||||||
public class Win32Service extends SigarCommandBase {
|
public class Win32Service extends SigarCommandBase {
|
||||||
|
|
||||||
|
private static final List COMMANDS =
|
||||||
|
Arrays.asList(new String[] {
|
||||||
|
"state",
|
||||||
|
"start",
|
||||||
|
"stop",
|
||||||
|
"restart",
|
||||||
|
});
|
||||||
|
|
||||||
public Win32Service() {
|
public Win32Service() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -37,19 +47,41 @@ public class Win32Service extends SigarCommandBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void output(String[] args) throws SigarException {
|
public void output(String[] args) throws SigarException {
|
||||||
|
Service service = null;
|
||||||
String name = args[0];
|
String name = args[0];
|
||||||
Service service = new Service(name);
|
String cmd = null;
|
||||||
if (args.length == 1) {
|
|
||||||
service.list(this.out);
|
if (args.length == 2) {
|
||||||
|
cmd = args[1];
|
||||||
}
|
}
|
||||||
else if (args[1].equals("start")) {
|
|
||||||
service.start();
|
try {
|
||||||
}
|
service = new Service(name);
|
||||||
else if (args[1].equals("stop")) {
|
|
||||||
service.stop();
|
if ((cmd == null) || cmd.equals("state")) {
|
||||||
}
|
service.list(this.out);
|
||||||
else {
|
}
|
||||||
throw new SigarException("Unsupported service command: " + args[1]);
|
else if (cmd.equals("start")) {
|
||||||
|
service.start();
|
||||||
|
}
|
||||||
|
else if (cmd.equals("stop")) {
|
||||||
|
service.stop();
|
||||||
|
}
|
||||||
|
else if (cmd.equals("delete")) {
|
||||||
|
service.delete();
|
||||||
|
}
|
||||||
|
else if (cmd.equals("restart")) {
|
||||||
|
service.stop(0);
|
||||||
|
service.start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println("Unsupported service command: " + args[1]);
|
||||||
|
println("Valid commands: " + COMMANDS);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (service != null) {
|
||||||
|
service.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue