I'm creating a minigame plugin and I thought of a small hack that might allow me to restart the server without stopping the server and editing the server bat file to make it loop back to the start and start it again. Wouldn't it be possible to do this: I use ping to make it sleep for 15 seconds before starting the server up again. Code (Text): Runtime r = Runtime.getRuntime(); r.exec("ping -n 15 localhost>nul\njava -Xmx12288M -Xms512M -jar spigot.jar -log-strip-color"); Bukkit.getServer().shutdown(); My questions: Will it even work? Is there a better way to do this? [Edit] I'm at school at the moment so I can't test my self. But if anyone wants to see if this little hack would work, feel free. I think it'd be really useful.
Lol. No, I'm at school. Can't yet. Thought I'd just create a thread quickly to see what people think.
Using a subprocess is fine but you need to add a shutdown hook which manually enforces System#exit if you want to ensure the parent process exits before yours begins
Looks like a really ugly solution to me. Sure, it may work, but I can also slice bread with a fork if I want to. Not exactly an elegant method, though.
Tested: Code (Text): @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (label.equals("test")) { Runtime r = Runtime.getRuntime(); try { r.exec("ping -c 15 localhost>nul; sh \"/home/william/Desktop/Plugin Development/Test server/spigot.sh\""); } catch (IOException e) { e.printStackTrace(); } Bukkit.getServer().shutdown(); return true; } return false; } Didn't work. It just stopped the server and didn't restart. (This is in linux. Havn't tested with Windows.) How? Maybe explain in a bit more detail. I don't have any experiences in "hooks". (googling atm) How would you come to a solution then?