Unitech / Unitech/pm2

pm2 spawn child EPERM error

Open
#2,467 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S: Icebox T: Bug
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

I use system under root.
I have a script that successfully runs directly with node but does not work through pm2. It worked before but after installing some updates it does not work anymore (Sadly I'm not sure what exactly I updated because I have noticed the issue afterwards).

That's about spawning child process under root user. I run every command under root user too (node test.js, pm2 start test.js, etc).

PM2 Log output
test-4 (err): Error: spawn EPERM
test-4 (err):     at exports._errnoException (util.js:1026:11)
test-4 (err):     at ChildProcess.spawn (internal/child_process.js:313:11)
test-4 (err):     at exports.spawn (child_process.js:380:9)
test-4 (err):     at exports.execFile (child_process.js:143:15)
test-4 (err):     at /home/www/proxy/test/test.js:9:2
test-4 (err):     at Layer.handle [as handle_request] (/home/www/proxy/node_modules/express/lib/router/layer.js:95:5)
test-4 (err):     at next (/home/www/proxy/node_modules/express/lib/router/route.js:131:13)
test-4 (err):     at Route.dispatch (/home/www/proxy/node_modules/express/lib/router/route.js:112:3)
test-4 (err):     at Layer.handle [as handle_request] (/home/www/proxy/node_modules/express/lib/router/layer.js:95:5)
test-4 (err):     at /home/www/proxy/node_modules/express/lib/router/index.js:277:22
Software versions used
OS         : Ubuntu 16.04.1 LTS
node.js    : 6.9.1
PM2        : 1.1.3
Sample script

test.sh:

#!/usr/bin/env zsh

if [[ $UID != 0 ]]; then
    echo "This must be run as root."
    exit 1
fi

echo $1

fping google.com

test.js:

var express = require("express");
var execFile = require("child_process").execFile;
var path = require("path");

var RDIR = path.dirname(require.main.filename);
var app = express();

app.get("/",function(req,res) {
    execFile(RDIR+"/test.sh",{uid:0},function(err,out,code) {
        console.log(err,out,code);
        res.send(out);
    });
});

app.listen(3017);

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 reproducing the failure with the provided test.js and test.sh under Ubuntu 16.04. Compare running test.js directly with starting it through PM2, using the listed Node.js and PM2 versions, and inspect the PM2 log and child_process.execFile call. Done means identifying the cause of the EPERM difference and confirming that the sample child process works through PM2 or documenting the incompatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, zsh
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.