Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm global install on elastic beanstalk

I am running into an issue installing pm2 globally on aws elastic beanstalk. I created the following script for installing pm2:

option_settings:
  - option_name: NODE_ENV
    value: production
container_commands:
  01_enable_rootaccess:
    command: echo Defaults:root \!requiretty >> /etc/sudoers 
  02_install_imagemagic:
    command: yum install -y ImageMagick
  03_download_new_relic:
    command: rpm -Uvh http://download.newrelic.com/pub/newrelic/el5/i386/newrelic-repo-5-3.noarch.rpm 
    ignoreErrors: true
  04_install_new_relic:
    command: yum install -y newrelic-sysmond
    ignoreErrors: true
  05_add_license_key:
    command: /usr/sbin/nrsysmond-config --set license_key=xxxxxxx
    ignoreErrors: true
  06_start_new_relic:
    command: /etc/init.d/newrelic-sysmond start
    ignoreErrors: true
  07_install_pm2:
    command: sudo /opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/npm install pm2 -g
    ignoreErrors: true    
  08_stop_old_pm2_processes:
    command: sudo /opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/pm2 delete all
    ignoreErrors: true
  09_start_pm2:
    command: sudo /opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/pm2 startup -u ec2-user
    ignoreErrors: true

I have tried using just 'pm2 delete all' and 'pm2 startup' for commands 8 & 9 put i just get command not found. when i give the specific path to pm2(i logged on to the ec2 and verified) i get "line 4: exec: : not found". any idea what i am doing wrong here? Thanks in advance for your help!

like image 488
Jeff W Avatar asked May 01 '14 12:05

Jeff W


People also ask

Does Elastic Beanstalk do an npm install?

When a package. json file is present, Elastic Beanstalk runs npm install to install dependencies. It also uses the start command to start your application. For more information about the package.

How install npm install globally?

Install Package Globally NPM can also install packages globally so that all the node. js application on that computer can import and use the installed packages. NPM installs global packages into /<User>/local/lib/node_modules folder. Apply -g in the install command to install package globally.

Does npm install globally or locally?

It's best to install locally when relying on a package from your module, such as Node. js. This is how npm install works by default. The grunt CLI package, for example, must be installed globally before it can be used as a command-line tool.


1 Answers

I managed to install pm2 globally on elastic beanstalk with the following code snippet embedded in an .ebextensions/your_file_name.config file

container_commands:
  01_node_symlink:
    command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
  02_npm_symlink:
    command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
  03_pm2_install:
    command: "if [ ! -e /bin/pm2 ]; then npm install pm2 -g; fi"
    ignoreErrors: true
like image 98
asaf am Avatar answered Oct 11 '22 21:10

asaf am