在系统重新启动时自动启动(节点) [英] Automatically start forever (node) on system restart

查看:176
本文介绍了在系统重新启动时自动启动(节点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用节点的永远模块来保持我的节点服务器运行。然而,当系统重新启动时,永久终止。有什么方法,我可以自动启动节点服务器(永远)当系统重新启动?

解决方案

我建议使用crontab 。



如何




  1. 开始编辑请运行以下命令,将testuser替换为所需的运行时用户以进行节点进程。如果您选择不同于自己的用户,则必须使用sudo运行此用户。

      $ crontab -u testuser -e 


  2. 如果以前从来没有这样做,它会询问您要编辑哪个编辑器与。


  3. 在编辑器中添加以下行:

      @reboot / usr / local / bin / forever start /your/path/to/your/app.js 
    pre>

  4. 保存文件。


  5. 要进一步确认cron的安装,请执行以下操作(再次将testuser替换为您的目标用户名)列出当前安装的cron:

      $ crontab -u testuser -l 


注意,在我看来,在cron中执行二进制文件时, 。
此外,如果你的永久脚本的路径不正确,请运行,它永远获得完整路径。



由于永远调用节点,您可能还需要提供 node

  @reboot / usr / local / bin / forever start -c / usr / local / bin / node /your/path/to/your/app.js 



/ h2>


I am using node's forever module to keep my node server running. Forever however terminates when there is a system restart. Is there any way I can automatically start the node server (with forever) when the system restarts?

解决方案

I would suggest using crontab. It's easy to use.

How to

  1. To start editing run the following replacing the "testuser" with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.

    $ crontab -u testuser -e
    

  2. If you have never done this before, it will ask you which editor you wish to edit with. I like vim, but will recommend nano for ease of use.

  3. Once in the editor add the following line:

    @reboot /usr/local/bin/forever start /your/path/to/your/app.js
    

  4. Save the file. You should get some feedback that the cron has been installed.

  5. For further confirmation of the installation of the cron, execute the following (again replacing "testuser" with your target username) to list the currently installed crons:

    $ crontab -u testuser -l 
    

Note that in my opinion, you should always use full paths when executing binaries in cron. Also, if the path to your forever script is not correct, run which forever to get the full path.

Given that forever calls node, you may also want to provide the full path to node:

@reboot /usr/local/bin/forever start -c /usr/local/bin/node /your/path/to/your/app.js

Further Reading

这篇关于在系统重新启动时自动启动(节点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆