Unitech / Unitech/pm2

PM2 heredoc support for bash

Open
#1,848 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

pm2's json app configuration is great, however it does not comply with bash heredoc standard, meaning you have to have a physical .json file to pass to pm2.

Here is what you could achieve (think from an automated deployment point of view) if the input was heredoc compliant:

pm2 start <<EOF
{
"apps" : [{
    "name"        : "eventTrack",
    "script"      : "index.js",
    "args"        : [],
    "watch"       : true,
    "instances"   : 4,
    "node_args"   : "",
    "merge_logs"  : true,
    "cwd"         : "$1/myapppath/",
    "env": {
        "NODE_ENV": "production",
        "MONGOCOL":"log",
        "REDIS_PORT":6379
    }
  }]
}
EOF

Now if my $1 parameter has my working path (which in automation/containerized environment can be dynamic and hard to meaningfully predict), I can start pm2 on that instance quite easily, without having to write a json file to disk and read it for this exclusive reason.

You can test this functionality with:

cat <<EOF
{
"apps" : [{
    "name"        : "eventTrack",
    "script"      : "index.js",
    "args"        : [],
    "watch"       : true,
    "instances"   : 4,
    "node_args"   : "",
    "merge_logs"  : true,
    "cwd"         : "$1/myapppath/",
    "env": {
        "NODE_ENV": "production",
        "MONGOCOL":"log",
        "REDIS_PORT":6379
    }
  }]
}
EOF

which treats the heredoc as a file (as it should) and simply prints it.

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 tracing how the pm2 start command handles JSON configuration and stdin, using the heredoc example in the issue as the expected input. Compare this with the shown cat <<EOF behavior; done means PM2 can consume equivalent heredoc input without requiring a physical JSON file.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, javascript, nodejs
Domain
cli, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.