PM2 + pocketbase - works when launched directly but not thru ecosystem file

102 views Asked by At

Since pm2 repo is completely abandoned I decided to search for luck here.

When I'm launching pocketbase process using pm2 start pocketbase -- serve --http=127.0.0.1:8097 then curl 127.0.0.1:8097 I get {"code":404,"message":"Not Found.","data":{}} which is expected as it's just root of the process. So far so good.

But what I really need to do is launch it from pm2 ecosystem file. Here's my config:

module.exports = {
  apps : [{
    name: "dev-db",
    script: "./pocketbase",
    args: ['serve', '--http', '127.0.0.1:8097'],
    interpreter: "none",
  }]
};

but then when it's run with pm2 (pm2 start dev-db.js) the process launches and also is seen as online, but the service in inaccessible:

curl 127.0.0.1:8097
curl: (7) Failed to connect to 127.0.0.1 port 8097: Connection refused

Current shape of args as an array I've found in an issue as a solution - to use it instead of string, but that didn't work. defining interpreter as none also doesn't work. Also tried to add

    env: {
      PORT: 8097
    }

to the config, but no luck.

Went over 100s of issues on the abandoned pm2 repo but nothing I've found have been related or worked.

Probably unrelated but the server is setup on litespeed

EDIT: I think this might have something to do with PM2 having their own serve command see

I've also tried wrapping pocketbase invocation into nodejs child process adn then starting that from ecosystem file:

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

const pocketbase = spawn('./pocketbase', ['serve', '--http=127.0.0.1:8097']);

pocketbase.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

pocketbase.stderr.on('data', (data) => {
  console.error(`stderr: ${data}`);
});

pocketbase.on('close', (code) => {
  console.log(`PocketBase process exited with code ${code}`);
});

but that did not work.

0

There are 0 answers