forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.java
More file actions
executable file
·88 lines (78 loc) · 2.41 KB
/
Copy pathservice.java
File metadata and controls
executable file
·88 lines (78 loc) · 2.41 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package javaforce.utils;
/**
* Created : July 9, 2012
*
* @author pquiring
*/
import java.util.*;
import javaforce.*;
import javaforce.jbus.*;
public class service {
public static void usage() {
System.out.println("jservice <name> <command>\n --status-all = show all services\n command = start | stop | status | restart\n");
System.exit(1);
}
public static void statusAll() {
Random r = new Random();
int id = Math.abs(r.nextInt());
JBusClient client = new JBusClient("org.jflinux.servicemanager.j" + id, new JBusMethods());
client.start();
client.call("org.jflinux.jsystemmgr", "serviceStatusAll", "\"" + client.pack + "\"");
//wait 4 ever
while (true) {
JF.sleep(5000);
}
}
public static void runCommand(String svc, String cmd) {
Random r = new Random();
int id = Math.abs(r.nextInt());
JBusClient client = new JBusClient("org.jflinux.servicemanager.j" + id, new JBusMethods());
client.start();
if (cmd.equals("start")) {
System.out.println("Requested Service:" + svc + ":start");
client.call("org.jflinux.jsystemmgr", "startService", "\"" + svc + "\"");
} else if (cmd.equals("stop")) {
System.out.println("Requested Service:" + svc + ":stop");
client.call("org.jflinux.jsystemmgr", "stopService", "\"" + svc + "\"");
} else if (cmd.equals("status")) {
System.out.println("Requested Service:" + svc + ":status");
client.call("org.jflinux.service." + svc, "status", "\"" + client.pack + "\"");
//wait upto 5 secs
JF.sleep(5000);
System.out.println("no response");
} 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);
}
public static class JBusMethods {
public void serviceStatusAll(String status) {
System.out.println(status.replaceAll("[|]", "\n"));
System.exit(1);
}
public void serviceStatus(String status) {
System.out.println(status.replaceAll("[|]", "\n"));
System.exit(1);
}
}
}