Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeDeploy PM2 Command Not Found

I'm trying to use AWS CodeDeploy to deploy my application. Everything seems to be working fine but I'm getting the following error.

[stderr]/opt/codedeploy-agent/deployment-root/f1ea67bd-97bo-08q1-b3g4-7b14becf91bf/d-WJL0QLF9H/deployment-archive/scripts/start_server.sh: line 3: pm2: command not found

Below is my start_server.sh file.

#!/bin/bash
pm2 start ~/server.js -i 0 --name "admin" &

I have tried using SSH to connect to my server as user ubuntu and running that bash file and it works perfectly with no errors. So I know that PM2 is installed and working correctly on that user.

Below is also my appspec.yml file.

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu
hooks:
  ApplicationStart:
    - location: scripts/start_server.sh
      timeout: 300
      runas: ubuntu
  ApplicationStop:
    - location: scripts/stop_server.sh
      timeout: 300
      runas: ubuntu

Also not sure if this will help but here is my stop_server.sh file.

#!/bin/bash
npm install pm2 -g
pm2 stop admin || true
pm2 delete admin || true

Any ideas?

like image 715
Charlie Fish Avatar asked Sep 15 '16 21:09

Charlie Fish


2 Answers

Perform the below steps:

  1. which node
  2. sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node
  3. which pm2
  4. sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/pm2 (output of above step) /usr/bin/pm2

in start_server.sh and stop_server.sh use it as below (run start.sh as ubuntu):

sudo /usr/bin/pm2 status

Hope this will help you!!

like image 139
Harsh Patel Avatar answered Sep 17 '22 12:09

Harsh Patel


Usually in cases like that is to use full path to pm2.

#!/bin/bash
/usr/local/bin/pm2 start ~/server.js -i 0 --name "admin" &
like image 35
SneakyMummin Avatar answered Sep 19 '22 12:09

SneakyMummin