Libraryless. Click here for Pure Java version (5306L/37K/121K).
1 | !752 |
2 | |
3 | m { |
4 | static new L<S> programsToStart; |
5 | static new L<Boot> bootLog; |
6 | static int sleepTime = 60; |
7 | static new Flag stop; |
8 | static new Flag booted; |
9 | |
10 | static boolean stayAliveAfterBoot = false; |
11 | |
12 | !include #1000915 // Flag class |
13 | |
14 | static class Boot { |
15 | long when; |
16 | S uptime; |
17 | } |
18 | |
19 | p { |
20 | if (args.length != 0 && args[0].equals("nosleep")) |
21 | sleepTime = 0; |
22 | |
23 | readLocally("programsToStart"); |
24 | readLocally("bootLog"); |
25 | |
26 | makeAndroid3("Boot Bot."); |
27 | |
28 | new Boot b; |
29 | b.when = now(); |
30 | b.uptime = backtick(isWindows() ? "systeminfo" : "uptime"); |
31 | bootLog.add(b); |
32 | saveLocally("bootLog"); |
33 | |
34 | print("Booting at: " + b.when + ", uptime: " + b.uptime); |
35 | print(); |
36 | |
37 | print("PID: " + getPID() + ". BOOT BOT sleeping for 60 to be possibly killed before really doing something (starting these programs: " + structure(programsToStart) + ")."); |
38 | |
39 | sleepSeconds(sleepTime); // Allow someone higher up :o)))) to "kill" me |
40 | |
41 | print("Bot Boot waking up."); |
42 | |
43 | if (stop.isUp()) |
44 | print("Boot cancelled."); |
45 | else { |
46 | int i = 1; |
47 | for (S program : programsToStart) { |
48 | print("Starting program " + i + "/" + programsToStart.size() + ": " + program); |
49 | ++i; |
50 | nohupJavax(program); |
51 | sleepSeconds(5); |
52 | } |
53 | booted.raise(); |
54 | print("Done starting programs."); |
55 | } |
56 | |
57 | if (stayAliveAfterBoot) { |
58 | print("Sleeping as bot."); |
59 | sleep(); |
60 | } else { |
61 | print("Exiting."); |
62 | System.exit(0); |
63 | } |
64 | } |
65 | |
66 | static synchronized S answer(S s, L<S> history) { |
67 | new Matches m; |
68 | if (match3("please add program * to boot list.", s, m)) { |
69 | S p = unquote(m.m[0]); |
70 | boolean isNew = !programsToStart.contains(p); |
71 | if (isNew) { |
72 | programsToStart.add(p); |
73 | saveLocally("programsToStart"); |
74 | nohupJavax(p); |
75 | } |
76 | return isNew ? "OK, added and started." : "OK, was there already."; |
77 | } |
78 | |
79 | if (match3("please remove program * from boot list.", s, m)) { |
80 | S p = unquote(m.m[0]); |
81 | programsToStart.remove(p); |
82 | saveLocally("programsToStart"); |
83 | return "OK, removed."; |
84 | } |
85 | |
86 | if (match3("stop", s) || match3("stop boot", s) || match3("stop booting", s)) { |
87 | stop.raise(); |
88 | return "OK, boot cancelled."; |
89 | } |
90 | |
91 | if (match3("have you booted", s)) |
92 | return booted.isUp() ? "yes" : (stop.isUp() ? "no, boot was stopped" : "not yet but soon"); |
93 | |
94 | if (match3("reboot", s)) { |
95 | final S cmd = isWindows() ? "shutdown -t 5 -r" : "reboot"; |
96 | print(cmd); |
97 | S answer = "Rebooting in 5 seconds!"; |
98 | thread { |
99 | sleepSeconds(5); |
100 | backtick(cmd); |
101 | } |
102 | return answer; |
103 | } |
104 | |
105 | S answer = standardQuery(s, "programsToStart"); |
106 | if (answer == null) answer = additionalQuery(s, "bootLog", "boot"); |
107 | return answer; |
108 | } |
109 | } |
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
ID | Author/Program | Comment | Date |
---|---|---|---|
1115 | stefan | See also: http://stackoverflow.com/questions/11809191/linux-launch-java-program-on-startup-ec2-instance | 2015-10-05 18:18:16 |
Snippet ID: | #1001224 |
Snippet name: | Boot Bot |
Eternal ID of this version: | #1001224/1 |
Text MD5: | 45f75e8ad7f735b03e7800c4fa83a812 |
Transpilation MD5: | f1616788c190fe61671e5216415bf67f |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-30 20:55:49 |
Source code size: | 2980 bytes / 109 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 970 / 1580 |
Referenced in: | [show references] |