Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.57k stars 2.62k forks source link

docker-compose up throws SyntaxError: Invalid or unexpected token #5472

Open Gharsnull opened 2 years ago

Gharsnull commented 2 years ago

What's going wrong?

I'm trying to start a service using docker-compose up, but pm2 is not able to execute docker-compose file. docker-compose up command runs fine if I execute it manually, it just fails when pm2 executes it

pm2 log 0
[TAILING] Tailing last 15 lines for [0] process (change the value with --lines option)
/home/gharsnull/.pm2/logs/docker-services-out.log last 15 lines:
/home/gharsnull/.pm2/logs/docker-services-error.log last 15 lines:
0|docker-s | /usr/bin/docker-compose:2
0|docker-s | # EASY-INSTALL-ENTRY-SCRIPT: 'docker-compose==1.29.2','console_scripts','docker-compose'
0|docker-s | ^
0|docker-s | 
0|docker-s | SyntaxError: Invalid or unexpected token
0|docker-s |     at wrapSafe (internal/modules/cjs/loader.js:1001:16)
0|docker-s |     at Module._compile (internal/modules/cjs/loader.js:1049:27)
0|docker-s |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
0|docker-s |     at Module.load (internal/modules/cjs/loader.js:950:32)
0|docker-s |     at Function.Module._load (internal/modules/cjs/loader.js:790:12)
0|docker-s |     at Object.<anonymous> (/home/gharsnull/.nvm/versions/node/v14.20.1/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
0|docker-s |     at Module._compile (internal/modules/cjs/loader.js:1085:14)
0|docker-s |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
0|docker-s |     at Module.load (internal/modules/cjs/loader.js:950:32)
0|docker-s |     at Function.Module._load (internal/modules/cjs/loader.js:790:12)

Supporting information

npm --version
6.14.17
node --version
v14.20.1
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy
ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'docker-services',
      cwd: './docker',
      script: 'docker-compose',
      args: 'up',
      kill_timeout: 100000,
    },
  ],
};
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'docker-compose==1.29.2','console_scripts','docker-compose'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'docker-compose==1.29.2'

try:
    from importlib.metadata import distribution
except ImportError:
    try:
        from importlib_metadata import distribution
    except ImportError:
        from pkg_resources import load_entry_point

def importlib_load_entry_point(spec, group, name):
    dist_name, _, _ = spec.partition('==')
    matches = (
        entry_point
        for entry_point in distribution(dist_name).entry_points
        if entry_point.group == group and entry_point.name == name
    )
    return next(matches).load()

globals().setdefault('load_entry_point', importlib_load_entry_point)

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())
--- PM2 report ----------------------------------------------------------------
Date                 : Fri Oct 21 2022 11:14:54 GMT-0500 (Colombia Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.2
node version         : 14.20.1
node path            : /home/gharsnull/.nvm/versions/node/v14.20.1/bin/pm2
argv                 : /home/gharsnull/.nvm/versions/node/v14.20.1/bin/node,/home/gharsnull/.nvm/versions/node/v14.20.1/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : gharsnull
uid                  : 1000
gid                  : 1000
uptime               : 21min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.2
node version         : 14.20.1
node path            : /home/gharsnull/.nvm/versions/node/v14.20.1/bin/pm2
argv                 : /home/gharsnull/.nvm/versions/node/v14.20.1/bin/node,/home/gharsnull/.nvm/versions/node/v14.20.1/bin/pm2,report
argv0                : node
user                 : gharsnull
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : AMD Ryzen 5 5600X 6-Core Processor
cpus nb              : 12
freemem              : 1839833088
totalmem             : 16692473856
home                 : /home/gharsnull
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ docker-services        │ default     │ N/A     │ fork    │ 0        │ 0      │ 30   │ errored   │ 0%       │ 0b       │ gha… │ disabled │
│ 3   │ document-service-be    │ default     │ 0.39.2  │ fork    │ 13558    │ 6s     │ 15   │ online    │ 0%       │ 55.6mb   │ gha… │ disabled │
│ 1   │ main-be                │ default     │ 0.39.2  │ fork    │ 11644    │ 6m     │ 0    │ online    │ 0%       │ 47.5mb   │ gha… │ disabled │
│ 2   │ main-fe                │ default     │ 0.39.2  │ fork    │ 11652    │ 6m     │ 0    │ online    │ 0.2%     │ 48.1mb   │ gha… │ disabled │
└─────┴────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
/home/gharsnull/.pm2/pm2.log last 20 lines:
PM2        | 2022-10-21T11:11:29: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:11:29: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:12:02: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:12:02: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:12:02: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:12:35: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:12:35: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:12:35: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:13:09: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:13:09: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:13:09: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:13:42: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:13:42: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:13:42: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:14:15: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:14:15: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:14:15: PM2 log: App [document-service-be:3] online
PM2        | 2022-10-21T11:14:48: PM2 log: App [document-service-be:3] exited with code [255] via signal [SIGINT]
PM2        | 2022-10-21T11:14:48: PM2 log: App [document-service-be:3] starting in -fork mode-
PM2        | 2022-10-21T11:14:48: PM2 log: App [document-service-be:3] online
SoberBluee commented 10 months ago

I was getting the same issue trying to run pm2 with docker-compose. I tried this and it worked for me npm version - 10.2.5 node version - 20.10.0 docker-compose version - 1.29.2 pm2 version - 5.3.0

ERROR


/usr/bin/docker-compose:2
# EASY-INSTALL-ENTRY-SCRIPT: 'docker-compose==1.29.2','console_scripts','docker-compose'
^

SyntaxError: Invalid or unexpected token
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)

before:

module.exports = {
  apps: [
    {
      name: '<process-name>',
      cwd: '/var/www/<project>', // must have absolute path
      script: 'docker-compose',
      args: 'up -d',
      env: {
        NODE_ENV: 'development',
      },
    },
  ],
};

after:

module.exports = {
  apps: [
    {
      name: '<process-name>',
      cwd: '/var/www/<project>', // must have absolute path
      script: '/usr/bin/docker-compose',
      args: ['up', '-d'], //arguments in array instead of string and absolute path of docker-compose
      env: {
        NODE_ENV: 'development',
      },
    },
  ],
};

Hope this helps you or anyone else having this issue :)