简体   繁体   English

让流星在亚马逊EC2上运行

[英]Keep meteor running on amazon EC2

I have a simple meteor app that I'm running on an Amazon EC2 server. 我有一个简单的流星应用程序,我在Amazon EC2服务器上运行。 Everything is working great. 一切都很好。 I start it manually with my user via meteor in the project directory. 我通过项目目录中的meteor手动启动我的用户。

However, what I would like is for this app to 但是,我想要的是这个应用程序

  1. Run on boot 在启动时运行
  2. Be immune to hangups 免受挂断

I try running it via nohup meteor & , but when I try to log out of the EC2 instance, I get the "You have running jobs" message. 我尝试通过nohup meteor &运行它,但是当我尝试注销EC2实例时,我收到“你有正在运行的工作”消息。 Continuing to log out stops the app. 继续注销会停止该应用。

How can I get the app to start on startup and stay up (unless it crashes for some reason)? 如何让应用程序在启动时启动并保持运行(除非由于某种原因崩溃)?

Install forever and use a start script. 永远安装并使用启动脚本。

$ npm install -g forever

I have several scripts for managing my production environment - the start script looks something like: 我有几个脚本来管理我的生产环境 - 启动脚本看起来像:

#!/bin/bash

forever stopall

export MAIL_URL=...
export MONGO_URL=...
export MONGO_OPLOG_URL=...
export PORT=3000
export ROOT_URL=...
forever start /home/ubuntu/apps/myapp/bundle/main.js

exit 0

Conveniently, it will also append to a log file in ~/.forever which will show any errors encountered while running your app. 方便的是,它还会附加到~/.forever的日志文件,该文件将显示运行应用程序时遇到的任何错误。 You can get the location of the log file and other stats about your app with: 您可以使用以下命令获取日志文件的位置以及有关您的应用的其他统计信息:

$ forever list

To get your app to start on startup, you'd need to do something appropriate for your flavor of linux. 要让你的应用程序在启动时启动,你需要做一些适合你的linux风格的东西。 You can maybe just put the start script in /etc/rc.local . 您可以将启动脚本放在/etc/rc.local For ubuntu see this question . 对于ubuntu,请看这个问题

Also note you really should be bundling your app if using it in production. 另请注意,如果在生产中使用它,您真的应该捆绑您的应用程序。 See this comparison for more details on the differences. 有关差异的更多详细信息,请参阅此比较

I am using upstart on Ubuntu server which you should be able to easily install on Amazon linux. 我在Ubuntu服务器上使用upstart ,你应该可以在Amazon linux上轻松安装。

This is roughly my /etc/init/myapp.conf : 这大致是我的/etc/init/myapp.conf

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

respawn
respawn limit 99 5

script
    export HOME="/home/deploy"
    export NODE_ENV="production"
    export MONGO_URL="mongodb://localhost:27017/myappdb"
    export ROOT_URL=http://localhost
    export MAIL_URL=smtp://localhost:25
    export METEOR_SETTINGS='{"somesetting":true}'

    cd /var/www/myapp/bundle/
    exec sudo -u deploy PORT=3000 /usr/bin/node main.js >> /var/log/node.log 2>&1
end script

I can then manually start and stop myapp like this: 然后我可以像这样手动启动和停止myapp

sudo start myapp
sudo stop myapp

I believe this package solves your problem: https://github.com/arunoda/meteor-up 我相信这个包解决了你的问题: https//github.com/arunoda/meteor-up

which seems to use forever : https://github.com/nodejitsu/forever 似乎forever使用: https//github.com/nodejitsu/forever

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM