¡Sumérgete en un mundo web inigualable con nuestras soluciones de hosting innovadoras!

Explora opciones confiables, seguras y de alto rendimiento adaptadas a todas tus necesidades en línea.

Todas nuestras soluciones de hosting web

¡Descubre un poder inigualable con nuestros servidores VPS innovadores y personalizados!

Experimenta libertad y potencia con nuestros VPS, diseñados para elevar tus proyectos a nuevas alturas.

Todos nuestros servidores VPS

Optimiza tus bots con nuestro hosting dedicado, poderoso y personalizado.

Experimenta una gestión fluida y un rendimiento óptimo con nuestro hosting para bots.

Todas nuestras ofertas de bot

Nueva oferta BoxGaming

Descubre nuestra última oferta, disponible en nuestros centros de datos en Francia y EE. UU. Con una sola oferta, puedes cambiar el tipo de servidor en cualquier momento.

Descubre la oferta
¡Mejora tus servidores de juegos con nuestro hosting especializado y de alto rendimiento!

Sumérgete en la experiencia de juego definitiva con nuestro hosting optimizado y potente.

Todas nuestras ofertas de Minecraft

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
Nombre del autor
OUIHEBERG SARL
Categorías
Tutoriels
Fecha
28/06/2024

Artículo destacado