-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathservice.java
More file actions
executable file
·73 lines (66 loc) · 2.03 KB
/
Copy pathservice.java
File metadata and controls
executable file
·73 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package javaforce.utils;
import javaforce.*;
import javaforce.bus.*;
/**
* JF Service control CLI
*
* Created : July 9, 2012
*
* @author pquiring
*/
public class service {
public static void usage() {
System.out.println("jfservice <command> <service>\n --status-all = show all services\n command = start | stop | status | restart\n");
System.exit(1);
}
public static void statusAll() {
JBusClient client = new JBusClient(null);
client.connect();
String status = (String)client.invoke(SystemBusNames.system, "serviceStatusAll");
System.out.println(status.replaceAll("[|]", "\n"));
}
public static void runCommand(String cmd, String svc) {
JBusClient client = new JBusClient(null);
client.connect();
if (cmd.equals("start")) {
System.out.println("Requested Service:" + svc + ":start");
boolean res = (boolean)client.invoke(SystemBusNames.system, "startService", svc);
if (!res ) {
JFLog.log("Error:Failed to start service");
}
} else if (cmd.equals("stop")) {
System.out.println("Requested Service:" + svc + ":stop");
boolean res = (boolean)client.invoke(SystemBusNames.system, "stopService", svc);
if (!res ) {
JFLog.log("Error:Failed to start service");
}
} else if (cmd.equals("status")) {
System.out.println("Requested Service:" + svc + ":status");
String status = (String)client.invoke("javaforce.jflinux.service." + svc, "status");
System.out.println(status.replaceAll("[|]", "\n"));
} else if (cmd.equals("restart")) {
runCommand(svc, "stop");
JF.sleep(2500);
runCommand(svc, "start");
} else {
System.out.println("unknown command:" + cmd);
usage();
}
}
public static void main(String[] args) {
if (args.length == 0) {
usage();
}
if (args[0].equals("--help")) {
usage();
}
if (args[0].equals("--status-all")) {
statusAll();
}
if (args.length != 2) {
usage();
}
runCommand(args[0], args[1]);
System.exit(0);
}
}