Ubuntu服务器运行js,让js一直运行下去
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu服务器运行js,让js一直运行下去
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ssh連接Ubuntu,node xxx.js運行js,一關閉ssh連接,js服務就關閉了。百度了一下發現了一個大神的回答這里copy了一個大神的回答,來記錄一下
?
讓 Ghost 一直運行前面提到的啟動 Ghost 使用 npm start 命令。這是一個在開發模式下啟動和測試的不錯的選擇,但是通過這種命令行啟動的方式有個缺點,即當你關閉終端窗口或者從 SSH 斷開連接時,Ghost 就停止了。為了防止 Ghost 停止工作,有兩種方式解決這個問題。Forever (https://npmjs.org/package/forever) 你可以使用 forever 以后臺任務運行 Ghost 。forever 將會按照 Ghost 的配置,當進程 crash 后重啟 Ghost。通過 npm install forever -g 安裝 forever 為了讓 forever 從 Ghost 安裝目錄運行,輸入 NODE_ENV=production forever start index.js 通過 forever stop index.js 停止 Ghost 通過 forever list 檢查 Ghost 當前是否正在運行 Supervisor (http://supervisord.org/) 流行的 Linux 發行版——例如 Fedora, Debian 和 Ubuntu,都包含一個 Supervisor 包:一個進程控制系統,允許在啟動的時候無需初始化腳本就能運行 Ghost。不像初始化腳本一樣,Supervisor 可以移植到不同的發行版和版本。根據不同的 Linux 發行版 安裝 Supervisor 。如下所示: Debian/Ubuntu: apt-get install supervisor Fedora: yum install supervisor 其他大多數發行版: easy_install supervisor 通過 service supervisor start 確保 Supervisor 運行 為 Ghost 創建一個啟動腳本。通常為 /etc/supervisor/conf.d/ghost.conf ,例如:[program:ghost] command = node /path/to/ghost/index.js directory = /path/to/ghost user = ghost autostart = true autorestart = true stdout_logfile = /var/log/supervisor/ghost.log stderr_logfile = /var/log/supervisor/ghost_err.log environment = NODE_ENV="production" 使用 Supervisor 啟動 Ghost:supervisorctl start ghost停止 Ghost: supervisorctl stop ghost詳細內容請參閱 Supervisor 文檔。摘抄自
http://docs.ghostchina.com/zh/installation/deploy/
?
轉載于:https://www.cnblogs.com/dayu007/p/8376066.html
總結
以上是生活随笔為你收集整理的Ubuntu服务器运行js,让js一直运行下去的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 今天升级win10.vs调试程序各种崩溃
- 下一篇: cocos2dx 3.x Value、V