Skip to content

Added redeploy command#195

Merged
MoonTM-GIT merged 3 commits intomainfrom
moon/redeploy
Jan 31, 2022
Merged

Added redeploy command#195
MoonTM-GIT merged 3 commits intomainfrom
moon/redeploy

Conversation

@MoonTM-GIT
Copy link
Copy Markdown
Member

@MoonTM-GIT MoonTM-GIT commented Jan 31, 2022

So, I've created a redeploy command. This might not be the ideal approach but it's the easiest and works very well if everything is set up correctly. Closes #35

For this to work, you need some kind of way to start the bot again if it stops. Before that happens you can then run a script recompiling the bot with the latest GitHub version. I'll show how we do it below.

Example

We're running the bot on a Debian 11 VPS, we have a systemd service set up that looks something like this:

[Unit]
Description=Java Discord Bot

[Service]
User=<USER>
WorkingDirectory=/home/<USER>/JavaBot
ExecStartPre=bash <REDEPLOY-SCRIPT.sh>
ExecStart=java -jar JavaBot-all.jar
Restart=always

[Install]
WantedBy=multi-user.target

As you can see, the service will run a bash script before actually starting the bot. This script looks like this:

cd /home/<USER>
sudo rm -rf <CLONE-FOLDER>

gh repo clone Java-Discord/JavaBot <CLONE-FOLDER>

cd <CLONE-FOLDER>
sudo bash gradlew :shadowJar

sudo mv /home/<USER>/JavaBot/JavaBot-all.jar /home/<USER>/JavaBot/JavaBot-old.jar
sudo mv /home/<USER>/<CLONE-FOLDER>/build/libs/JavaBot-1.0.0-SNAPSHOT-all.jar /home/<USER>/JavaBot/JavaBot-all.jar

This clones the repository into <CLONE-FOLDER> and recompiles it. Then the old jar is moved and replaced with the newly compiled one. When this is finished the service will run the jar.

@MoonTM-GIT MoonTM-GIT merged commit b3fb64a into main Jan 31, 2022
@MoonTM-GIT MoonTM-GIT deleted the moon/redeploy branch January 31, 2022 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Redeployment Command

2 participants