服务器重启时自动启动Node.js应用程序(Ghost博客)

时间:2014-10-01 16:41:48

标签: node.js ubuntu digital-ocean ghost-blog

在我准备和安装Ghost之后,我一直坚持设置我的DO Ubuntu在服务器重启时自动启动。我被建议永远使用,我确实使用它,但据我所知,它的概念;永远只是让它在启动后保持运行,并且每次重启都会消失(需要手动启动)。

我正在寻找一个可靠的解决方案,即使服务器重新启动或完全崩溃,也能使多个nodejs应用程序保持活动状态。

3 个答案:

答案 0 :(得分:2)

DigitalOcean的一键式Ghost应用程序使用Upstart脚本让Ghost启动时启动。它看起来像:

description "Ghost: Just a blogging platform"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectedly trigger a respawn
respawn

setuid ghost
setgid ghost
env NODE_ENV=production
chdir /var/www/ghost

exec /usr/local/bin/npm start --production

pre-stop exec /usr/local/bin/npm stop --production

并将其安装到/etc/init/ghost.conf这样做的另一个好处是允许您像使用sudo service ghost restart

之类的命令一样管理服务器上的任何其他服务

答案 1 :(得分:2)

对于howtoinstallghost.com,allghostthemes.com,ghostforbeginners.com,我们使用pm2来保持Ghost运行。我们在这里写了关于如何设置pm2的文章:

http://www.allaboutghost.com/keep-ghost-running-with-pm2/

答案 2 :(得分:0)

您希望将其设置为init.d脚本,以便您可以启动它或将其作为服务停止(并使用chkconfig将其设置为自动启动)。

详细信息如下:https://help.ubuntu.com/community/UbuntuBootupHowto

请注意,除了使用诸如Forever和Monit之类的东西在服务崩溃时重新启动等等。