Manage with Forever under Linux

Source: Internet
Author: User

What is forever:
Forever can be seen as a Nodejs daemon that can start, stop, and restart our app.
The official note is that:
A Simple CLI tool for ensuring, 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 child process for the node app under the forever process.
For example, if you have an express-based or some other application then it will be convenient for you to update and operate your service and ensure that your service will continue to operate.
The better thing is that every time you change a file, it can help you automatically restart the service without requiring a manual restart.

Installing Forever
Remember to add-g,forever required to install in the global environment

Install forever-g

Forever Instructions for use:

Start related
1. Simple Start-up

Forever Start App.js

2. Specify forever information output file, of course, it will be put to ~/.forever/forever.log

Or you can see the corresponding log through the Forever list.

Forever Start-l Forever.log App.js

3. Specify the log information and error log output files in the 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 the log, forever default is not to overwrite the last boot log,

So if the second boot does not add-a, it will not let the run

Forever Start-l forever.log-a App.js

5. Listen for all file changes under the current folder (file change monitoring and automatic restart)

Forever Start-w app.js

The code is as follows:

1. Listen for all file changes under the current folder (not recommended)

Forever Start-w app.js

To display all running services:

Forever List

To stop the operation:

Stop all the running node apps

Forever StopAll

Stop one of the node apps

Forever Stop App.js

Of course you can do that.

Forever list to find the corresponding ID, and then:
Forever Stop [ID]

Restart operation
The restart operation is consistent with the stop operation

Start All:

Forever Restartall

Development and on-line recommended configuration

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 let app.js identify what environment is currently used. Without it, you might not know?

Some points of attention
It is possible that you need to use Crontab under UNIX (Scheduled Tasks)
This time you need to be aware of configuring environment variables.


The code is as follows:

shell=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Manage with Forever under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.