Skip to content

Commit

Permalink
Restart command and logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seizoxu committed Nov 11, 2023
1 parent 2fa2f63 commit 43dc9b5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.seizoxu.zyenyo</groupId>
<artifactId>zyenyo</artifactId>
<version>0.3.02-beta</version>
<version>0.3.03-beta</version>
<name>ZyenyoBot</name>

<properties>
Expand Down
19 changes: 16 additions & 3 deletions pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

cd $BOT_DIR

git pull origin stable
#git pull origin stable

rm target/*.jar
mvn package
pkill java
pkill -f "java -cp $jarfile zyenyo.Zyenyo $BOT_TOKEN $MONGO_URI $ZYENYO_ENVIRONMENT"

jarfile=$(find target/ -name zyenyo-*.*.*.jar)

java -cp $jarfile zyenyo.Zyenyo $BOT_TOKEN $MONGO_URI $ZYENYO_ENVIRONMENT &
echo "[TERM] Starting Zyenyo..."
java -cp $jarfile zyenyo.Zyenyo $BOT_TOKEN $MONGO_URI $ZYENYO_ENVIRONMENT

while true; do
if [ -e "zbflag-restart" ]; then
echo "[TERM] Restarting Zyenyo..."
rm "zbflag-restart"
pkill -f "java -cp $jarfile zyenyo.Zyenyo $BOT_TOKEN $MONGO_URI $ZYENYO_ENVIRONMENT"
java -cp $jarfile zyenyo.Zyenyo $BOT_TOKEN $MONGO_URI $ZYENYO_ENVIRONMENT
else
echo "[TERM] Shutting Down..."
break
fi
done
30 changes: 27 additions & 3 deletions src/main/java/commands/Administrator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package commands;

import asynchronous.typing.AddTest;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import asynchronous.typing.AddPrompt;
import asynchronous.typing.AddTest;
import asynchronous.typing.ClearProfile;
import asynchronous.typing.FindCheaters;
import asynchronous.typing.RefreshUsers;
Expand All @@ -13,8 +18,8 @@
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import zyenyo.BotConfig;
import zyenyo.CalculatePromptDifficulty;
import zyenyo.Zyenyo;
import zyenyo.Database;
import zyenyo.Zyenyo;

public class Administrator extends ListenerAdapter
{
Expand Down Expand Up @@ -98,7 +103,26 @@ public void run()
}
});
}


else if (Aliases.RESTART.contains(args[0].toLowerCase()))
{
channel.sendMessageFormat("A restart has been scheduled.").queue();

File restartFlagFile = new File("zbflag-restart");

try
{
restartFlagFile.createNewFile();

channel.sendMessageFormat("Shutting down...").queue();
event.getJDA().shutdown();
}
catch (IOException e)
{

}
}

else if (Aliases.SHUTDOWN.contains(args[0].toLowerCase()))
{
channel.sendMessageFormat("Shutting down...").queue();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dataStructures/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class Aliases
|————————————————ADMIN————————————————|
|————————————————————————————————————*/
public final static Set<String> SHUTDOWN = Collections.singleton(BotConfig.PREFIX + "shutdown");
public final static Set<String> RESTART = Collections.singleton(BotConfig.PREFIX + "restart");
public final static Set<String> ADDTEST = Collections.singleton(BotConfig.PREFIX + "addtest");
public final static Set<String> CLEARPROFILE = Collections.singleton(BotConfig.PREFIX + "clearprofile");
public final static Set<String> FINDCHEATERS = Collections.singleton(BotConfig.PREFIX + "findcheaters");
Expand Down
8 changes: 8 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd $BOT_DIR

logstamp=$(date +%Y%m%d-%H%M%S)
mkdir -p logs/

BOT_DIR=$BOT_DIR BOT_TOKEN=$BOT_TOKEN MONGO_URI=$MONGO_URI ZYENYO_ENVIRONMENT=$ZYENYO_ENVIRONMENT ./pull.sh > logs/$logstamp.log 2>&1 &

0 comments on commit 43dc9b5

Please sign in to comment.