From 50111cf9520ac74f3e848cd1f3fc58c855d9ef7b Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 13 Feb 2023 18:51:57 +0100 Subject: [PATCH 1/6] Service doumentation --- docs/running-as-a-service.md | 121 +++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 docs/running-as-a-service.md diff --git a/docs/running-as-a-service.md b/docs/running-as-a-service.md new file mode 100644 index 000000000..9c3d77116 --- /dev/null +++ b/docs/running-as-a-service.md @@ -0,0 +1,121 @@ +--- +title: Running as a service +description: "How to run JMusicBot as a service, so that it can run in the background without needing to be manually started." +--- + +## Running as a service +Running JMusicBot as a service allows it to run in the background without needing to be manually started. This is useful for running the bot on a server, or if you want to be able to close your terminal without stopping the bot. + +### Linux using systemd + +!!! warning + This method assumes that you've created a user for the bot to run as. If you haven't, see [this guide](https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart) for instructions. + +!!! note + Copy the jar file to the home directory of the user that the bot is running as, or change the `WorkingDirectory` and `ExecStart` lines in the service file to point to the correct location. + +1. Open a terminal and run the following command to create a new service file: + +```bash +sudo nano /etc/systemd/system/JMusicBot.service +``` + +2. Copy the following text into the file and save it: + +```ini +[Unit] +Description=JMusicBot +After=network.target + +[Service] +WorkingDirectory=/home/ +User= +Group= +Type=simple +ExecStart=/usr/bin/java -Dnogui=true -jar /home//JMusicBot.jar +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target +``` + +!!! note + Replace `` with the name of the user that the bot is running as. + +4. Run the following command to start the bot: + +```bash +sudo systemctl start JMusicBot +``` + +5. Run the following command to stop the bot: + +```bash +sudo systemctl stop JMusicBot +``` + +6. Run the following command to restart the bot: + +```bash +sudo systemctl restart JMusicBot +``` + +7. Run the following command to enable the bot to start on boot: + +```bash +sudo systemctl enable JMusicBot +``` + + +### Linux using screen + +!!! warning + This method is not recommended for production use, see [systemd](#linux-using-systemd) instead. + +1. Install the [screen](https://www.howtoforge.com/linux_screen) utility, if it isn't already installed. +2. Run the following command to start the bot: + +```bash +screen -dmS JMusicBot java -jar JMusicBot.jar +``` + +3. Run the following command to stop the bot: + +```bash +screen -S JMusicBot -X quit +``` + +4. Run the following command to restart the bot: + +```bash +screen -S JMusicBot -X quit +screen -dmS JMusicBot java -jar JMusicBot.jar +``` + +### Windows + +1. Download the [NSSM](https://nssm.cc/download) executable and place it in the same directory as the JMusicBot jar file. +2. Open a command prompt in the same directory as the JMusicBot jar file and run the following command: + +```bat +nssm install JMusicBot java -jar JMusicBot.jar +``` + +3. Run the following command to start the service: + +```bat +nssm start JMusicBot +``` + +4. Run the following command to stop the service: + +```bat +nssm stop JMusicBot +``` + +5. Run the following command to remove the service: + +```bat +nssm remove JMusicBot +``` \ No newline at end of file From 7d3f728f6800fa0db2eb91a8bc5890b2d3b8268c Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 13 Feb 2023 18:58:43 +0100 Subject: [PATCH 2/6] remove references to nohup --- docs/setup.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/setup.md b/docs/setup.md index 3e6aa7d2e..bc0378111 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -29,10 +29,12 @@ prefix = "!" * Run the jar file (choose one of these options): * Double-click the jar file (on desktop environments), OR * Run `java -Dnogui=true -jar JMusicBot-X.Y.Z.jar` from the command line (replace X, Y, and Z with the release numbers), OR - * Run `nohup java -Dnogui=true -jar JMusicBot-X.Y.Z.jar &` to run in the background (Linux only) * Provide the requested information, if prompted. * Wait for the "Finished Loading" message. +!!! tip + If you want to run the bot in the background, see [Running as a Service](running-as-a-service.md) + ## 5️⃣ Add your bot to your server * When the bot starts, if it hasn't been added to any servers yet, it will provide you with a link in the console. * Alternatively, follow these instructions (with images): [Adding Your Bot To Your Server](adding-your-bot.md) \ No newline at end of file From c685be64bf8cc3f46db0bb0fb03595c22c0fcf56 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 13 Feb 2023 18:59:52 +0100 Subject: [PATCH 3/6] add navigation ref --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 596e59c62..dc720023d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -57,6 +57,7 @@ nav: - config.md - advanced-config.md - hosting.md + - running-as-a-service.md - Reference: - commands.md - playlists.md From 7e01450d1910ba482651533b702e0d156982a430 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 13 Feb 2023 19:02:25 +0100 Subject: [PATCH 4/6] grammar --- docs/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/setup.md b/docs/setup.md index bc0378111..7bbb08ecc 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -28,7 +28,7 @@ prefix = "!" ## 4️⃣ Run JMusicBot * Run the jar file (choose one of these options): * Double-click the jar file (on desktop environments), OR - * Run `java -Dnogui=true -jar JMusicBot-X.Y.Z.jar` from the command line (replace X, Y, and Z with the release numbers), OR + * Run `java -Dnogui=true -jar JMusicBot-X.Y.Z.jar` from the command line (replace X, Y, and Z with the release numbers) * Provide the requested information, if prompted. * Wait for the "Finished Loading" message. From 971b0f55d6af3b1b779432093fcc5af542c83e95 Mon Sep 17 00:00:00 2001 From: Remco Jongschaap Date: Mon, 13 Feb 2023 19:17:15 +0100 Subject: [PATCH 5/6] Update docs/running-as-a-service.md Co-authored-by: M R S E <25187502+Sanduhr32@users.noreply.github.com> --- docs/running-as-a-service.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/running-as-a-service.md b/docs/running-as-a-service.md index 9c3d77116..243574718 100644 --- a/docs/running-as-a-service.md +++ b/docs/running-as-a-service.md @@ -25,6 +25,7 @@ sudo nano /etc/systemd/system/JMusicBot.service ```ini [Unit] Description=JMusicBot +Wants=network.target After=network.target [Service] @@ -32,7 +33,7 @@ WorkingDirectory=/home/ User= Group= Type=simple -ExecStart=/usr/bin/java -Dnogui=true -jar /home//JMusicBot.jar +ExecStart=/usr/bin/env java -Dnogui=true -jar JMusicBot.jar Restart=always RestartSec=10 From 76291cab1e370050cfe87d50bc3e796f3893bdab Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 13 Feb 2023 19:30:49 +0100 Subject: [PATCH 6/6] wants > requires --- docs/running-as-a-service.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/running-as-a-service.md b/docs/running-as-a-service.md index 243574718..1b2ab8867 100644 --- a/docs/running-as-a-service.md +++ b/docs/running-as-a-service.md @@ -25,7 +25,7 @@ sudo nano /etc/systemd/system/JMusicBot.service ```ini [Unit] Description=JMusicBot -Wants=network.target +Requires=network.target After=network.target [Service]