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 supervisorFedora: 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.jsdirectory = /path/to/ghostuser = ghostautostart = trueautorestart = truestdout_logfile = /var/log/supervisor/ghost.logstderr_logfile = /var/log/supervisor/ghost_err.logenvironment = NODE_ENV="production"使用 Supervisor 启动 Ghost:supervisorctl start ghost停止 Ghost: supervisorctl stop ghost详细内容请参阅 Supervisor 文档。
摘抄自
http://docs.ghostchina.com/zh/installation/deploy/
Ubuntu服务器运行js,让js一直运行下去
原文地址:https://www.cnblogs.com/dayu007/p/8376066.html