How do I leave Node.js server on EC2 running forever?

前端 未结 5 874
逝去的感伤
逝去的感伤 2020-12-22 16:11

As you can tell by my question, I\'m new to this...

I built my first website, I set up my first Node.js server to serve it and then pushed everything live on EC2.

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 16:57

    Before you invoke Node.js, run the command:

    screen

    This will create a persistent environment which will allow your process to keep running after you disconnect.

    When you reconnect, you can use this command to reconnect to that environment:

    screen -r

    Here's a random link to learn more about screen:

    http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

    However, this won't help you if your EC2 instance restarts. There are many different ways to do that. Adding your startup command to /etc/rc.local is one way. Here's a link to an Amazon guide which includes adding something to /etc/rc.local.

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/building-shared-amis.html

    Hope this helps,

    James

提交回复
热议问题