Jump to content
  • 0
Sign in to follow this  
PwntNoob

PI Shutdown Hook - Auto Restarting

Question

[B]Time to make myself look like a right noob[/B]
[MENTION=198095]falconpunch[/MENTION]

ShutDownHook Class:
[CODE]package core.util;

import java.io.IOException;

import server.game.players.Client;
import server.Server;
import server.game.players.PlayerHandler;

public class ShutDownHook extends Thread {

[MENTION=15855]Over[/MENTION]ride
public void run() {
System.out.println("[RunePwn] Anti-Roll Back Prevention..");
for (int j = 0; j < PlayerHandler.players.length; j++) {
if (PlayerHandler.players[j] != null) {
Client c = (Client)PlayerHandler.players[j];
server.game.players.PlayerSave.saveGame(c);
}
}
System.out.println("[RunePwn] Server Crashed.. Restarting..");
try {
Server.main(null);
} catch (NullPointerException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}[/CODE]

[B]Explanation:[/B]
I am trying to make it automatically restart the server once it crashes, so then if worse comes to worst I don't have to worry about downtime. I have done this so far, got it all good no errors etc. But when I test the hook, It trys restarting the server before the previous prompt finishes. So it then says bind error etc, port already in use blah blah blah...

I'm not in the thinking or coding mood tonight so I thought i'd just post it here like a noob haha. Someone let me know if you have any ideas on how to fix this shit. I was thinking make a new class and make it like run a method from it once the server is offline. For example...
[CODE]System.out.printLn("Server Crashed, Restarting...");
newclass.Run();
System.exit(0); Maybe??
[/CODE]

Please let me know your thoughts.. Edited by PwntNoob

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
i dont know anything about this but when you think about it
a dead server cannot revive itself so you would have to have a process in the backround
always alive keeping it running, not using any ports, just something holding it together like jrebel
i can't help further but gl!

Share this post


Link to post
Share on other sites
  • 0
[quote name='OP411']i dont know anything about this but when you think about it
a dead server cannot revive itself so you would have to have a process in the backround
always alive keeping it running, not using any ports, just something holding it together like jrebel
i can't help further but gl![/QUOTE]

Well it doesn't fetch the port or allow connections until the loading is complete. That's why I added System.exit(0) then made it run the Server.main thread. I see where you are coming from though. I'll work it out.

Share this post


Link to post
Share on other sites
  • 0
Well, I don't know where it's crashing for you, and like what [MENTION=246899]OP411[/MENTION] said, a dead server can't just start back up, so what you could do, is use a auto restart, that restarts the server every couple of hours or so.
This is from Adrastos 667 (which me and Gircat worked on)

[CODE]
public static boolean restarting;
private static void addAutoRestartTask() {
CoresManager.slowExecutor.schedule(new Runnable() {
[MENTION=15855]Over[/MENTION]ride
public void run() {
safeShutdown(true, 126);
restarting = true;
World.sendWorldMessage("<col=FF0033>Auto-restart has been activated.", false);
}
}, 5, TimeUnit.HOURS);
}
[/CODE]

under your server init, add restarting = false;
That's world.java ^^

This is launcher.java
public static long nextRestart;
[CODE]
public static void restart() {
closeServices();
System.gc();
try {
Runtime.getRuntime().exec("java -server -Xms2048m -Xmx3000m -cp bin;/data/libs/netty-3.2.7.Final.jar;/data/libs/FileStore.jar Launcher true true false");
//Runtime.getRuntime().exec("java -server -Xmx815m -cp bin;lib/*; com.rs.Launcher true true false");
System.exit(2);
} catch (Throwable e) {
Logger.handle(e);
}

}
[/CODE]

Share this post


Link to post
Share on other sites
  • 0
The isn't any issues with the server crashing. I just wanted to try and implement it just incase it did crash.

Cheers for the auto restarter, but I probably won't use it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×