Running multiple bots on a single server has been a very popular demand on our bot service, today we shall cover the steps in order to get started on how to configure the server and working environment to adapt to it.
- A server configured for discord bots.
- Very basic knowledge of bash files.
- The bots source code which is required to run, uploaded on the server, properly separated in each folder
For our demonstration purpose today, we shall follow the following file structure below:
/home/container — alpha --- package.json --- index.js — beta --- main.py - bash.sh
Step 1 - Getting started with the bash script
The server boots up with a startup command, since running multiple commands in it causes issues, we shall proceed by creating a bash script that has all the commands that would be called instead.
Upload a file into the root directory named as “run.sh” with the following content as shown below adjusted to your needs.
Please do ensure that the below bash commands get replaced to how your program has to execute.
Below there are two options to choose from which will be explained.
#!/usr/bin/env bash cd alpha && node index.js & cd beta && python3 main.py
#!/usr/bin/env bash node alpha/index.js & python3 beta/main.py
Option A runs the programs after moving over to the specified folders, hence this method does not mess up any used paths and no further file changes is required.
Option B runs the programs on the root directory which houses the bash script as well, due to this at times the working directory changes for the programs and hence there would be a need for one to update their files to accommodate for new relative paths.
- The & operator used here is to indicate to bash to run these two commands as background processes.
- The && operator which is used to execute two commands one after another. If the first fails then the second won't execute.
Step 2 - Change each bot file paths.
Since we are running the bot from the root directory of the server, we must accommodate for this by changing each of the files of the multiple bot files to the current relative path in respect to the root directory.
For example if you were importing/requiring the “package.json” file, instead of the path ./package.json it would become ./alpha/package.json.
Step 3 - Changing the startup parameters
After completing the above steps, now we can tell the server to always boot up running the bash script first.
Below explains the steps as to how one would do so:
- Access the WISP Server Panel for your bot at: https://panel.cubes.host
- Select your server from the list of servers.
- Navigate to the category named as Configuration and under it to the sub-category named as Startup Parameters.
- Under the second container named as “Startup command” change it to: bash run.sh
- Save your changes.
Step 4 - Restarting the server.
Now access the console section of the server by navigating to the category named System, under it to the sub-category named Console.
Under the terminal there are four buttons, click on the second one named as “Restart” to restart the server.
Now, the server will consider all the changes made and boot with the bash script.
If you have been following the steps, the server should boot up successfully without any issues and all your bots should work as intended.
Feel free to contact our support team if you do come across any issues.