0

I wrote a script for deploying code to EC2 instance using AWS Code Deploy, my files are getting copied to the destination, then my hooks run, remove commands, cd commands are running fine but when the following command is run:

/usr/bin/node/bin/forever start /home/ubuntu/codebase/app/bin/www

I get the following error and deployment fails:

/usr/bin/env: node: Permission denied

I have setup the node version v4.4.0 by downloading using wget and then adding following paths to bashrc:

export NODEJS_HOME=/usr/share/nodejs/bin
export PATH=$PATH:$NODEJS_HOME

I also added a symlink:

sudo ln -s /usr/share/nodejs/ 

My appspec.yml hooks:

  ApplicationStart:
    - location: scripts/start_server.sh
      timeout: 30
      runas: ubuntu

Questions:

  1. Why am I getting 'node: permission denied' error?
  2. Secondly, Why I need to give the full path for 'npm, node, forever'?

If I go to the corresponding directory: /opt/codedeploy-agent/deployment-root/..... and then run my script manually as an Ubuntu user, it works fine. Although running it as sudo, gives the same error on console

user2379271
  • 613
  • 2
  • 7
  • 15
  • What happens when you change the runas : root? Also what are the permission on file start_server.sh? – Piyush Patil Jul 20 '16 at 13:34
  • same error. Permission denied. – user2379271 Jul 20 '16 at 13:35
  • If I go to the corresponding directory: /opt/codedeploy-agent/deployment-root/..... and then run my script manually as an Ubuntu user, it works fine. Although running it as sudo, gives the same error on console. – user2379271 Jul 20 '16 at 13:36

1 Answers1

0

The service command strips out most of environment variables. So the variables NODEJS_HOME will not be available to start_server.sh. You can try and setting up the environment variables in /etc/profile. The agent sources that at startup.

Hope this will resolve the issue.

Thanks, Amartya Datta Gupta