forked from ChomeNS/chomens-bot-java
backup thingy
This commit is contained in:
parent
fec4f20420
commit
dc5a62540b
3 changed files with 46 additions and 0 deletions
|
@ -15,6 +15,8 @@ public class Configuration {
|
|||
|
||||
public InternetCheck internetCheck = new InternetCheck();
|
||||
|
||||
public Backup backup = new Backup();
|
||||
|
||||
public String weatherApiKey;
|
||||
|
||||
public Core core = new Core();
|
||||
|
@ -35,6 +37,11 @@ public class Configuration {
|
|||
public String address = "https://sus.red";
|
||||
}
|
||||
|
||||
public static class Backup {
|
||||
public boolean enabled = false;
|
||||
public String address = "http://fard.sex/check";
|
||||
}
|
||||
|
||||
public static class Keys {
|
||||
public String normalKey;
|
||||
public String ownerKey;
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.yaml.snakeyaml.Yaml;
|
|||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -38,6 +39,8 @@ public class Main {
|
|||
|
||||
private static Configuration config;
|
||||
|
||||
private static boolean alreadyStarted = false;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
final Path configPath = Path.of("config.yml");
|
||||
|
||||
|
@ -79,6 +82,33 @@ public class Main {
|
|||
}
|
||||
}, 0, 1, TimeUnit.MINUTES);
|
||||
|
||||
if (!config.backup.enabled) {
|
||||
initializeBots();
|
||||
return;
|
||||
}
|
||||
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
boolean reachable;
|
||||
|
||||
try {
|
||||
reachable = InetAddress.getByName(config.backup.address).isReachable(5000);
|
||||
} catch (IOException e) {
|
||||
reachable = false;
|
||||
}
|
||||
|
||||
if (!reachable) {
|
||||
LoggerUtilities.info("Main instance is down! Starting backup instance");
|
||||
|
||||
initializeBots();
|
||||
} else if (alreadyStarted) {
|
||||
System.exit(1);
|
||||
}
|
||||
}, 0, 1, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public static void initializeBots() {
|
||||
alreadyStarted = true;
|
||||
|
||||
Configuration.BotOption[] botsOptions = config.bots;
|
||||
|
||||
// idk if these should be here lol, but it is just the discord stuff
|
||||
|
|
|
@ -13,6 +13,15 @@ internetCheck:
|
|||
enabled: true
|
||||
address: 'https://sus.red'
|
||||
|
||||
# how backup works is that it checks for the address every 1 minute,
|
||||
# if the address is reachable it will not start the bot
|
||||
# if the address is not reachable then it will start the bot
|
||||
#
|
||||
# if the bot has already been started and address is back up it will stop the bot (using System.exit(1))
|
||||
backup:
|
||||
enabled: false
|
||||
address: '192.168.1.169'
|
||||
|
||||
discord:
|
||||
enabled: false
|
||||
prefix: 'default!'
|
||||
|
|
Loading…
Reference in a new issue