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 --helpusage: forever [action] [options] SCRIPT [script-options]Monitors the script specified in the current process or as a daemonactions:start               Start SCRIPT as a daemonstop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Scriptstopall             Stop all running forever scriptsrestart             Restart the daemon SCRIPTrestartall          Restart all running forever scriptslist                List all running forever scriptsconfig              Lists all forever user configurationset <key> <val>     Sets the specified forever config <key>clear <key>         Clears the specified forever config <key>logs                Lists log files for all forever processeslogs <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 filesoptions:-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.jsforever 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 startin the background. This is extremely useful for remote starting simple node.js scriptswithout 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.jsforever stop my-daemon.js

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

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

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

转载于:https://www.cnblogs.com/cssfirefly/p/4895271.html

linux中nodejs后台运行工具forever相关推荐

  1. Linux中vue后台运行

    Linux中vue后台运行 只会简单的尝试 新的改变 功能快捷键 合理的创建标题,有助于目录的生成 如何改变文本的样式 插入链接与图片 如何插入一段漂亮的代码片 生成一个适合你的列表 创建一个表格 设 ...

  2. linux java后台运行_Java程序在Linux中实现后台运行

    1.运行脚本 脚本如下,这个脚本存在一点问题,Log4j稍微有点问题,但是对运行及日志记录没有影响,日志是通过将所有控制台数据全部写入文件的形式记录的. #!/bin/sh #author:wangc ...

  3. 【genius_platform软件平台开发】第七十九讲:Linux系统中可执行程序后台运行的几种方式

    [genius_platform软件平台开发]第七十九讲:Linux系统中可执行程序后台运行的几种方式 1. 问题描述 2. & 符号 3. nohup指令 4. ctrl + z.jobs. ...

  4. Linux nohup实现后台运行程序及查看(nohup与)

    Linux nohup实现后台运行程序及查看(nohup与&) 更新时间:2019年09月11日 09:28:40 作者:猿的生活 这篇文章主要介绍了Linux nohup实现后台运行程序及查 ...

  5. 如何查看 Linux 中所有正在运行的服务

    有许多方法和工具可以查看 Linux 中所有正在运行的服务.大多数管理员会在 System V(SysV)初始化系统中使用 service service-name status 或 /etc/ini ...

  6. linux oracle查看服务,技术|如何查看 Linux 中所有正在运行的服务

    有许多方法和工具可以查看 Linux 中所有正在运行的服务.大多数管理员会在 System V(SysV)初始化系统中使用 service service-name status 或 /etc/ini ...

  7. Linux 中的 netcat 网络工具简介

    Linux 中的 netcat 网络工具简介 Apr 3, 2020 |  Linux |  linux netcat netcat 是 Linux 系统中的网络工具,其通过 TCP 和 UDP 协议 ...

  8. 在Linux 中编写并运行C语言

    在Linux 中编写并运行C语言 流程 后续 流程 首先我们创建一个C语言文件 vim 1.c 我们进行相关程序的编写(我们以简单的输入输出为例) #include <stdio.h> i ...

  9. linux shell 在后台运行命令

    linux shell 在后台运行命令: http://blog.csdn.net/CAIYUNFREEDOM/article/details/6339390 http://blog.sina.com ...

最新文章

  1. C++_STL——map、multimap、set、multiset
  2. 导航,头部,CSS基础
  3. 万字长文:近年来学界、业界视角下的“事理图谱”发展总结与思考
  4. leetcode 53 python 动态规划
  5. ai智能和大数据测试_测试版可帮助您根据自己的条件创建数据和AI平台
  6. Apache commons-text和Configuration 命令执行CVE-2022-42889/CVE-2022-33980分析
  7. 按键精灵打怪学习-窗口绑定技能
  8. java do while 循环语句_Java do while循环语句用法
  9. 在Linux下使用“360随身WiFi 2” ubuntu14.04 64位系统适用
  10. 一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
  11. 手游传奇刷元宝_战神传奇手游刷元宝方法技巧大全
  12. 中间件小师妹 de 年度工作总结
  13. Quora如何在快速开发中保持高品质代码
  14. linux vi 看下一页,linux中的vi命令(2)
  15. zk4元年拆解_科比zk4复刻拆解测评 zk4复刻配置和元年区别是什么
  16. 中英数据库专家谈:数据库的过去、未来和现在
  17. ubuntu1804系统设置在哪里_ubuntu1804修改IP地址方式及脚本
  18. 奥赛金牌计算机博士中学老师,12岁获奥赛金牌,17岁读博的数学天才,全人教育下现状令人想不到...
  19. 时间序列预测,非季节性ARIMA及季节性SARIMA
  20. 影响全马破三的因素分析

热门文章

  1. Linux启动SAP服务,sap启动相关
  2. 获取不到html页面上的元素,Vue v-for渲染页面,获取不到DOM元素解析
  3. dbscan java_DBSCAN算法的Java,C++,Python实现
  4. linux 修改Db2主机名,对DB2服务器主机名的修改的正确操作流程
  5. php超大树形分页,PHP+MySql千万级数据limit分页优化方案
  6. informix和mysql的区别_DB2与Informix区别比较
  7. python矩阵运算dot_numpy中的dot矩阵乘法
  8. Java字符串性能优化
  9. MySQL 内连接查询
  10. 计算机系统性错误,《深入理解计算机系统-异常》