PM2 inside bash script deployed and executed with puppet not working - node.js

#!/bin/bash
yum -y install gcc-c++
wget https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
tar -xvzf node-v0.12.7.tar.gz
cd node-v0.12.7
./configure
make
sudo make install
yum -y install git
/usr/local/bin/npm install pm2 -g
cd /home/admin/Order-Management/
/usr/local/lib/node_modules/pm2/bin/pm2 start processes.json
The above script run perfectly when I run it locally but when I try to execute it with puppet on the client machine the last line throwing the following error.
/usr/bin/env: node: No such file or directory
I am using RedHat 6 master and RedHat 6 client. I saw a solution here
Node forever /usr/bin/env: node: No such file or directory However not working for me. Any help will be much appreciated.

I had to add environment variable for puppet exec resource. That was not a problem for node.

Related

How To Make Node Server Always Load Within Service

I have a simple service file that is supposed to run a bash script that starts a node js server in my "build" directory.
Contents of the script are
#!/bin/bash
cd /home/path/to/build && npm install -g serve && serve -l 5679
However, I get the error => /usr/bin/env: ‘node’: No such file or directory
Even when I try a symlink like so
#!/bin/bash
cd /home/path/to/build && ln -s /usr/bin/nodejs /usr/bin/node && npm install -g serve && serve -l 5679
I get the error => failed to create symbolic link ‘/usr/bin/node’: File exists
Please how do I fix this? I wouldn't want my user to have to manually start serving on each reboot. It also works if I add the script contents straight to terminal.
Thanks for any help!
Turns out I had to install node with a different method (inspired by https://www.geeksforgeeks.org/installation-of-node-js-on-linux/) to ensure it actually existed in /usr/bin because ExecStart didn't like having the "serve" command working with my symlink node.
Step 1: Open your terminal or press Ctrl + Alt + T and use the following commands to update and upgrade the package manager:
sudo apt-get update
sudo apt-get upgrade
Step 2: Install Python software libraries using the following command:
sudo apt-get install software-properties-common
Step 3: Add Node.js PPA to the system.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Note: Here, we are installing node.js version 14, if you want to install version 11, you can replace setup_14.x with setup_11.x.
Step 4: To Install Node.js and NPM to your Ubuntu machine, use the command given below:
sudo apt-get install nodejs
Step 5: Once installed, verify it by checking the installed version using the following command:
node -v or node –version
npm -v or npm –version

Install Apache Zeppelin binary on Ubuntu Linux

I'm trying to install Apache Zeppelin and various interpreters on Ubuntu Linux using AWS EC2. Below are my steps for the binary and from source.
SSH through Putty as ubuntu#IP
wget http://mirrors.gigenet.com/apache/zeppelin/zeppelin-0.6.2/zeppelin-0.6.2.tgz
sudo tar -zxf zeppelin-0.6.2.tgz
cd zeppelin-0.6.2
sudo bin/zeppelin-daemon.sh start
It gives me the following status in the cli:
Zeppelin start [OK]
Zeppelin process died [FAILED]
I then tried to install build from source using the following:
sudo apt-get update
sudo apt-get install git
sudo apt-get install openjdk-7-jdk
sudo apt-get install npm
sudo apt-get install libfontconfig
git clone https://github.com/apache/zeppelin.git
apt-cache search maven
sudo apt-get install maven
export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=1024m"
mvn -version
I use the java home directory and set the environment variable for JAVA_HOME by
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
cd into zeppelin folder and then run
mvn clean package -Pspark-2.0 -Phadoop-2.4 -Pyarn -Ppyspark -Psparkr -Pscala-2.11
And it builds Zeppelin but fails at the next Zeppelin: Interpreter
How do I get her to work without going to AWS EMR? Thanks in advance.
The tgz file that you downloaded is source file. Not prebuild one. So you need to build it first before you try to start Zeppelin daemone. If you won't modify the source, I'd recommend you to download binary package.
$ http://mirrors.gigenet.com/apache/zeppelin/zeppelin-0.6.2/zeppelin-0.6.2-bin-all.tgz
$ sudo tar -zxf zeppelin-0.6.2-bin-all.tgz
$ cd zeppelin-0.6.2-bin-all
$ sudo bin/zeppelin-daemon.sh start
Then you can start Zeppelin server without any further steps.

Can't run Node after install on EC2 Instance

I followed the instructions here: https://codeforgeek.com/2015/05/setup-node-development-environment-amazon-ec2/ - Everything seems to have installed properly. When I run 'node --version' I get -bash: node: command not found. I have run sudo ln -fs out/Release/node /usr/bin/node and still the same issue. When I run 'whereis node' I get node: /usr/bin/node /usr/local/bin/node. When I navigate to either of these directories 'node' is in red.
I am a front end guy so all this infrastructure stuff is new to me so please excuse my ignorance. I would like to avoid smashing my machine!
Thanks
Use the NodeSource packages.
The setup script is https://rpm.nodesource.com/setup_6.x
If you just want it to work, as root run
sudo su - root
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs gcc-c++ make

node - Nothing happens when running a script

I installed Node on Linux Mint doing sudo apt-get install node npm, but it doesn't seem to work at all.
I created this small script to check if anything was happening:
console.log('this is a test');
throw new Error();
When I execute it from the terminal, there is absolutely no ouput: no log, no error:
remi#remi-pc ~ $ node tests.js
remi#remi-pc ~ $
Anyone knows how to fix this?
Try these commands to install nodejs
curl -sL https://deb.nodesource.com/setup | sudo bash -
then
sudo apt-get install -y nodejs
now run your script
Below are the steps to install Node.js from source (OSX/linux)
NOTE - this installs Node.js which gives you both node as well as npm,
they come together per release.
to start fresh remove prior node and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
download source from : http://nodejs.org/download/
cd node-v0.12.0
You may/should issue all following cmds as yourself NOT root (sudo)
Pick one of these NODE_PARENT locations to define where node gets installed into :
export NODE_PARENT=/some/desired/install/path_goes_here
export NODE_PARENT=/usr/local/bin/nodejs # use this ONLY if you MUST install as root (sudo)
export NODE_PARENT=${HOME}/node-v0.12.0 # Recommended - its owned by you NOT root
export PATH=${NODE_PARENT}/bin:${PATH} # jacks up PATH so executables are found later
export NODE_PATH=${NODE_PARENT}/lib/node_modules # so node itself can find its modules dir
./configure --prefix=${NODE_PARENT}
make -j8 # if you have quad core use -j8 else -j4 ... it parallelizes make
make install
which puts it into dir defined by above --prefix
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
IMPORTANT - put above three export xxx=yyy
commands into your ~/.bashrc or some such to persist these environment variable changes
On subsequent updates to Nodejs, just update your ~/.bashrc with new release name in
your NODE_PARENT env var , then source this ~/.bashrc and simply issue the configure/make/install as above

Installing NPM on AWS EC2

Working on Ec2 on AWS.
I have installed Node.js and it works fine.
But the problem arises when trying to install npm.
I am using the following command to install it:
sudo curl http://npmjs.org/install.sh | sh
But the install seems to freeze...
I get "fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz" at the prompt and it stays on like this.
Have any idea what is going on here?
sudo yum install nodejs npm --enablerepo=epel
Follow this AWS Tutorial that uses Node Version Manager.
Node Version Manager (NVM) lets you install multiple versions of Node.js and switch between them.
Here are the steps:
Install NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Activate NVM
. ~/.nvm/nvm.sh
Install Node (choose version)
nvm install 15.0.0
Confirm Successful Installation
node -e "console.log('Running Node.js ' + process.version)"
To install NodeJS 6.x execute the following commands:
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Update
You can install NodeJS 7 and 8 in the same way. Just specify the version you need instead of 6 in the command above.
Update
To update to NodeJS 16 (or any other version) do the following:
rm -rf /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Simplest way to install npm/nodejs on Amazon Linux 2 ec2 isntance:
First install epel repo using amazon-linux-extras command as below:
sudo amazon-linux-extras install epel
Now install npm and nodejs as below:
sudo yum install nodejs npm
you can verify the version of node and npm as below:
node -v
npm -v
PS. I've tested this on Amazon Linux 2 AMI (HVM) ec2 instance.
This guide worked perfectly: https://tecadmin.net/install-latest-nodejs-amazon-linux/
Make sure you have make
# sudo yum install -y gcc-c++ make
Install source
# curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
Install node
# sudo yum install -y nodejs
Note - you'll have to run sudo npm install to get the installs to work.
Firstly
sudo yum install make
You can run this to get zip of desired version of node
wget https://nodejs.org/dist/v8.10.0/node-v8.10.0.tar.gz
Then you can unzip it like this
tar -xvf node-v8.10.0.tar.gz
then go in to the extracted directory and install node like this
./configure && make && sudo make install
I found his tutorial that has been very usefull to me: The last chapter explains how to install node and npm compiling it.
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/#installNode
Get the http://npmjs.org/install.sh file on your system first and then execute it directly instead of piping with curl.
Use chmod +x install.sh to make it executable
Then run ./install.sh
I did it manually. Why mess with installers that break or don't put things where I want them? Such were the problems encountered while installing *node.js" on Amazon Web Services, that a manual install was the easy way to get the result I wanted.
I want a GLOBAL install of node and npm on AWS. By that I mean install should be put in a place like /usr/bin, so that all users have access. Surprisingly, AWS apparently doesn't give support to that idea. AWS encourages using nvm, node version manager, but that seems to always install in a user directory, and not a system level directory. After being frustrated when the "rpm" solutions (mentioned elsewhere) failed, I finally decided to just do the installation manually.
In a browser, go to nodejs.org download page:
https://nodejs.org/en/download/
Find a link that says:
All download options
Click through that; it goes to an index page with a URL like:
https://nodejs.org/dist/v14.16.1/
There I looked for the name that had "linux" and "x86" in the name.
I wrote this down, or select-and-copied, to get the correct spelling.
In my case it was:
node-v14.16.1-linux-x64.tar.gz
Putting the two parts together, I got the following URL:
https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
So that's what is to be downloaded using curl.
I have a "temp" directory conveniently located in my home dir.
cd ~/temp
The download was accomplished with "curl". Note that the -o option was used to give the output file the name of my choosing. Of course, I chose to give it the same name as the web site file.
curl -o node-v14.16.1-linux-x64.tar.gz https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
Untar the downloaded file.
tar xf node-v14.16.1-linux-x64.tar.gz
Conveniently, it creates its own directory. Go there.
cd node-v14.16.1-linux-x64 || exit 1;
Observe that the delivery consists of a relatively small number of files and directories (since node_modules is dealt with as a unit).
In my case, I had an old and bad implementation still installed, so the following commands were used to move aside any junk that might happen to be in the way. Some commands errored out because the old junk didn't exist. That's ok, error while moving to -OLD just means there is nothing to move; which is good.
Note: I put all these mv (move) commands into a script file, made it executable, and ran it as sudo. The alternative is to run each line individually as sudo.
mv /usr/bin/node /usr/bin/node-OLD
mv /usr/bin/npm /usr/bin/npm-OLD
mv /usr/bin/npx /usr/bin/npx-OLD
mv /usr/include/node /usr/include/node-OLD
mv /usr/lib/node_modules /usr/lib/node_modules-OLD
mv /usr/share/doc/node /usr/share/doc/node-OLD
mv /usr/share/man/man1/node.1 /usr/share/man/man1/node.1-OLD
mv /usr/share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/node.stp-OLD
An here is the actual install. Remember, this is occurring in the untarred directory, in my case node-v14.16.1-linux-x64.
mv bin/node /usr/bin
mv bin/npm /usr/bin
mv bin/npx /usr/bin
mv include/node /usr/include
mv lib/node_modules /usr/lib
mv share/doc/node /usr/share/doc
mv share/man/man1/node.1 /usr/share/man/man1
mv share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/
That's it, all finished.
Latest version 18 has dependency I think..
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
Finally I got solution by running by running following commands.
sudo apt-get remove nodejs
nvm install 16.15.1
v16.15.1 node version and npm v v16.15.1 is installed.
For same make sure nvm is installed in your machine.
This works for me:
sudo apt install npm
Edit as my answer wasn't pertinent anymore:
Try:
curl --silent --location https://rpm.nodesource.com/setup | bash -
yum -y install nodejs
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#enterprise-linux-and-fedora-core

Resources