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