Unitech / Unitech/pm2

PM2 logs errors when running in distroless

Open
#4,908 4 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

When running an app in docker on a distroless base image, we see these two errors being logged.

The Dockerfile

FROM node:12 AS build-env

ENV HOME=/usr/src/app
ENV NPM_CONFIG_PREFIX=$HOME/.npm-global
WORKDIR /usr/src/app

COPY . .

RUN npm ci --only=production
RUN npm i -g pm2

FROM gcr.io/distroless/nodejs:12-debug

COPY --from=build-env /usr/src/app /app
WORKDIR /app

EXPOSE 3000

ENV PATH=$PATH:/nodejs/bin

CMD [ ".npm-global/bin/pm2-runtime", "--format", "pm2.json" ]

error logged while running, doesn't affect the process

2020-11-04T16:30:58: PM2 error: Error while getting CLK_TCK Error: spawn /bin/sh ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /bin/sh',
  path: '/bin/sh',
  spawnargs: [ '-c', 'getconf CLK_TCK' ],
  cmd: 'getconf CLK_TCK'
}
2020-11-04T16:30:58: PM2 error: Error while getting PAGESIZE Error: spawn /bin/sh ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /bin/sh',
  path: '/bin/sh',
  spawnargs: [ '-c', 'getconf PAGESIZE' ],
  cmd: 'getconf PAGESIZE'
}

How could we reproduce this issue?

Run a simple application under pm2 on a distroless container.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Nov 04 2020 16:54:07 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.5.0
node version         : 12.18.3
node path            : not found
argv                 : /nodejs/bin/node,/usr/src/example/.npm-global/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
uptime               : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.5.0
node version         : 12.18.3
node path            : not found
argv                 : /nodejs/bin/node,/usr/src/example/.npm-global/bin/pm2,report
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
cpus nb              : 3
freemem              : 1030197248
totalmem             : 2084245504
home                 : /usr/src/example
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/usr/src/example/.pm2/pm2.log last 20 lines:
PM2        | 2020-11-04T16:54:07: PM2 log: ===============================================================================
PM2        | 2020-11-04T16:54:07: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2020-11-04T16:54:07: PM2 log: Time                 : Wed Nov 04 2020 16:54:07 GMT+0000 (Coordinated Universal Time)
PM2        | 2020-11-04T16:54:07: PM2 log: PM2 version          : 4.5.0
PM2        | 2020-11-04T16:54:07: PM2 log: Node.js version      : 12.18.3
PM2        | 2020-11-04T16:54:07: PM2 log: Current arch         : x64
PM2        | 2020-11-04T16:54:07: PM2 log: PM2 home             : /usr/src/example/.pm2
PM2        | 2020-11-04T16:54:07: PM2 log: PM2 PID file         : /usr/src/example/.pm2/pm2.pid
PM2        | 2020-11-04T16:54:07: PM2 log: RPC socket file      : /usr/src/example/.pm2/rpc.sock
PM2        | 2020-11-04T16:54:07: PM2 log: BUS socket file      : /usr/src/example/.pm2/pub.sock
PM2        | 2020-11-04T16:54:07: PM2 log: Application log path : /usr/src/example/.pm2/logs
PM2        | 2020-11-04T16:54:07: PM2 log: Worker Interval      : 30000
PM2        | 2020-11-04T16:54:07: PM2 log: Process dump file    : /usr/src/example/.pm2/dump.pm2
PM2        | 2020-11-04T16:54:07: PM2 log: Concurrent actions   : 2
PM2        | 2020-11-04T16:54:07: PM2 log: SIGTERM timeout      : 1600
PM2        | 2020-11-04T16:54:07: PM2 log: ===============================================================================

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Dockerfile with the simple application in a distroless container, then trace the PM2 path that invokes getconf CLK_TCK and getconf PAGESIZE. Compare the behavior with a regular Node image; done means the application still runs and the distroless container no longer emits these errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, node.js
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.