Think before you speak, read before you think.

nodejs-forever

node.js的forever可保证进程挂掉之后重启,保证高可用

Monitors the script specified in the current process or as a daemon

[Daemon]                                                                                                                                                                     

  The forever process will run as a daemon which will make the target process start

  in the background. This is extremely useful for remote starting simple node.js scripts

  without using nohup. It is recommended to run start with -o -l, & -e.

  ex. forever start -l forever.log -o out.log -e err.log my-daemon.js

常用动作有

start Start SCRIPT as a daemon
stop Stop the daemon SCRIPT
stopall Stop all running forever scripts
restart Restart the daemon SCRIPT
restartall Restart all running forever scripts
list List all running forever scripts
config Lists all forever user configuration
set Sets the specified forever config
clear Clears the specified forever config
logs Lists log files for all forever processes
logs <script|index> Tails the logs for <script|index>
columns add
Adds the specified column to the output in `forever list`
columns rm
Removed the specified column from the output in `forever list`
columns set Set all columns for the output in `forever list`
columns reset Resets all columns to defaults for the output in `forever list`
cleanlogs [CAREFUL] Deletes all historical forever log files

例子:

查看被forever启动的进程

forever list

重启具体某一个脚本,如果不知道绝对路径,forever会自动匹配重启

forever restart myscript.js

–sourceDir指定js脚本位置

forever stop --sourceDir=/data/nodejs/ start.js

-l 指定log所在位置, -e 指定错误日志,-o指console的输出,-a 追加的方式,平时使用时最好把-l, -e, -o全用上。

forever start -l /var/log/nodejs/log -e /var/log/nodejs/error -o /var/log/nodejs/out.log -a --sourceDir=/data/nodejs start.js

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *