Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baremetal deploy fails on Starting serve serve process step - pm2 #5081

Closed
zpeters opened this issue Apr 8, 2022 · 16 comments
Closed

Baremetal deploy fails on Starting serve serve process step - pm2 #5081

zpeters opened this issue Apr 8, 2022 · 16 comments
Assignees

Comments

@zpeters
Copy link
Contributor

zpeters commented Apr 8, 2022

I am happy to do additional testing and contribute patches, etc to help solve this issue.

Main issue

  • What happens
    • I have run yarn rw setup deploy baremetal and made the necessary config settings (below)
    • When i run yarn rw deploy baremetal --firstrun all steps succeed until i get to "Starting serve process ofr the first time". At that step i get an error that the Deploy Failed running the command yarn pm2 start ecosystem.config.js --only serve
    • If i ssh into the server i can manually start the service using the "manual" pm2 command of pm2 start ecosystem.config.js
  • What is expected
    • I am expecting that this step should be running pm2 start ecosystem.config.js to install the initial api services. I cannot find a reference to using yarn to run the pm2 command. I suspect i am missing something in my packages config possibly?

Additional thoughts

  • I found it necessary to run pm2 save to make my settings persist, this would be helpful to add
  • possibly a statement about pm2 startup to discuss injecting pm2 into the systems normal services so it will run on reboot

Relevant configs

deploy.toml
[[servers]]
host = "redwood"
username = "zach"
agentForward = false
privateKey = "/Users/zachpeters/.ssh/id_rsa"
migrate = false
sides = ["api","web"]
path = "/var/www/oblique-strategies"
processNames = ["serve"]
package.json (root)
{
  "private": true,
  "workspaces": {
    "packages": [
      "api",
      "web",
      "packages/*"
    ]
  },
  "devDependencies": {
    "@redwoodjs/core": "^1.0.0",
    "node-ssh": "^12.0.4"
  },
  "eslintConfig": {
    "extends": "@redwoodjs/eslint-config",
    "root": true
  },
  "engines": {
    "node": ">=14.19 <=16.x",
    "yarn": ">=1.15"
  },
  "prisma": {
    "seed": "yarn rw exec seed"
  },
  "packageManager": "[email protected]"
}
ecosystem.config.js
module.exports = {
  apps: [
    {
      name: 'api',
      script: 'node_modules/.bin/rw',
      args: 'serve api',
      instances: 'max',
      exec_mode: 'cluster',
      wait_ready: false,
      listen_timeout: 10000,
    },
  ],
}
@jtoar jtoar added this to Triage Apr 8, 2022
@jtoar jtoar moved this to Needs triage in Triage Apr 8, 2022
@thedavidprice
Copy link
Contributor

Looping in @cannikin

@cannikin
Copy link
Member

cannikin commented Apr 8, 2022

Hi @zpeters did you add pm2 to your app's package.json or install globally? Right now it always tries to run with yarn pm2 which will only be available if you add it to your app via yarn add -W pm2. I have a note in the docs about licensing concerns with pm2 but I should also add a note about installing it properly!

At some point I'd like to make it an option whether to use globally installed pm2 (by just running pm2) vs the local install (run with yarn pm2).

@cannikin
Copy link
Member

cannikin commented Apr 8, 2022

Added a couple of issues to track this: #5083 #5082

@zpeters
Copy link
Contributor Author

zpeters commented Apr 8, 2022

@cannikin This sounds like the right track. I will report back. Happy to help contribute to the docs or code if needed.

@zpeters
Copy link
Contributor Author

zpeters commented Apr 9, 2022

@cannikin Confirming that adding the pm2 dep did solve my issue.

One thing to note, i needed to manually run "yarn pm2 startup" and "yarn pm2 save" to add the systemd hooks and to have it retain the services on reboot.

My thoughts would be to have the adding of the pm2 dep part of the "yarn rw deploy setup baremetal" process and have the "pm2 save" and "pm2 startup" part of the "first run" process.

I saw a few different issues get created so im going to pause here and get your thoughts.

Im happy to spend time documenting, submitting a patch or testing to help with the project. just let me know how you'd like time spent.

@cannikin
Copy link
Member

cannikin commented Apr 9, 2022 via email

@zpeters
Copy link
Contributor Author

zpeters commented Apr 12, 2022

Nearly have the first part of this complete. I am wrapping up the command to save the state. It looks like the "startup" command just spits out a sudo command to run. To avoid complication i will not try to tackle this in the setup, but rather add a note in the documentation.

After i have this i'd like to tackle the local/global option we discussed

@zpeters
Copy link
Contributor Author

zpeters commented Apr 13, 2022

#5139 for review

@zpeters
Copy link
Contributor Author

zpeters commented Apr 14, 2022

#5139 merged - adds "save" step to baremetal and add docs for baremetal startup

continuing on local/global pm2 options

@zpeters
Copy link
Contributor Author

zpeters commented Apr 14, 2022

@jtoar jtoar assigned cannikin and zpeters and unassigned callingmedic911 Apr 16, 2022
@jtoar jtoar removed this from Triage Apr 16, 2022
@jtoar jtoar moved this to Todo in Release Apr 16, 2022
@jtoar jtoar added this to Release Apr 16, 2022
@jtoar jtoar moved this from Todo to In progress in Release Apr 16, 2022
@cannikin
Copy link
Member

cannikin commented Apr 21, 2022

@zpeters
Copy link
Contributor Author

zpeters commented Apr 21, 2022

This is prefect thanks!

@zpeters
Copy link
Contributor Author

zpeters commented Apr 22, 2022

PRs submitting, awaiting approval

@cannikin
Copy link
Member

Going to close this along with the PR, thanks again for working on it!

@jtoar jtoar moved this from In progress to Done in Release Apr 25, 2022
@shobhitic
Copy link

I keep getting this error:

bash: line 1: pm2: command not found

I've added pm2 to package.json, installed globally on the server. In deploy.toml, I have:

packageManagerCommand = "yarn"
monitorCommand = "pm2"

This issue is the closest I got to find the answer, please let me know what am I doing wrong (and also let me know if this isn't the right place to ask the question)

@cannikin
Copy link
Member

Hello! You shouldn't need to add pm2 to package.json, it really needs to be installed globally on the server, not in your app:

yarn global add pm2
# or
npm install -g pm2

We usually prefer to do help like this in the Discord!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

5 participants