Sunday, 4 June 2017

Node.js app can't access any env variables when pm2 is started from a script but can when launched from ssh

I am trying to launch a node.js app on a production EC2 server with pm2 process manager.When I ssh into the instance and run pm2 start app.js, PM2 starts just fine and has access to all environment variables. Everything good.However, I want to run pm2 start app.js from a Codedeploy hook script called applicationstart.sh, the app fails with an errored status becasue it is missing all environment variables.http://ift.tt/2rHCNrX is where the script is added so it is launched with each deployment and calls pm2 start: appspec.ymlversion: 0.0 os: linux files: - source: / destination: /home/ubuntu/teller-install hooks: AfterInstall: - location: scripts/afterinstall.sh timeout: 1000 runas: root ApplicationStart: - location: scripts/applicationstart.sh timeout: 300 runas: ubuntu Here is the applicationstart script:#!/bin/bash echo "Running Hook: applicationstart.sh" cd /home/ubuntu/teller-install/Server/ pm2 start app.js exit 0 I am logged in as ubuntu when I run the script from ssh and I set the script in the appconfig.yml to run as ubuntu as well.Why am I getting a difference between starting pm2 from terminal and starting it from a launch hook script?Here is running directly from ssh:http://ift.tt/2sFRt8c can provide any information necessary in dire need of solution. Thanks!

Submitted June 05, 2017 at 02:57AM by poethetortoise

No comments:

Post a Comment