Libraryless. Click here for Pure Java version (5306L/37K/121K).
!752 m { static new L<S> programsToStart; static new L<Boot> bootLog; static int sleepTime = 60; static new Flag stop; static new Flag booted; static boolean stayAliveAfterBoot = false; !include #1000915 // Flag class static class Boot { long when; S uptime; } p { if (args.length != 0 && args[0].equals("nosleep")) sleepTime = 0; readLocally("programsToStart"); readLocally("bootLog"); makeAndroid3("Boot Bot."); new Boot b; b.when = now(); b.uptime = backtick(isWindows() ? "systeminfo" : "uptime"); bootLog.add(b); saveLocally("bootLog"); print("Booting at: " + b.when + ", uptime: " + b.uptime); print(); print("PID: " + getPID() + ". BOOT BOT sleeping for 60 to be possibly killed before really doing something (starting these programs: " + structure(programsToStart) + ")."); sleepSeconds(sleepTime); // Allow someone higher up :o)))) to "kill" me print("Bot Boot waking up."); if (stop.isUp()) print("Boot cancelled."); else { int i = 1; for (S program : programsToStart) { print("Starting program " + i + "/" + programsToStart.size() + ": " + program); ++i; nohupJavax(program); sleepSeconds(5); } booted.raise(); print("Done starting programs."); } if (stayAliveAfterBoot) { print("Sleeping as bot."); sleep(); } else { print("Exiting."); System.exit(0); } } static synchronized S answer(S s, L<S> history) { new Matches m; if (match3("please add program * to boot list.", s, m)) { S p = unquote(m.m[0]); boolean isNew = !programsToStart.contains(p); if (isNew) { programsToStart.add(p); saveLocally("programsToStart"); nohupJavax(p); } return isNew ? "OK, added and started." : "OK, was there already."; } if (match3("please remove program * from boot list.", s, m)) { S p = unquote(m.m[0]); programsToStart.remove(p); saveLocally("programsToStart"); return "OK, removed."; } if (match3("stop", s) || match3("stop boot", s) || match3("stop booting", s)) { stop.raise(); return "OK, boot cancelled."; } if (match3("have you booted", s)) return booted.isUp() ? "yes" : (stop.isUp() ? "no, boot was stopped" : "not yet but soon"); if (match3("reboot", s)) { final S cmd = isWindows() ? "shutdown -t 5 -r" : "reboot"; print(cmd); S answer = "Rebooting in 5 seconds!"; thread { sleepSeconds(5); backtick(cmd); } return answer; } S answer = standardQuery(s, "programsToStart"); if (answer == null) answer = additionalQuery(s, "bootLog", "boot"); return answer; } }
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 |