linux中nodejs后台运行工具forever
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
linux中nodejs后台运行工具forever的更多相关文章
- 如何在Linux中使用Firejail运行应用程序
有时您可能希望使用在不同环境中未经过良好测试的应用程序,但您必须使用它们.在这种情况下,关注系统的安全性是正常的.在Linux中可以做的一件事是在沙箱中使用应用程序. “沙盒”是在有限环境中运行应用程 ...
- 如何查看 Linux 中所有正在运行的服务
有许多方法和工具可以查看 Linux 中所有正在运行的服务.大多数管理员会在 System V(SysV)初始化系统中使用 service service-name status 或 /etc/ini ...
- 在Linux中通过Top运行进程查找最高内存和CPU使用率
按内存使用情况查找前15个进程,在批处理模式下为"top" 使用top命令查看有关当前状态,系统使用情况的更详细信息:正常运行时间,负载平均值和进程总数. 分类:Linux命令操作 ...
- Linux中常用压缩打包工具
Linux中常用压缩打包工具 压缩打包是常用的功能,在linux中目前常用的压缩工具有gzip,bzip2以及后起之秀xz.本文将介绍如下的工具常见压缩.解压缩工具以及打包工具tar. gzip2 直 ...
- 如何在Linux中tomcat下运行一个web项目
如何在Linux中tomcat下运行一个web项目 然后启动Tomcat项目.运行的运行后会自动将war包解压. 如果页面报404,那么请查看tomcat日志文件,它一定是报错了....
- Linux 下在后台运行进程:nohup,setsid,& 以及 tmux
参考: Linux 技巧:让进程在后台可靠运行的几种方法 ssh 登录了远程服务器时,如果在前台运行耗时较长的任务, 当 ssh 掉线或关闭窗口时会导致命令停止运行. hup 与 nohup 当用户注 ...
- Linux nohup 程序后台运行
&方式: Unix/Linux下一般想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/my ...
- 如何在Linux中使用rz/sz工具进行文件传输
在Linux中,使用rz/sz工具能够进行Linux和windows之间的文件传输,那么要如何使用rz/sz工具工具呢?下面小编就给大家介绍下Linux下如何使用rz/sz工具进行文件传输,一起来学习 ...
- Linux jar包 后台运行
Linux 运行jar包命令如下: 方式一: java -jar shareniu.jar 特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 那如何让窗口不锁定? ...
随机推荐
- SQL操作XML
前面一段时间为了赶项目的进度,一直在加班,现在空闲了下来将前面碰到的问题整理了一下,发现了一些十分有用的,在此记录下来,看能不能帮助到遇到同样问题的朋友,此文仅是自己个人的意见,若存在问题,还望不宁赐 ...
- [JavaEE] 深入理解Struts2的ognl标签
OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调用对象的方法,能够 ...
- [Java] HashMap详解
转自:http://alex09.iteye.com/blog/539545 HashMap 和 HashSet 是 Java Collection Framework 的两个重要成员,其中 Hash ...
- CSDN中根据文章自动生成文章目录
概述 CSDN中有根据文件内容中H标签在文章中自动生成文章目录,看起来比较专业,就想把它搬到自己的博客园中.类似下图 提取JS脚本 通过浏览器开发者工具(IE/Chrome)找到产生文章目录javas ...
- 【Shell脚本学习13】Shell数组:shell数组的定义、数组长度
Shell在编程方面比Windows批处理强大很多,无论是在循环.运算. bash支持一维数组(不支持多维数组),并且没有限定数组的大小.类似与C语言,数组元素的下标由0开始编号.获取数组中的元素要利 ...
- 强大的JQuery(二)--动画效果
上篇博客我们讲过了jquery的基础知识--强大的JQuery(一)--基础篇,作为web开发人员,网页的动画效果是不可缺少的,本篇博客重点来说说jquery的动画效果的实现. 因为动画的效果不能截图 ...
- X86汇编语言中的registers相关
0.写在前面 本文中总结于王爽老师的汇编语言,建议有兴趣的都买一本,以支持王爽老师的辛勤付出.再者,这本书写的确实很nice. 8086CPU共有14个registers:AX, BX, CX, DX ...
- hdu 4412 利用单调性的动态规划
思路: 这题和1227的求法一样,只不过1227是小数据,暴力下,就能进行预处理. 这题的预处理区间期望cost[i][j]需要利用单调性. 即假使以pos位置为安排的点,那么这个区间在其左边的概率为 ...
- JavaWeb 学习的第一阶段总结
本人从事Asp.net开发三年,结合市场情况,综合考虑后决心转向JavaWeb方向.于是开始了自学Java的历程. 首先,我用马士兵的Java基础教学视频,快速地学习了一遍Java基础.因为有C#基础 ...
- SQL数据库开发知识总结:基础篇
1数据库概述 (1) 用自定义文件格式保存数据的劣势. (2) DBMS(DataBase Management System,数据库管理系统)和数据库,平时谈到”数据库”可能有两种含义:MSSQL ...