npm command not found pm2: command not found - pm2

NVM node is installed under Ubuntu19.04 but local pm2 deploy production update will report errors such as pm2: command not found
On the remote server
root#vultr:/usr/bin# git --version
git version 2.20.1
root#vultr:/usr/bin# nvm --version
0.34.0
root#vultr:/usr/bin# node -v
v10.15.3
root#vultr:/usr/bin# npm -v
6.4.1
On the local server
pm2 deploy production update
--> Deploying to production environment
--> on host 202.182.98.13
○ deploying origin/master
○ executing pre-deploy-local
○ hook pre-deploy
○ fast forward master
Already on 'master'
Your branch is up to date with 'origin/master'.
From github.com:zq0904/pm2
Updating d79b633..2fe1d22
Fast-forward
README.md | 3 ++-
ecosystem.config.js | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
* branch master -> FETCH_HEAD
d79b633..2fe1d22 master -> origin/master
○ executing post-deploy `git pull && npm install && pm2 reload ecosystem.config.js --env production`
Already up to date.
npm WARN 06-pm2#1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
up to date in 3.997s
pm2: command not found
post-deploy hook failed
Deploy failed
1
I can do it on a remote server
whereis npm
lh -s /root/.nvm/versions/node/v10.15.3/bin/node /usr/bin/node
lh -s /root/.nvm/versions/node/v10.15.3/bin/npm /usr/bin/npm
lh -s /root/.nvm/versions/node/v10.15.3/bin/pm2 /usr/bin/pm2
That would solve the problem,
But I don't understand why,
The server can already output NPM node pm2 and other versions,
But why do I have to set up a soft connection?
Is there any good solution to this troublesome problem,
Thank you very much!

I am not sure what's the route cause of this issue. But, it was happening to me when I created a new user in AWS EC2 ubuntu instance and try to deploy my NodeJS app using pm2 through that new user.
I followed this github thread and this particular comment solved my issue. Simply comment the following line in your server's .bashrc file
#If not running interactively, don 't do anything
case $ - in
*
i * );;
*) return;;
esac

Related

Error installing RMySQL to run in Docker on Mac OS X

I am trying to run MySQL in an R script running inside a Docker (actually Rocker) container, but am getting an error on the “install_packages(…” step. The only solution I found that was somewhat similar was specific to running RedHat Linux (I am running Mac OS X 10.15) and the solution included pointing to several directories that I do not have. Running under RStudio or from the command line, RMySQL loads without a problem.
Dockerfile:
FROM rocker/r-ver:latest
RUN mkdir /home/analysis
COPY install_packages.R /home/analysis/install_packages.R
COPY script_basic.R /home/analysis/script_basic.R
RUN Rscript /home/analysis/install_packages.R
CMD Rscript /home/analysis/script_basic.R
R files:
script_basic.R
library( RMySQL )
install_packages.R
install_packages(“RMySQL”)
Commands and responses:
$ docker build -t myapp .
…
Successfully tagged myapp:latest
$ docker run -it --rm myapp
Loading required package: DBI
Error: package or namespace load failed for ‘RMySQL’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/RMySQL/libs/RMySQL.so':
libmysqlclient.so.21: cannot open shared object file: No such file or directory
Execution halted
$
I believe that rocker/r-dev does not include the libraries you need to get this to run. Untested, but try something like this.
Dockerfile
FROM rocker/r-ver:latest
RUN mkdir /home/analysis
RUN apt-get update \
&& apt-get install -y --no-install-recommends libmariadbclient-dev
COPY install_packages.R /home/analysis/install_packages.R
COPY script_basic.R /home/analysis/script_basic.R
RUN Rscript /home/analysis/install_packages.R
CMD Rscript /home/analysis/script_basic.R
You can find the need for certain libraries on https://cran.r-project.org/web/packages/RMySQL/index.html, as
SystemRequirements: libmariadb-client-dev | libmariadb-client-lgpl-dev | libmysqlclient-dev (deb), mariadb-devel (rpm), mariadb | mysql-connector-c (brew), mysql56_dev (csw)
and a note on how to install them in RMySQL's github README.md's Installation section.
(The CRAN page references libmysqlclient-dev, but the github page suggests "the mariadb implementation is much better". I don't know the premise of the statement, just explaining why I suggested one and CRAN listed another.)

How do I specify a repo for yum install in aws beanstalk file install_packages.config?

I need to install sshpass on my AWS beanstalk when it is deployed.
I created a new clone to check that I could do it from the ssh shell command line and found that unless I specified the epel repo, it would not find the package:
$ sudo yum -y install sshpass
Failed to set locale, defaulting to C
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00
amzn-updates | 2.5 kB 00:00:00
No package sshpass available.
Error: Nothing to do
but this works:
$ sudo yum --enablerepo=epel -y install sshpass
Failed to set locale, defaulting to C
Loaded plugins: priorities, update-motd, upgrade-helper
1070 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package sshpass.x86_64 0:1.06-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
sshpass x86_64 1.06-1.el6 epel 20 k
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total download size: 20 k
Installed size: 34 k
Downloading packages:
sshpass-1.06-1.el6.x86_64.rpm | 20 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : sshpass-1.06-1.el6.x86_64 1/1
Verifying : sshpass-1.06-1.el6.x86_64 1/1
Installed:
sshpass.x86_64 0:1.06-1.el6
Complete!
So how would I do this in the .ebextensions/-1-packages/install-packages.config file?
The syntax is defined in the AWS example as follows:
packages:
yum:
libmemcached: []
ruby-devel: []
gcc: []
rpm:
epel: http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rubygems:
chef: '0.10.2'
But I'm not sure how to implement that for my case where i just want to tell it to use the epel repo
packages:
yum:
...
...
sshpass: []
I'm guessing the above won't automatically cause it to use the epel repo?
There might be a better way, but this worked:
commands:
24-sshpass:
command: "yum --enablerepo=epel -y install sshpass"

Run statsd as a daemon on EC2 instances programatically

EDIT: My goal is to be able to emit metrics from my spring-boot application and have them sent to a Graphite server. For that I am trying to set up statsd. If you can suggest a cleaner approach, that would be better.
I have a Beanstalk application which requires statsd to run as a background process. I was able to specify commands and packages through ebextensions config file as follows:
packages:
yum:
git: []
commands:
01_nodejs_install:
command: sudo yum -y install nodejs npm --enablerepo=epel
ignoreErrors: true
02_mkdir_statsd:
command: mkdir /home/ec2-user/statsd
03_fetch_statsd:
command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
ignoreErrors: true
04_run_statsd:
command: node stats.js exampleConfig.js
cwd: /home/ec2-user/statsd
When I try to deploy the application to a new environment, the EC2 node never comes up fully. I logged in to check what might be going on and noticed in /var/log/cfn-init.log that 01_nodejs_install, 02_mkdir_statsd and 03_fetch_statsd were executed successfully. So I guess the system was stuck on the fourth command (04_run_statsd).
2016-05-24 01:25:09,769 [INFO] Yum installed [u'git']
2016-05-24 01:25:37,751 [INFO] Command 01_nodejs_install succeeded
2016-05-24 01:25:37,755 [INFO] Command 02_mkdir_statsd succeeded
2016-05-24 01:25:38,700 [INFO] Command 03_fetch_statsd succeeded
cfn-init.log (END)
I need help with the following:
If there is a better way to install and run statsd while instantiating an environment, I would appreciate if you could provide details on that approach. This current scheme seems hacky.
If this is the approach I need to stick with, how can I run the fourth command so that statsd can be run as a background process?
Tried a few things and found that the following ebextensions configs work:
packages:
yum:
git: []
commands:
01_nodejs_install:
command: sudo yum -y install nodejs npm --enablerepo=epel
ignoreErrors: true
02_mkdir_statsd:
command: mkdir /home/ec2-user/statsd
03_fetch_statsd:
command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
ignoreErrors: true
04_change_config:
command: cat exampleConfig.js | sed 's/2003/<graphite server port>/g' | sed 's/graphite.example.com/my.graphite.server.hostname/g' > config.js
cwd: /home/ec2-user/statsd
05_run_statsd:
command: setsid node stats.js config.js >/dev/null 2>&1 < /dev/null &
cwd: /home/ec2-user/statsd
Note that I added another command (04_change_config) so that I may configure my own Graphite server and port in statsd configs. This change is not needed to address the original question, though.
The actual run command uses setsid to run the command as a daemon.

Cygnus installation

I try to install cygnus. I install yum install java-1.6.0-openjdk-devel and run , my problem is:
Then, the developed classes must be packaged in a Java jar file which must be added to the APACHE_FLUME_HOME/lib directory:
$ git clone https://github.com/telefonicaid/fiware-connectors.git
$ git checkout release/0.1
$ cd fiware-connectors/flume
$ APACHE_MAVEN_HOME/bin/mvn package
$ cp target/cosmos-injector-1.0-SNAPSHOT.jar APACHE_FLUME_HOME/lib
in this step, I create cygnus.jar not cosmos-injector-1.0-SNAPSHOT.jar , and # APACHE_FLUME_HOME/conf/cosmos-injector.conf not exist on my flume directory.
Alejandro, I recommend you to install last version of Cygnus (currenty, 0.7.1), which can be installed through RPM packages (recommended). Simply configure the FIWARE repo and install it using yum (CentOS):
$ sudo cat > /etc/yum.repos.d/fiware.repo <<EOL [Fiware]
name=FIWARE
repository baseurl=http://repositories.testbed.fi-ware.eu/repo/rpm/x86_64/
gpgcheck=0
enabled=1
EOL
$ yum install cygnus
You can find the Cygnus Quick Start Guide at this link.
The README will give you extended information about the tool.
Advanced topics can be found at the doc/ folder.

OpenShift Origin on Fedora 19

I have problem to deploy OpenShift Origin on Fedora 19. I'm getting error:
Preflight check: verifying system and resource availability.
Checking broker.example.com:
* SSH connection succeeded
* Target host is running non-Fedora, non-RHEL
* Located getenforce
* SELinux is running in please login as the user "fedora" rather than
the user "root". mode
* Located yum
* Located puppet
* Located augtool
* Located dnssec-keygen
* Located htpasswd
* Located scl
* ERROR: The ruby193 software collection is not installed. Correct
this by running `yum install ruby193` on this system.
* ERROR: The 'epel' repository isn't available via yum. Install /
enable this repository and try again.
That's weird:
Target host is running non-Fedora, non-RHEL
Release:
[root#broker tmp]# cat /etc/issue
Fedora release 19 (Schrödinger’s Cat)
Kernel \r on an \m (\l)
I'm not able to install ruby193 via yum. Dependency problem. Fedora 19 has ruby version 2.0.0. Log from installation of ruby193: http://pastebin.com/raw.php?i=TpJEF4Rw
So I'm using rvm:
[root#broker tmp]# ruby -v
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]
[root#broker tmp]#
At the end, I'm installing Origin by:
sh <(curl -s https://install.openshift.com/)
And my configuration file: http://pastebin.com/raw.php?i=sSgYVVMt
I figured out that problem was in ssh check. I was not able to ssh to broker but installation script was facing as if ssh is OK.
Needed packages: (yum -y install) ruby unzip httpd-tools puppet augeas bind
Interesting. I solved it by adding repos and install some things:
cat <<EOF> /etc/yum.repos.d/openshift-origin-deps.repo
[openshift-origin-deps]
name=openshift-origin-deps
baseurl=http://mirror.openshift.com/pub/origin-server/release/3/fedora-19/dependencies/x86_64/
gpgcheck=0
enabled=1
EOF
cat <<EOF> /etc/yum.repos.d/openshift-origin.repo
[openshift-origin]
name=openshift-origin
baseurl=http://mirror.openshift.com/pub/origin-server/release/3/fedora-19/packages/x86_64/
gpgcheck=0
enabled=1
EOF
yum clean all
yum -y update
yum -y install ruby unzip httpd-tools puppet bind vim rubygem-openshift-origin-container-selinux</strike>
I would email this to the openshift origin users list here (https://lists.openshift.redhat.com/openshiftmm/listinfo/users) alot of the developers are on that list and should be able to help you with a solution. Then once you have one come back here and update us so that if anyone else runs into it they'll have something to reference.