What Is forever
Forever can be seen as a Nodejs daemon that can start, stop, and restart our app apps.
The official note is that:
Copy Code code as follows:
A simple CLI tool to ensuring that a given script runs continuously (i.e. forever).
A simple command-line tool for continuing (or forever) running a given script
GitHub Address: Https://github.com/nodejitsu/forever
Forever use
The purpose of forever is to help us better manage our Node app service, essentially creating a node app's subprocess under the forever process.
For example, if you have a express based or some other application, it will be very convenient for you to update and operate your service, and ensure that your service continues to operate.
The better thing is that every time you change a file, it automatically restarts the service without having to restart it manually.
Install Forever
Copy Code code as follows:
Remember to add-g,forever requirements to install to the global environment
sudo npm install forever-g
Forever Use Instructions
Start related
Copy Code code as follows:
1. Easy to start
Forever Start App.js
2. Specify forever information output file, of course, by default it will be placed in ~/.forever/forever.log
Forever Start-l Forever.log App.js
3. Specifies the log information and error log output files in App.js.
-O is the Console.log output information, E is the Console.error output information
Forever Start-o out.log-e Err.log app.js
4. Append log, forever default is unable to overwrite the last boot log,
So if the second boot does not add-a, it will not let the running
Forever Start-l forever.log-a App.js
5. Listen for all file changes under the current folder
Forever Start-w App.js
File changes are monitored and automatically restarted
Copy Code code as follows:
1. Listens for all file changes under the current folder (this is not recommended)
Forever Start-w App.js
Show all running Services
Copy Code code as follows:
Stop operation
Copy Code code as follows:
1. Stop all the running node apps
Forever StopAll
2. Stop one of the node apps
Forever Stop App.js
Of course I can.
The Forever list finds the corresponding ID, and then:
Forever Stop [ID]
Restart operation
The restart operation is consistent with the stop operation.
Copy Code code as follows:
1. Start all
Forever Restartall
Development and online recommended configuration
Copy Code code as follows:
Under development environment
Node_env=development Forever start-l forever.log-e err.log-a app.js
In the online environment
Node_env=production Forever start-l ~/.forever/forever.log-e ~/.forever/err.log-w-a app.js
Add node_env to allow App.js to identify what the current environment is. Without it, you might not know it.
Some attention.
It is possible that you need to use the crontab (timed task) under Unix
This time you need to pay attention to configuring environment variables.
Copy Code code as follows:
Shell=/bin/sh
Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin