Jump to content

Recommended Posts

Posted (edited)

Ok so :

 

I've followed all the steps to start and stop the bot, but i've replaced the .py bot by server.js (my server script, placed in root directory). I've added the same permissions. Is that what was expected ?

Unfortunately  citadel.helioho.st/bot_control/ only shows

Cannot GET /bot_control/

i've also tried the full adress :
console error : bot_control/:1 
            
            
           GET https://citadel.helioho.st/httpdocs/bot_control/ 404 (Not Found)

The tutorial said to check the bot logs but i cannot find them in the bot_control dir. There are logs in the log dir, but i don't know which ones are the bot one.

Am I on a wrong track ?

Edited by gofterdom
Posted

Ok i managed to find it by going directyly to https://citadel.helioho.st/bot_control/index.sh

but now it's giving me errors, that seems like it's expecting a python document and not a js document, the comments are not read as comment...

 

server.js is not running. Start - Check Load

Logs: Clear Logs - Full Logs

[2025-06-27 12:22:07] Starting server.js.
  File "/home/citadel.helioho.st/server.js", line 321
    // Only add tiles that don't already exist at those coordinates
                              ^
SyntaxError: unterminated string literal (detected at line 321)
[2025-06-27 12:22:11] Starting server.js.
  File "/home/citadel.helioho.st/server.js", line 321
    // Only add tiles that don't already exist at those coordinates
                              ^
SyntaxError: unterminated string literal (detected at line 321)
Posted

I THINK i managed to adapt the bash script to start the node.js server.js script using passenger, but it feels like there is not much i can do now, since ports are not open to me...

I don't know how to stop the node using passenger though. Can you please help me with the next steps ?

 

server.js is not running. Start - Check Load

Logs: Clear Logs - Full Logs

[2025-06-27 13:38:48] Restarting server.js.
[2025-06-27 13:39:22] Restarting server.js.
[2025-06-27 13:39:27] Restarting server.js.
[2025-06-27 13:42:32] Restarting server.js.

 

 

 

#!/bin/bash

# edit this to match your bot filename
bot_name="server.js"

###################################################################

printf 'Content-Type: text/html\n\n'
username=`whoami`
pwd=`printenv|grep '^PWD'|cut -f2 -d'='`
main_domain=`echo "$pwd"|cut -f3 -d'/'`
control=`echo "$pwd"|cut -f5 -d'/'`
temp=`ps axo user:16,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,command|grep -v grep|grep "^$username "`
running=`echo "$temp"|grep -c "$bot_name"`
file_base=`echo $bot_name|tr -cd "a-zA-Z0-9"`
log_name="$file_base.txt"

if [ "$QUERY_STRING" == "" ]; then
    if [ $running -ne 0 ]; then
        mem_kb=`echo "$temp"|grep "$bot_name"|awk '{print $6}'`
        mem_mb=$( echo "scale=2;$mem_kb/1024"|bc )
        mem_24=$( echo "scale=2;$mem_kb*1440/1048576"|bc )
        echo "$bot_name is running. <a href='?action=stop'>Stop</a><br>Current memory usage: $mem_mb MB<br>Estimated 24 hour usage: $mem_24 GB - "
    else
        echo "$bot_name is not running. <a href='?action=start'>Start</a> - "
    fi
    echo "<a href='https://heliohost.org/dashboard/load/' target='_blank'>Check Load</a><br><br>Logs: <a href='?action=clear'>Clear Logs</a> - <a href='/$control/$log_name'>Full Logs</a><pre>"
    tail -30 $pwd/$log_name
    echo "</pre><script>reloading = setTimeout('window.location.reload();', 10000);</script>"
fi

ts=`date +"%Y-%m-%d %H:%M:%S"`

if [ "$QUERY_STRING" == "action=stop" ]; then
    echo "[$ts] Stop action requested for $bot_name." >> $pwd/$log_name
    echo "Stop action triggered. You must handle graceful shutdown inside your app.<br>"
    echo "<script>setInterval(\"window.location.replace('/$control/');\", 2000);</script>"
fi

if [ "$QUERY_STRING" == "action=start" ]; then
    echo "[$ts] Restarting $bot_name." >> $pwd/$log_name
    touch "$pwd/../tmp/restart.txt"
    echo "Restart triggered for $bot_name.<script>window.location.replace('/$control/');</script>"
fi

if [ "$QUERY_STRING" == "action=clear" ]; then
    cat /dev/null > $pwd/$log_name
    echo "Clearing logs...<script>window.location.replace('/$control/');</script>"
fi

exit 0
 

Posted
5 hours ago, gofterdom said:

I don't know how to stop the node using passenger though.

Passenger automatically kills your Node.js server after 5-10 minutes without any page hits. That's why I was recommending starting and stopping your websocket with the /bot_control/index.sh script if you want it to run for more than 5 minutes.

Posted

I have not been able to start and stop the websocket from the /bot_control/index.sh script, it is looking for the node install folder and i don't know where to indicate it.

it is looking in /usr/local/bin/node, but not finding it

Could you please tell me what i need to change in that bash script to make it work with node.js ?

In its initial state, it seemed to be looking for a python file only

apologies for taking your time, i have been trying all day

Posted
11 minutes ago, gofterdom said:

Could you please tell me what i need to change in that bash script to make it work with node.js ?

Instead of this

5 hours ago, gofterdom said:

if [ "$QUERY_STRING" == "action=start" ]; then
    echo "[$ts] Restarting $bot_name." >> $pwd/$log_name
    touch "$pwd/../tmp/restart.txt"
    echo "Restart triggered for $bot_name.<script>window.location.replace('/$control/');</script>"
fi

Try this

if [ "$QUERY_STRING" == "action=start" ]; then
    if [ $running -ne 0 ]; then
        echo "$bot_name is already running..."
    else
        echo "[$ts] Starting $bot_name." >> $pwd/$log_name
        /opt/plesk/node/22/bin/node /home/$main_domain/$bot_name >> $pwd/$log_name 2>&1 &
        echo "Starting $bot_name...<script>window.location.replace('/$control/');</script>"
    fi
fi

 

Posted (edited)

thank you, it seems to work !

 

now i'm blocked by the port issue we discussed, but i'm guessing that's expected ? Only need the apache/nginx redirect that was mentioned in the FAQ ? Or am i forgetting something

 

[2025-06-27 19:35:41] Starting server.js.
SERVER STARTED AND RUNNING
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1940:16)
    at listenInCluster (node:net:1997:12)
    at Server.listen (node:net:2102:7)
    at Object. (/home/citadel.helioho.st/server.js:548:8)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Object..js (node:internal/modules/cjs/loader:1895:10)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
Emitted 'error' event on WebSocketServer instance at:
    at Server.emit (node:events:518:28)
    at emitErrorNT (node:net:1976:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Node.js v22.17.0
Edited by gofterdom
Posted (edited)

I thought the whole point was that no port was available ;( that's why i didn't try further

I switched to 8080 and it works now indeed :

server.js is running. Stop
Current memory usage: 62.12 MB
Estimated 24 hour usage: 87.36 GB - Check Load


However on the main game itself :
 

network.js:3 WebSocket connection to 'wss://citadel.helioho.st/' failed:
  setupWebSocket @ network.js:3
  (anonymous) @ game.js:39

 

Is that where nginx/apache are needed ?

I've been able to stop the script as well

server.js is not running. Start - Check Load

Logs: Clear Logs - Full Logs

[2025-06-27 21:48:01] Stop action requested for server.js.
[2025-06-27 21:48:38] Stop action requested for server.js.
[2025-06-27 21:50:19] Stop action requested for server.js.
[2025-06-27 21:52:03] Stopping server.js.
Edited by gofterdom
Posted
5 minutes ago, gofterdom said:

I thought the whole point was that no port was available ;( that's why i didn't try further

No external ports are available, and we don't open them in the firewall on Morty, Tommy, or Johnny. Internal ports are basically all available, but they can't be accessed remotely without proxying them through Apache or Nginx because the firewall blocks the direct connection. There are 65535 internal ports, and only a handful are in use by other users.

Right now Passenger is blocking access to everything on your domain, so we need to either add another subdomain to access /bot_control/ or you'll need to disable Passenger.

Posted

I am unsure if there is something else I can do from my side ? You said :

we need to either add another subdomain to access /bot_control/ or you'll need to disable Passenger.

I am down for either, but as I mentioned, I am lost. Is there a tutorial I can follow for any one of these options ? 

I'll be glad to stop bothering you, I just don't know what i'm supposed to do next

 

 

Posted

Ok, let's leave Passenger on for your main domain so you can play around with that. I created 2 subdomains for you: wss.citadel.helioho.st which we'll use for your websocket, and control.citadel.helioho.st that we'll use for your start/stop/logs index.sh script. The new domains should start working in about 100 minutes or so. You can go ahead and move the .htaccess file and index.sh file from /home/citadel.helioho.st/httpdocs/bot_control/ to /home/citadel.helioho.st/control.citadel.helioho.st/ We'll work on this more when the domains are ready.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...