Keep meteor running on amazon EC2

前端 未结 3 1715
野趣味
野趣味 2020-12-06 14:55

I have a simple meteor app that I\'m running on an Amazon EC2 server. Everything is working great. I start it manually with my user via meteor in the project

相关标签:
3条回答
  • 2020-12-06 15:25

    I am using upstart on Ubuntu server which you should be able to easily install on Amazon linux.

    This is roughly my /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:

    sudo start myapp
    sudo stop myapp
    
    0 讨论(0)
  • 2020-12-06 15:32

    I believe this package solves your problem: https://github.com/arunoda/meteor-up

    which seems to use forever: https://github.com/nodejitsu/forever

    0 讨论(0)
  • 2020-12-06 15:33

    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. 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. You can maybe just put the start script in /etc/rc.local. For ubuntu see this question.

    Also note you really should be bundling your app if using it in production. See this comparison for more details on the differences.

    0 讨论(0)
提交回复
热议问题