Skip to content

Commit

Permalink
Merge pull request #1292 from Dougley/gh-pages
Browse files Browse the repository at this point in the history
Add documentation for running JMusicBot as a service
  • Loading branch information
jagrosh authored Feb 14, 2023
2 parents 6808319 + 76291ca commit ba3bbee
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
122 changes: 122 additions & 0 deletions docs/running-as-a-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
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
Requires=network.target
After=network.target

[Service]
WorkingDirectory=/home/<username>
User=<username>
Group=<username>
Type=simple
ExecStart=/usr/bin/env java -Dnogui=true -jar JMusicBot.jar
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

!!! note
Replace `<username>` 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
```
6 changes: 4 additions & 2 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ 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 `nohup java -Dnogui=true -jar JMusicBot-X.Y.Z.jar &` to run in the background (Linux only)
* 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.

!!! 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)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ nav:
- config.md
- advanced-config.md
- hosting.md
- running-as-a-service.md
- Reference:
- commands.md
- playlists.md
Expand Down

0 comments on commit ba3bbee

Please sign in to comment.