I am installing an SailsJS app on an Amazon Ubuntu instance.
If I run the app with sails lift everything works and the program run successfully. Now I try to run it through forever for obvious reasons. As specified by the SailsJS documentation I run forever on the app.js file located at the root of my project : forever start app.js
But that time the app fails :
forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] XXXX /usr/bin/nodejs app.js 15348 15350 /home/ubuntu/.forever/XXXX.log STOPPED
Logfile contains only :
error: Forever detected script exited with code: 0
Any idea why sails lift would work but not with forever ?
Sometimes there are permissions errors. Try to verify forver's permissions files in .forever directory or maybe run with sudo.
I run forever start app.js with sudo and I did't have any problems.
After that sudo forever list a get:
data: [0] kBdX /usr/bin/nodejs app.js 23533 23538 /home/ubuntu/.forever/kBdX.log 0:0:34:28.312
Related
When I start pm2, I get this
Error: ENOENT: no such file or directory, open 'C:\WINDOWS\system32\.pm2\module_conf.json'
how can I fix this?
1 . Add user environment variable as below:
PM2_HOME=%USERPROFILE%\.pm2
2 . Restart command line
cmd
3 . Then kill pm2 daemon once
pm2 kill
4 . Now run pm2 as usual (An example is below)
pm2 start ./bin/www
I learning NodeJS. I have ubuntu 16 server with installed nodejs. Then i install globally express-generator and forever. Next i maked a folder into /var/www named as hack-it-up.ru and used express-generator to generate the app. Next i changed port of my app as 8081 and tryed to start it with npm start. All works fine. But... when i tryed to start my app with forever, i got errors. I readed lots of guides but didnt solved it. Help me please. Thanks!
root#ashipka:/var/www/hack-it-up.ru# forever start -l /var/www/forever-logs/hack-it.log -a app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
root#ashipka:/var/www/hack-it-up.ru# forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] aj4I /usr/local/bin/node app.js 27060 27066 /root/.forever/aj4I.log STOPPED
data: [1] wFf4 /usr/local/bin/node app.js 27147 27153 /var/www/forever-logs/hack-it.log STOPPED
root#ashipka:/var/www/hack-it-up.ru# forever stop 0
error: Forever cannot find process with id: 0
I needed to start from bin/www file instead of app.js as said Mohit Bhardwaj. Thanks! All works fine.
I have strange problem with nodejs forever.
I have cloned iodocs to /home/user/iodocs
If I start forever from iodocs directory:
user#ubuntu:~/iodocs$ forever start app.js
everything is working fine.
If I try start forever from another directory, for example:
user#ubuntu:~$ forever start --sourceDir /home/user/iodocs/ app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
In log file I have seen:
user#ubuntu:~$ forever logs
info: Logs for running Forever processes
data: script logfile
data: [0] /home/user/iodocs/app.js /home/user/.forever/xYBf.log
user#ubuntu:~$ cat /home/user/.forever/xYBf.log
File /home/user/config.json not found or is invalid. Try: `cp config.json.sample config.json`
error: Forever detected script exited with code: 1
Why forever try to read config from unix user home directory instead sourceDir?
How to fix it?
I just installed forever globally (-g). Before that I used to run with
$ npm start
Now after installed forever, I tried to lunch the node app
$ NODE_ENV=development forever nodemon server.js
but I receive this error
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
error: Cannot start forever
error: script /path/to/app/nodemon does not exist.
the same also with
$ NODE_ENV=development forever nodemon server.js
any idea?
The error you received in your output:
error: script /path/to/app/nodemon does not exist.
It appears that forever is looking for nodemon in the current working directory, and can't find it because it doesn't exist there. Try providing the absolute path when starting nodemon, which can be found with which nodemon.
forever start /usr/local/bin/nodemon server.js
Note that the start flag is what puts the application in daemon mode.
Try this
NODE_ENV=development forever start -c nodemon server.js
The -c is for execute commands, forever send you that error because it's looking for a app called nodeamon, but your app is server.js
The command I run on my server to start my node app is:
sudo IS_PROD=1 node app.js
I have forever installed but can't seem to pass in the environment variable.
sudo IS_PROD=1 forever node app.js
Doesn't seem to do the trick. I have tried several varieties of this. How do I either execute this command successfully or permanently set the environment variable?
First of all you should skip the node thing in you command, it should not be there, you should not be able to execute that. forever automatically starts your script using nodejs. Instead you should do like this;
sudo IS_PROD=1 forever app.js
Probably you, instead of starting your server in foreground, will want to start your server as a daemon. eg.
sudo IS_PROD=1 forever start app.js
This will create a process in the background that will watch your node app and restart it when it exits. For more information see the readme.
Both of these methods preserves the environment variables, just like when you are just using node.
app.js:
console.log(process.env.IS_PROD);
Using node (v0.8.21)
$ node app.js
undefined
$ IS_PROD=1 node app.js
1
$ sudo IS_PROD=1 node app.js
1
Using forever (v0.10.0)
$ forever app.js
undefined
$ IS_PROD=1 forever app.js
1
$ sudo IS_PROD=1 forever app.js
1
Documentation:
process.env
An object containing the user environment. See environ(7).