forever让nodejs应用后台执行

命令如下:

forever start './bin/www'

nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人。如何让nodejs应用当成服务,在后台执行呢?

最简单的办法(不推荐):

$ nohup node app.js &

但是,forever能做更多的事情,比如分别记录输出和错误日志,比如可以在js中作为api使用。

forever安装:

$ sudo npm install forever -g   #安装
$ forever start app.js #启动
$ forever stop app.js #关闭
$ forever start -l forever.log -o out.log -e err.log app.js #输出日志和错误
$ forever --help
usage: forever [action] [options] SCRIPT [script-options] Monitors the script specified in the current process or as a daemon actions:
start Start SCRIPT as a daemon
stop Stop the daemon SCRIPT by Id|Uid|Pid|Index|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 <key> <val> Sets the specified forever config <key>
clear <key> Clears the specified forever config <key>
logs Lists log files for all forever processes
logs <script|index> Tails the logs for <script|index>
columns add <col> Adds the specified column to the output in `forever list`
columns rm <col> Removed the specified column from the output in `forever list`
columns set <cols> Set all columns for the output in `forever list`
cleanlogs [CAREFUL] Deletes all historical forever log files options:
-m MAX Only run the specified script MAX times
-l LOGFILE Logs the forever output to LOGFILE
-o OUTFILE Logs stdout from child script to OUTFILE
-e ERRFILE Logs stderr from child script to ERRFILE
-p PATH Base path for all forever related files (pid files, etc.)
-c COMMAND COMMAND to execute (defaults to node)
-a, --append Append logs
-f, --fifo Stream logs to stdout
-n, --number Number of log lines to print
--pidFile The pid file
--uid Process uid, useful as a namespace for processes (must wrap in a string)
e.g. forever start --uid "production" app.js
forever stop production
--sourceDir The source directory for which SCRIPT is relative to
--workingDir The working directory in which SCRIPT will execute
--minUptime Minimum uptime (millis) for a script to not be considered "spinning"
--spinSleepTime Time to wait (millis) between launches of a spinning script.
--colors --no-colors will disable output coloring
--plain Disable command line colors
-d, --debug Forces forever to log debug output
-v, --verbose Turns on the verbose messages from Forever
-s, --silent Run the child script silencing stdout and stderr
-w, --watch Watch for file changes
--watchDirectory Top-level directory to watch from
--watchIgnore To ignore pattern when watch is enabled (multiple option is allowed)
-t, --killTree Kills the entire child process tree on `stop`
--killSignal Support exit signal customization (default is SIGKILL),
used for restarting script gracefully e.g. --killSignal=SIGTERM
-h, --help You're staring at it [Long Running Process]
The forever process will continue to run outputting log messages to the console.
ex. forever -o out.log -e err.log my-script.js [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
forever stop my-daemon.js

命令语法及使用 https://github.com/nodejitsu/forever

由于express4.x后,目录结构变化,运行方式改变,在此备注。

Express4 启航指南 http://www.cnblogs.com/Darren_code/p/express4.html

最新文章

  1. linux ISO/IMG make
  2. HDU5807分段dp
  3. php资料站
  4. j2ee的十三个规范
  5. Cobar分布式数据库的应用与实践
  6. 5.android系统裁剪
  7. ubuntu设置系统时间与网络时间同步
  8. Java中普通代码块,构造代码块,静态代码块的代码演示样例及区分
  9. spring的长处 ioc aop
  10. print打印网页相关
  11. Flink JobManager HA模式部署(基于Standalone)
  12. Linux下的Shell编程(1)最简单的例子
  13. MySQL &#183; 引擎特性 &#183; InnoDB 同步机制
  14. 前端技术之_CSS详解第一天
  15. Mybatis的缓存
  16. 剑指offer:反转链表
  17. SSH防暴力破解脚本
  18. 《剑指offer》 包含min函数的栈
  19. 解决maven编译Java中的使用了未经检查或不安全的操作
  20. sql,取得当前系统时间,算时间区间

热门文章

  1. 小白日记50:kali渗透测试之Web渗透-CSRF
  2. SQL Server 表和索引存储结构
  3. java邮件发送 qq与163邮箱互发和qq和163邮箱发送其他邮箱实例
  4. PN-Traniger
  5. iOS - UI - UISwitch
  6. cent os 6 安装 nginx
  7. Linux下cut命令使用
  8. React Native视频播放(iOS)
  9. [转]15 个顶级 HTML5 游戏引擎
  10. poj 1821 动态规划