Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Jul 20, 2017
2 parents ae2106e + 8d6b155 commit 1590007
Show file tree
Hide file tree
Showing 47 changed files with 746 additions and 332 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ nbproject/private/
run.bat
target/
.nb-gradle/
/dependency-reduced-pom.xml
*/dependency-reduced-pom.xml
*credentials.json
*credentials.yaml
*tokens.json
Expand All @@ -132,3 +132,4 @@ target/
/music_persistence/
/bootloader.json
gc-*.log
*dbconf.yaml
38 changes: 23 additions & 15 deletions FredBoat-Bootloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>fredboat</groupId>
<artifactId>FredBoat-Root</artifactId>
<version>1.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.frederikam</groupId>
<artifactId>FredBoat-Bootloader</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<start-class>fredboat.bootloader.Bootloader</start-class>
</properties>

<dependencies>
<dependency>
<!-- fredboat internal shared library -->
<groupId>fredboat</groupId>
<artifactId>Shared</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -51,7 +67,7 @@
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.frederikam.fredboat.bootloader.Bootloader</Main-Class>
<Main-Class>fredboat.bootloader.Bootloader</Main-Class>
</manifestEntries>
</transformer>
</transformers>
Expand All @@ -61,12 +77,4 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
*
* MIT License
*
* Copyright (c) 2017 Frederik Ar. Mikkelsen
Expand All @@ -20,42 +21,43 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.frederikam.fredboat.bootloader;
package fredboat.bootloader;

import fredboat.shared.constant.ExitCodes;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Scanner;
import org.json.JSONArray;
import org.json.JSONObject;

public class Bootloader {

private static JSONArray command;
private static String jarName;
private static int recentBoots = 0;
private static long lastBoot = 0L;

public static void main(String[] args) throws IOException, InterruptedException {
OUTER:
while (true) {
InputStream is = new FileInputStream(new File("./bootloader.json"));
Scanner scanner = new Scanner(is);
JSONObject json = new JSONObject(scanner.useDelimiter("\\A").next());
scanner.close();

command = json.getJSONArray("command");
jarName = json.getString("jarName");

Process process = boot();
process.waitFor();
System.out.println("[BOOTLOADER] Bot exited with code " + process.exitValue());

switch (process.exitValue()) {
case ExitCodes.EXIT_CODE_UPDATE:
System.out.println("[BOOTLOADER] Now updating...");
Expand All @@ -65,7 +67,7 @@ public static void main(String[] args) throws IOException, InterruptedException
case ExitCodes.EXIT_CODE_NORMAL:
System.out.println("[BOOTLOADER] Now shutting down...");
break OUTER;
//SIGINT received or clean exit
//SIGINT received or clean exit
default:
System.out.println("[BOOTLOADER] Now restarting..");
break;
Expand All @@ -75,28 +77,28 @@ public static void main(String[] args) throws IOException, InterruptedException

private static Process boot() throws IOException {
//Check that we are not booting too quick (we could be stuck in a login loop)
if(System.currentTimeMillis() - lastBoot > 3000 * 1000){
if (System.currentTimeMillis() - lastBoot > 3000 * 1000) {
recentBoots = 0;
}

recentBoots++;
lastBoot = System.currentTimeMillis();
if(recentBoots >= 4){

if (recentBoots >= 4) {
System.out.println("[BOOTLOADER] Failed to restart 3 times, probably due to login errors. Exiting...");
System.exit(-1);
}

//ProcessBuilder pb = new ProcessBuilder(System.getProperty("java.home") + "/bin/java -jar "+new File("FredBoat-1.0.jar").getAbsolutePath())
ProcessBuilder pb = new ProcessBuilder()
.inheritIO();
ArrayList<String> list = new ArrayList<>();
command.forEach((Object str) -> {
list.add((String) str);
});

pb.command(list);

Process process = pb.start();
return process;
}
Expand Down
1 change: 0 additions & 1 deletion FredBoat/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/logs/
/bootloader.json
/dependency-reduced-pom.xml
/music_persistence/
/credentials_test.json
/credentials.json.old
Expand Down
12 changes: 6 additions & 6 deletions FredBoat/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
patron: false
development: true # Set this to true for self hosting
prefix: '<<' # Default prefix used by the bot
restServerEnabled: true # Change this if you are running multiple FredBoat bots on the same machine
admins: [] # add comma separated userIds and roleIds that should have access to admin commands
useAutoBlacklist: true # set to true to automatically blacklist users who frequently hit the rate limits
patron: false # Set this to true for self hosting the music bot
development: true # Set this to true for self hosting the full bot (including non music commands)
prefix: '<<' # Default prefix used by the bot
restServerEnabled: true # Set this to false if you are running multiple FredBoat bots on the same machine
admins: [] # add comma separated userIds and roleIds that should have access to bot admin commands
useAutoBlacklist: true # set to true to automatically blacklist users who frequently hit the rate limits
2 changes: 2 additions & 0 deletions FredBoat/feature_flags.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
# example to turn a feature on (uncomment it):
#RATE_LIMITER=false
#CHATBOT=false
#DATA_METHODS=false
PERMISSIONS=false
Loading

0 comments on commit 1590007

Please sign in to comment.