This article is a mirror article of machine translation, please click here to jump to the original article.

View: 7945|Reply: 0

node.js start the process Patronus forever

[Copy link]
Posted on 12/6/2016 9:27:26 AM | | | |
What is forever?
Forever can be thought of as a nodejs daemon that can start, stop, and restart our apps.
The official note says:
A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).
A simple command-line tool for running a given script continuously (or forever).
Github address: https://github.com/nodejitsu/forever

Forever has a purpose
The purpose of forever is to help us better manage our node app service, essentially creating a sub-process of the node app under the forever process.
For example, if you have an express-based or other application, it will be easy for you to update and operate your service, and it will ensure that your service continues to run.
Even better, it helps you automatically restart the service every time you change a file without having to restart it manually.
-------------------------- can add my WeChat ID: googlecao to communicate---------------------------

forever install
Remember to add -g, forever requires installation into the global environment



forever instructions
// 1. Simple start-up


// 2. Specify the forever information output file, of course, it will be placed in ~/.forever/forever.log by default


// 3. Specify the log information and error log output files in the app.js,
-o is the information output by the console.log, and -e is the information output by console.error


// 4. Add logs, forever cannot overwrite the last startup log by default,
So if the second start does not add -a, it will not run


// 5. Listen for all file changes under the current folder


Displays all running services


Listen for file changes and automatically restart
// 1. Listen for all file changes under the current folder (not recommended)

Stop the operation

// 1. Stop all running node apps


// 2. Stop one of the node apps

Of course it can be so
forever list, then:


Restart the operation
The restart operation is the same as the stop operation.
// 1. Launch all


Development and online recommended configurations
development environment

In an online environment


The NODE_ENV is added above so that app.js can identify what environment it is currently used for. If you don't add it, you may not know, right?

It is possible that you need to use crontab (timed tasks) under UNIX
At this time, you need to pay attention to configuring environment variables.



To make Forever run automatically, we first create a file node in the /etc/init.d directory, which reads:


The above code is my configuration in the local virtual machine, modify the relevant parameters according to the actual situation, mainly the path parameters of DEAMON, give the file executable permissions, and run chkconfig to add automatic running:



Reboot the system, enter the website through the browser, and you can find that the NodeJS can run automatically......





Previous:Install node.js deploy Express projects under CentOS
Next:Winform command line compile build program
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com