linux中nodejs后台运行工具forever
生活随笔
收集整理的這篇文章主要介紹了
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 --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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 大流量网站访问
- 下一篇: linux用grep查找包含两个关键字的