【问题标题】:Autostart Node.js app (Ghost Blog) on server restart服务器重新启动时自动启动 Node.js 应用程序(Ghost 博客)
【发布时间】:2014-10-01 16:41:47
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我在 pm2 上苦苦挣扎,希望不大。甚至安装也有问题。此外,由于某种原因,它填满了我的液滴的 ram。
    • 最后,pm2 是我的解决方案。
    【解决方案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 之类的命令来管理它

    【讨论】:

    • 服务是否像“永远”一样运行——就重启而言
    • 是的,如果它意外停止,它将重新生成进程。
    【解决方案3】:

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

    详情在这里:https://help.ubuntu.com/community/UbuntuBootupHowto

    请注意,除了使用 Forever 和 Monit 之类的东西来在服务崩溃等情况下重新启动之外。

    【讨论】:

    • 你能给我一个永远工作的例子吗?
    • 我这里有一个使用 Forever 的例子:howtoinstallghost.com/how-to-start-ghost-with-forever
    • @howtoinstallghost 我看过那篇博文,谢谢分享。然而,据我所知,它并没有帮助或“重启”的情况,不是吗?
    • 这就是 Upstart 的目的,Zettam。
    猜你喜欢
    • 2013-12-12
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多