Scopri un mondo web senza pari con le nostre soluzioni di hosting innovative!

Esplorate le opzioni affidabili, sicure e ad alte prestazioni per tutte le vostre esigenze online.

Tutte le nostre soluzioni di hosting web

Scopri una potenza ineguagliabile con i nostri server VPS su misura!

Sperimentate la libertà e la potenza con il nostro VPS, progettato per portare i vostri progetti a nuove altezze!

Tutti i nostri server VPS

Ottimizza i tuoi bot con il nostro hosting dedicato e potente!

Sperimentate una gestione fluida e prestazioni ottimali con il nostro hosting per bot.

Tutte le nostre offerte per bot

Nuova Offerta BoxGaming

Scopri la nostra nuova offerta nei data center in Francia e Stati Uniti. Cambia tipo di server in qualsiasi momento con un'unica offerta.

Scopri l'offerta
Potenzia i server di gioco con il nostro hosting specializzato!

Immergetevi nell'esperienza di gioco definitiva con il nostro hosting potente e ottimizzato!

Tutte le nostre offerte 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
Nome dell'autore
OUIHEBERG SARL
Categorie
Tutoriels
Data
28/06/2024

Articolo in evidenza