Tauchen Sie ein in eine unvergleichliche Webwelt mit unseren innovativen Hosting-Lösungen!

Entdecken Sie zuverlässige, sichere und leistungsstarke Optionen, die all Ihren Online-Anforderungen gerecht werden.

Alle unsere Webhosting-Lösungen

Entdecken Sie unübertroffene Leistung mit unseren innovativen, maßgeschneiderten VPS-Servern!

Erleben Sie Freiheit und Leistung mit unseren VPS, die entwickelt wurden, um Ihre Projekte auf neue Höhen zu bringen!

Alle unsere VPS-Server

Optimieren Sie Ihre Bots mit unserem dedizierten, leistungsstarken und maßgeschneiderten Hosting!

Erleben Sie eine reibungslose Verwaltung und optimale Leistung mit unserem Bot-Hosting.

Alle unsere Bot-Angebote

Neues BoxGaming-Angebot

Entdecken Sie unser neuestes Angebot, verfügbar in unseren Rechenzentren in Frankreich und den USA. Mit einem einzigen Angebot können Sie den Servertyp jederzeit ändern.

Das Angebot entdecken
Optimieren Sie Ihre Spielserver mit unserem spezialisierten und leistungsstarken Hosting!

Tauchen Sie ein in das ultimative Gaming-Erlebnis mit unserem optimierten und leistungsstarken Hosting!

Alle unsere Minecraft-Angebote

How to run multiple bots with a single Node.js/Python Plan on OuiHeberg

In this tutorial, we will show you how to run multiple bots (or scripts) using a single plan on OuiHeberg. We will cover two methods: one using Node.js and another using Python. These approaches will allow you to execute multiple processes in parallel efficiently.

Part 1: For NodeJS bot hosting plans

Step 1: Create a new JavaScript file

Create a new JavaScript file, for example, launchBots.js, in the same directory as your bot scripts.

Step 2: Write the code to launch the files in parallel

Copy the following code into your launchBots.js file. This code uses the child_process module, included by default with Node.js, to execute each script in parallel.


const { spawn } = require('child_process');

// List of files to launch
const filesToExecute = ['script1.js', 'script2.js', 'script3.js'];

// Function to launch the files in parallel
function runFilesInParallel() {
  filesToExecute.forEach((file) => {
    const childProcess = spawn('node', [file]);

    // Handle output events
    childProcess.stdout.on('data', (data) => {
      console.log(`[${file}] stdout: ${data}`);
    });

    childProcess.stderr.on('data', (data) => {
      console.error(`[${file}] stderr: ${data}`);
    });

    childProcess.on('close', (code) => {
      console.log(`[${file}] child process exited with code ${code}`);
    });
  });
}

// Launch the files in parallel
runFilesInParallel();

Replace the file names 'script1.js', 'script2.js', and 'script3.js' in the filesToExecute array with the names of your bot scripts. For example, if you have two bots named 'myFirstBot.js' and 'mySecondBot.js', the filesToExecute array should look like this: ['myFirstBot.js', 'mySecondBot.js'].

Step 3: Update the server configuration on OuiPanel

  1. Log in to your OuiPanel account.
  2. Navigate to the "Server Configuration" section.
  3. Look for the "JS Startup File" section.
  4. Replace the existing file name with launchBots.js.

This tells OuiPanel to run your new JavaScript file that will launch all your bots.

Part 2: For Python bot hosting plans

Step 1: Create a new Python file

Create a new Python file, for example, launch_bots.py, in the same directory as your bot scripts.

Step 2: Write the code to launch the files in parallel

Copy the following code into your launch_bots.py file. This code uses Python's subprocess module to execute each script in parallel.


import subprocess

# List of files to launch
files_to_execute = ['script1.js', 'script2.js', 'script3.js']

# Function to launch the files in parallel
def run_files_in_parallel():
    processes = []
    for file in files_to_execute:
        process = subprocess.Popen(['node', file], 
                                   stdout=subprocess.PIPE, 
                                   stderr=subprocess.PIPE, 
                                   text=True)
        processes.append((file, process))

    for file, process in processes:
        stdout, stderr = process.communicate()
        
        if stdout:
            print(f"[{file}] stdout: {stdout}")
        if stderr:
            print(f"[{file}] stderr: {stderr}")
        
        print(f"[{file}] child process exited with code {process.returncode}")

# Launch the files in parallel
run_files_in_parallel()

Replace the file names 'script1.js', 'script2.js', and 'script3.js' in the files_to_execute array with the names of your bot scripts. For example, if you have two bots named 'myFirstBot.js' and 'mySecondBot.js', the files_to_execute array should look like this: ['myFirstBot.js', 'mySecondBot.js'].

Step 3: Update the server configuration on OuiPanel

  1. Log in to your OuiPanel account.
  2. Navigate to the "Server Configuration" section.
  3. Look for the "Startup File" section.
  4. Replace the existing file name with launch_bots.py.

This tells OuiPanel to run your new Python file that will launch all your bots.

Conclusion

And there you go! You have successfully launched multiple bots using a single plan on OuiHeberg, whether with Node.js or Python. Each bot runs in its own process, so if one bot crashes, it won't affect the others. This method allows you to efficiently manage multiple scripts simultaneously, optimizing your server resources.

Feel free to share your experiences or ask questions in the comments below!



OuiHeberg SARL logo
Name des Autors
OUIHEBERG SARL
Kategorien
Tutoriels
Date
28/06/2024

Die Pluspunkte des Artikels