在LINUX中我们可以使用这种简单的方式让node.js在后台运行:

nohup node your_app.js &

forever可以让我们做得更好,并且可以跨平台的在windows和Linux下都能运行。
 

forever的安装:

npm install forever -g

 

forever的用法:
使用forever启动守护进程:

forever start your_app.js

关闭守护进程:

forever stop your_app.js

重启守护进程::

forever restart your_app.js

如果需要记录输出日志和错误:

forever start -l forever.log -o out.log -e err.log your_app.js

查看正在运行的程序:

forever list

查看forever帮助

forever -h

help: usage: forever [action] [options] SCRIPT [script-options]
help:
help: Monitors the script specified in the current process or as a daemon
help:
help: actions:
help: start Start SCRIPT as a daemon
help: stop Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
help: stopall Stop all running forever scripts
help: restart Restart the daemon SCRIPT
help: restartall Restart all running forever scripts
help: list List all running forever scripts
help: config Lists all forever user configuration
help: set <key> <val> Sets the specified forever config <key>
help: clear <key> Clears the specified forever config <key>
help: logs Lists log files for all forever processes
help: logs <script|index> Tails the logs for <script|index>
help: columns add <col> Adds the specified column to the output in `forever list`
help: columns rm <col> Removed the specified column from the output in `forever list`
help: columns set <cols> Set all columns for the output in `forever list`
help: columns reset Resets all columns to defaults for the output in `forever list`
help: cleanlogs [CAREFUL] Deletes all historical forever log files
help:
help: options:
help: -m MAX Only run the specified script MAX times
help: -l LOGFILE Logs the forever output to LOGFILE
help: -o OUTFILE Logs stdout from child script to OUTFILE
help: -e ERRFILE Logs stderr from child script to ERRFILE
help: -p PATH Base path for all forever related files (pid files, etc.)
help: -c COMMAND COMMAND to execute (defaults to node)
help: -a, --append Append logs
help: -f, --fifo Stream logs to stdout
help: -n, --number Number of log lines to print
help: --pidFile The pid file
help: --uid Process uid, useful as a namespace for processes (must wrap in a string)
help: e.g. forever start --uid "production" app.js
help: forever stop production
help: --sourceDir The source directory for which SCRIPT is relative to
help: --workingDir The working directory in which SCRIPT will execute
help: --minUptime Minimum uptime (millis) for a script to not be considered "spinning"
help: --spinSleepTime Time to wait (millis) between launches of a spinning script.
help: --colors --no-colors will disable output coloring
help: --plain alias of --no-colors
help: -d, --debug Forces forever to log debug output
help: -v, --verbose Turns on the verbose messages from Forever
help: -s, --silent Run the child script silencing stdout and stderr
help: -w, --watch Watch for file changes
help: --watchDirectory Top-level directory to watch from
help: --watchIgnore To ignore pattern when watch is enabled (multiple option is allowed)
help: --killSignal Support exit signal customization (default is SIGKILL)
help: used for restarting script gracefully e.g. --killSignal=SIGTERM
help: -h, --help You're staring at it
help:
help: [Long Running Process]
help: The forever process will continue to run outputting log messages to the console.
help: ex. forever -o out.log -e err.log my-script.js
help:
help: [Daemon]
help: The forever process will run as a daemon which will make the target process start
help: in the background. This is extremely useful for remote starting simple node.js scripts
help: without using nohup. It is recommended to run start with -o -l, & -e.
help: ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
help: forever stop my-daemon.js

forever命令行的中文解释

子命令actions:

  • start:启动守护进程
  • stop:停止守护进程
  • stopall:停止所有的forever进程
  • restart:重启守护进程
  • restartall:重启所有的foever进程
  • list:列表显示forever进程
  • config:列出所有的用户配置项
  • set <key> <val>: 设置用户配置项
  • clear <key>: 清楚用户配置项
  • logs: 列出所有forever进程的日志
  • logs <script|index>: 显示最新的日志
  • columns add <col>: 自定义指标到forever list
  • columns rm <col>: 删除forever list的指标
  • columns set<cols>: 设置所有的指标到forever list
  • cleanlogs: 删除所有的forever历史日志

配置参数options:

  • -m MAX: 运行指定脚本的次数
  • -l LOGFILE: 输出日志到LOGFILE
  • -o OUTFILE: 输出控制台信息到OUTFILE
  • -e ERRFILE: 输出控制台错误在ERRFILE
  • -p PATH: 根目录
  • -c COMMAND: 执行命令,默认是node
  • -a, –append: 合并日志
  • -f, –fifo: 流式日志输出
  • -n, –number: 日志打印行数
  • –pidFile: pid文件
  • –sourceDir: 源代码目录
  • –minUptime: 最小spinn更新时间(ms)
  • –spinSleepTime: 两次spin间隔时间
  • –colors: 控制台输出着色
  • –plain: –no-colors的别名,控制台输出无色
  • -d, –debug: debug模式
  • -v, –verbose: 打印详细输出
  • -s, –silent: 不打印日志和错误信息
  • -w, –watch: 监控文件改变
  • –watchDirectory: 监控顶级目录
  • –watchIgnore: 通过模式匹配忽略监控
  • -h, –help: 命令行帮助信息

转载:http://www.itkubo.com/201310293.html

centos下 forever: 让nodejs应用后台执行的更多相关文章

  1. forever让nodejs应用后台执行

    nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让nodejs应用当成服务,在后台执行呢? 最简单的办法: $ nohup node app.js & ...

  2. [转]forever: 让nodejs应用后台执行

    在LINUX中我们可以使用这种简单的方式让node.js在后台运行: nohup node your_app.js & forever可以让我们做得更好,并且可以跨平台的在windows和Li ...

  3. Android应用开发按下返回键退向后台执行

    转载请注明来源:http://blog.csdn.net/kjunchen/article/details/50429694 Android应用开发按下返回键退向后台执行 我们日常使用的非常多Andr ...

  4. 【服务器】CentOS下部署运行NodeJs Web App

    NodeJs Web App测试完成后,要怎么部署呢?介绍两个不错的方案 已知以下情景: 我要为 「kenniu」这个项目做配置 它的入口文件在 「/path/to/entry.js」 运行的User ...

  5. CentOS下使用crontab命令来定时执行任务

    原文地址:http://www.centoscn.com/CentOS/help/2015/0424/5261.html crontab命令 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说, ...

  6. Odoo8中“更多”下拉菜单选项指定后台执行代码

    在Odoo8中的仓库模块,根据每日最小安全库存数量,系统会自动生成一些补货单,而且是一个产品会生成一笔,如果产品比较多,这里生成的补货单也会很多. 如果这里的补货单没有即时处理,那相同产品后续不会再生 ...

  7. Linux命令行下:把程序放后台执行,以及从后台继续执行程序

    把任务放到后台用 & 和 Ctrl+z 让后台任务从停止状态转为运行状态用 bg %N 把后台任务调回到前台用 fg %N 查看所有任务用jobs

  8. forever让nodejs后台运行

    nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让nodejs应用当成服务,在后台执行呢? 最简单的办法: $ nohup node app.js 但是,for ...

  9. 使用xshell linux安装nodejs,CentOS下安装并配置nodejs环境教程

    1. 下载node最新版本 : 连接   https://nodejs.org/zh-cn/(查看node最新版本) 在跟目录root下,命令行输入: wget https://nodejs.org/ ...

随机推荐

  1. iBatis调用存储过程以及MySQL创建存储过程

    首先是MySQL中创建存储过程的SQL -- 列出全部的存储过程 SHOW PROCEDURE STATUS; -- 查看一个已存在的存储过程的创建语句,假设此存储过程不存在,会提示SQL错误(130 ...

  2. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心

    D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...

  3. [ACM] 最短路算法整理(bellman_ford , SPFA , floyed , dijkstra 思想,步骤及模板)

    以杭电2544题目为例 最短路 Problem Description 在每年的校赛里,全部进入决赛的同学都会获得一件非常美丽的t-shirt. 可是每当我们的工作人员把上百件的衣服从商店运回到赛场的 ...

  4. [xml解析]rapidxml读取文件

    因为项目需要读取xml配置文件,在原来调查一番后,项目组使用了tinyxml. tinyxml确实简单,非常清楚的就把读取方案写出来了.但是,由于后期xml文件越来越大(2.5M,大概1w多行数据), ...

  5. 多系统通讯-DotNetMQ

    很久都没有写博客了,从15年4月份一直忙到现在,我才有时间去做梳理和总结,因为我提离职了,感觉整个世界突然变得不一样,随着而来的就是心情的放松,写一篇文章也是对过去一年多工作的梳理,加深印象 积累和沉 ...

  6. python--判断数据类型可不可变

    内存是一块空间,可以比喻成一个比较大的房子,定义一个变量就是在大房子中建立一个小房子,判断一个数据类型可不可变,就是看在这个这个大房子中有没有新建小房子,可以通过id来判断,如果id没有变化则是不可变 ...

  7. Android反射机制实现与原理

    本文介绍Android反射机制实现与原理,在介绍之前,要和Java进行比较,所以先看下Java中的反射相关知识: 一.反射的概念及在Java中的类反射 反射主要是指程序可以访问.检测和修改它本身状态或 ...

  8. Android_listView

    package com.example.app5; import java.util.ArrayList; import java.util.HashMap; import java.util.Lis ...

  9. plsql 连接oralce数据库,报ora 12557 tns 协议适配器不可加载错误

    使用plsql 连接oracle 数据库报ora 12557 错误: 解决方案: 1:首先确保服务中的service以及监听器都开启 2:F:\app\Administrator\product\11 ...

  10. javascript开发中的封装模式(转)

    var bgAuido={ audio : pingfan.$$('audio'), audioBtn : pingfan.$$('audioBtn'), init : function(){ var ...