I am getting this error, verdaccio just crashed and no longer working after a server restart. When I try to pm2 start verdaccio , I get the following error
Error: Cannot find module '/home/ec2-user/verdaccio'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:53:21)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
npm config ls
; cli configs
scope = ""
user-agent = "npm/4.2.0 node/v7.10.0 linux x64"
; userconfig /home/ec2-user/.npmrc
http-proxy = null
https-proxy = null
registry = "https://registry.npmjs.org/"
strict-ssl = false
; globalconfig /usr/etc/npmrc
registry = "https://registry.npmjs.org/"
; node bin location = /usr/bin/node
; cwd = /home/ec2-user/verdaccio
; HOME = /home/ec2-user
; "npm config ls -l" to show all defaults.
pm2 show verdaccio
│ name │ verdaccio │
│ restarts │ 255 │
│ uptime │ 0 │
│ script path │ /home/ec2-user/verdaccio │
│ script args │ N/A │
│ error log path │ /home/ec2-user/.pm2/logs/verdaccio-error-0.log │
│ out log path │ /home/ec2-user/.pm2/logs/verdaccio-out-0.log │
│ pid path │ /home/ec2-user/.pm2/pids/verdaccio-0.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 0 │
│ exec cwd │ /home/ec2-user │
│ exec mode │ fork_mode │
│ node.js version │ 7.10.0 │
│ watch & reload │ ✘ │
│ unstable restarts │ 0 │
│ created at │ N/A
`
My config file is as follows:
storage: ./storage
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'av-*':
allow_access: $all
allow_publish: $all
'*':
allow_access: $all
allow_publish: $all
proxy: npmjs
'#*/*':
allow_access: $all
allow_publish: $authenticated
proxy: npmjs
https:
key: /home/ec2-user/verdaccio/verdaccio-keynew.pem
cert: /home/ec2-user/verdaccio/verdaccio-certnew.pem
ca: /home/ec2-user/verdaccio/server.ca
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: verdaccio.log, level: info}
listen:
- https://devnpm2:4873
max_body_size: 300mb
It can't find the verdaccio executable, to locate it you can use the which command.
To do this you should try:
pm2 start `which verdaccio`
Related
I am running a node js app on nginx/digital ocean .
When i try to run pm2 start app.js i get this
┌─────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ app │ default │ 1.2.0 │ fork │ 0 │ 0 │ 30 │ errored │ 0% │ 0b │ root │ disabled │
│ 1 │ app │ default │ 1.2.0 │ fork │ 49014 │ 0s │ 0 │ online │ 0% │ 15.1mb │ root │ disabled │
└─────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
**
when i try "node app.js" looks like this**
node:events:491
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::4000
at Server.setupListenHandle [as _listen2] (node:net:1733:16)
at listenInCluster (node:net:1781:12)
at Server.listen (node:net:1869:7)
at Function.listen (/var/www/delivery.emms.io/html/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/var/www/delivery.emms.io/html/app.js:114:5)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1760:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 4000
}
i tried getting the PID and using kill -9 but no success
any ideas?
In the documentation for highcharts-export-server : it says that you should use PM2 to run it as a server but I just can't get this to work on my Windows machine.
I have no problem to run it from the command line :
highcharts-export-server --enableServer 1
However when I run :
pm2 start highcharts-export-server -- --enableServer 1
I get :
[PM2] Applying action restartProcessId on app [highcharts-export-server](ids: [ 0 ])
[PM2] [highcharts-export-server](0) ✓
[PM2] Process successfully started
┌─────┬─────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬─────── ─┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ highcharts-export-server │ default │ N/A │ fork │ 13916 │ 0 │ 50 │ stopped │ 0% │ 0b │ <ME> │ disabled │
└─────┴─────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
It doesn't work and I get this error multiple times in highcharts-export-server-error.log :
C:\USERS\<ME>\APPDATA\ROAMING\NPM\HIGHCHARTS-EXPORT-SERVER.CMD:1
#ECHO off
^
SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Object.<anonymous> (C:\Users\lars\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
I don't undertand what I'm doing wrong here because this works flawlessly on my Mac machine
When trying to run npm start, I get the error:
Error: EACCES: permission denied, open '/root/.pm2/module_conf.json'
at Object.openSync (node:fs:582:3)
at Object.readFileSync (node:fs:450:35)
at Object.Configuration.getAllSync (/usr/local/lib/node_modules/pm2/lib/Configuration.js:299:26)
at Object.Configuration.getSync (/usr/local/lib/node_modules/pm2/lib/Configuration.js:270:30)
at new API (/usr/local/lib/node_modules/pm2/lib/API.js:117:44)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/binaries/CLI.js:22:11)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
/usr/local/lib/node_modules/pm2/node_modules/#pm2/agent/src/InteractorClient.js:58
if (stats.uid === 0) {
^
TypeError: Cannot read property 'uid' of undefined
at /usr/local/lib/node_modules/pm2/node_modules/#pm2/agent/src/InteractorClient.js:58:21
at FSReqCallback.oncomplete (node:fs:195:21)
the command in package.json looks like this
{
"scripts": {
"start": "pm2 start ./node_modules/laravel-echo-server/dist/index.js"
},
"dependencies": {
"laravel-echo-server": "^1.6.2",
"save": "^2.4.0"
}
}
But if I run the command in the terminal
pm2 start ./node_modules/laravel-echo-server/dist/index.js
it works fine
/app # pm2 start ./node_modules/laravel-echo-server/dist/index.js
[PM2] Starting /app/node_modules/laravel-echo-server/dist/index.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ index │ default │ 1.6.2 │ fork │ 13626 │ 0s │ 0 │ online │ 0% │ 7.6mb │ root │ disabled │
│ 0 │ laravelEcho │ default │ 1.6.2 │ fork │ 13608 │ 1s │ 1207 │ online │ 0% │ 69.6mb │ root │ disabled │
└─────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. Type 'pm2 save' to synchronize.
After searching the internet for a solution to the problem, I saw a possible solution, but it didn't work for me either.
This solution was to create an ecosystem.config.js file
here is an example with this solution but it doesn't work either
package.json
{
"scripts": {
"start": "pm2 start ecosystem.config.js"
},
"dependencies": {
"laravel-echo-server": "^1.6.2",
"save": "^2.4.0"
}
}
ecosystem.config.js
module.exports = {
apps : [
{
name: "laravelEcho",
script: "./node_modules/laravel-echo-server/dist/index.js",
args : "start"
}
]
}
Perhaps this will help when looking for the problem, I am using Docker
Dockerfile
FROM node:alpine
WORKDIR /app
RUN npm install pm2:2.9.2 -g && pm2 update
EXPOSE 8888
What could be the problem?
not sure it's great to run it as root, have a look here on pm2s git repo on user access: Starting PM2 as a non-root user is broken
i think you can fix the "permission denied" with running this as su so just run sudo npm start but because i can't code in js i can't help you with the errors i'm sorry!:/
I hope i could help you anyways a little bit!!
I am using PM2 with the following configuration:
module.exports = {
apps : [{
name: 'sandbox',
script: 'index.js',
args: ["PORT=8084", "--color"],
instances: 1,
autorestart: true,
watch: 'index.js',
out_file: "logs/out.log",
node_args: "--trace-warnings"
}]
};
All works well except that changes in index.js doesn't trigger restart.
I have tried many things:
adding the absolute path in script and in the watch
adding cwd with the absolute path
Using variations in the watch like ./index.js or ../ or ./ or true
Removing autorestart
Additional info:
My app use express
The status shows that watch is enabled:
│ status │ online
│ name │ sandbox
│ version │ 1.0.0
│ restarts │ 0
│ uptime │ 8m │
│ script path │ /var/www/api/index.js │
│ script args │ PORT=8084 --color │
│ error log path │ /home/ubuntu/.pm2/logs/sandbox-error-10.log │
│ out log path │ /var/www/api/logs/out-10.log │
│ pid path │ /home/ubuntu/.pm2/pids/sandbox-10.pid │
│ interpreter │ node │
│ interpreter args │ --trace-warnings │
│ script id │ 10 │
│ exec cwd │ /var/www/api │
│ exec mode │ cluster_mode │
│ node.js version │ 11.10.0 │
│ node env │ N/A │
│ watch & reload │ ✔ │
│ unstable restarts │ 0 │
│ created at │ 2019-11-30T10:45:14.704Z
I usually do pm2 stop to stop my application and it works fine.
However, when I just tried the pm2 delete on my app and starting it again, it doesn't seem to work anymore.
This is the pm2 error log I retrieved. No code was changed so I think it might be some ECONNRESET error from abrupt shutdown? (there wasn't any cleanup code)
Also tried killing the pid of pm2 and mongod when I find it using ps -ef and also pm2 kill and restarting of mongod to no avail.
Error: Invalid mongodb uri. Must begin with "mongodb://"
Received: NaN
at muri (/home/ubuntu/portal/node_modules/muri/lib/index.js:28:11)
at NativeConnection.Connection.openUri (/home/ubuntu/portal/node_modules/mongoose/lib/connection.js:713:18)
at Mongoose.createConnection (/home/ubuntu/portal/node_modules/mongoose/lib/index.js:198:17)
at Object.<anonymous> (/home/ubuntu/portal/models/stopwords.js:11:19)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/ubuntu/portal/helpers/database/helper_mongodb.js:2:19)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/ubuntu/portal/controllers/inf_controller.js:2:19)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
Code for stopwords.js:11:19 is
let db = mongoose.createConnection(process.env.MONGODB_URI + process.env.MONGODB_HELPER_DB, { useMongoClient: true })
As we commented, and as you did, I also solved my problems using pm2
+ grunt to run my express.js app. Will try to explain here the solution to close the question.
The way to start and stop pm2 with different apps and without trouble
was with an ecosystem file where I configured my node apps.(centOS apache)
my ecosystem file
-bash-4.2$ pm2 ecosystem
File /var/www/vhosts/domain.com/ecosystem.config.js
[...]
-bash-4.2$ cat ecosystem.config.js
module.exports = {
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps : [
// First application
{
name : 'DomainProd',
cwd : '/var/www/vhosts/domain.com/httpdocs/App',
script : 'start.sh'
},
{
name : 'DomainTest',
cwd : '/var/www/vhosts/domain.com/testing.domain.com/httpdocs/App',
script : 'start-test.sh'
}
]
};
the start.sh script
-bash-4.2$ cat /var/www/vhosts/domain.com/httpdocs/App/start.sh
/usr/bin/grunt serve:prod
-bash-4.2$
The serve task on my Gruntfile
return grunt.task.run(['concurrent:cleanandbuild', 'build', 'env:all', 'env:prod', 'express:prod', 'wait', 'express-keepalive']);
The run example:
-bash-4.2$ pm2 status
┌────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
├────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────────┼──────────┤
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63 │ 20D │ 0% │ 264.1 MB │ disabled │
│ DomainTest │ 1 │ fork │ 25526 │ online │ 295 │ 113m │ 0% │ 1.2 MB │ disabled │
└────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
-bash-4.2$ pm2 stop 1
[PM2] Applying action stopProcessId on app [1](ids: 1)
[PM2] [Domainest](1) ✓
┌────────────┬────┬──────┬───────┬─────────┬─────────┬────────┬─────┬────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
├────────────┼────┼──────┼───────┼─────────┼─────────┼────────┼─────┼────────────┼──────────┤
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63 │ 20D │ 0% │ 264.1 MB │ disabled │
│ DomainTest │ 1 │ fork │ 0 │ stopped │ 295 │ 0 │ 0% │ 0 B │ disabled │
└────────────┴────┴──────┴───────┴─────────┴─────────┴────────┴─────┴────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
-bash-4.2$ pm2 start 1
[PM2] Applying action restartProcessId on app [1](ids: 1)
[PM2] [DomainTest](1) ✓
[PM2] Process successfully started
┌────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
├────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────────┼──────────┤
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63 │ 20D │ 0% │ 264.1 MB │ disabled │
│ DomainTest │ 1 │ fork │ 29816 │ online │ 295 │ 0s │ 0% │ 1.2 MB │ disabled │
└────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
-bash-4.2$ pm2 logs 1
[TAILING] Tailing last 15 lines for [1] process (change the value with --lines option)
/var/www/vhosts/domain.com/.pm2/logs/DomainTest-out-1.log last 15 lines:
1|DomainTe | Execution Time (2017-10-02 19:33:24 UTC+2)
1|DomainTe | loading tasks 579ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 92%
1|DomainTe | clean:server 47ms ▇▇▇▇ 7%
1|DomainTe | Total 632ms
1|DomainTe |
1|DomainTe | Running "clean:dist" (clean) task
1|DomainTe | >> 5 paths cleaned.
1|DomainTe |
1|DomainTe | Done, without errors.
1|DomainTe |
1|DomainTe |
1|DomainTe | Execution Time (2017-10-02 19:33:24 UTC+2)
1|DomainTe | loading tasks 570ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 55%
1|DomainTe | clean:dist 456ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 44%
1|DomainTe | Total 1s
[STREAMING] Now streaming realtime logs for [1] process
Hope it helps anyone arriving here.