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?