【问题标题】:How to run meteor on startup on Ubuntu server如何在 Ubuntu 服务器上启动时运行流星
【发布时间】:2015-08-24 16:50:23
【问题描述】:

我学习meteorjs,我有一个小型远程VPS。

我想要:

  1. 设置从我的流星项目的 git 存储库自动拉取。
  2. 将脚本放入自动启动,将我的流星项目作为服务运行。

例如

meteor run -p 80 -- production

我的服务器是 Ubuntu 12.04

【问题讨论】:

    标签: git meteor ubuntu-12.04


    【解决方案1】:

    你应该使用Ubuntu的方式,也就是Upstart:

    http://upstart.ubuntu.com/ http://manpages.ubuntu.com/manpages/lucid/man5/init.5.html

    如何定义守护任务:

    http://newcome.wordpress.com/2012/02/26/running-programs-as-linux-daemons-using-upstart/

    希望对你有帮助:)

    你的新贵文件或多或少:

    # meteorjs - meteorjs job file
    
    description "MeteorJS"
    author "Igor S"
    
    # When to start the service
    start on runlevel [2345]
    
    # When to stop the service
    stop on runlevel [016]
    
    # Automatically restart process if crashed
    respawn
    
    # Essentially lets upstart know the process will detach itself to the background
    expect fork
    
    # Run before process
    pre-start script
            cd PATH_TO_METEOR_APP
            echo ""
    end script
    
    # Start the process
    exec meteor run -p 80 --help -- production
    

    【讨论】:

    • 如何使用 Mac OSX 在启动时运行陨石?
    • 当我运行时,我得到“'/vagrant/.meteor' 存在,但'/vagrant/.meteor/meteor' 不可执行。删除它并重试。”
    • @MikeGraf,甚至更好 - 我试图从这个例子中推导出一个 mrt 新贵,但似乎无法让它工作..你有没有机会分享一些技巧?这真的只是我无法弄清楚的exec 节..
    • 在执行meteor 之前我们必须先cwd(这样我们就在项目目录中),可能必须使用`mrt.
    • 确定要以root身份运行服务器吗?
    【解决方案2】:

    这是我的工作:

    description "meteor app server"
    start on runlevel [2345]
    stop on runlevel [06]
    respawn
    respawn limit 10 5
    pre-start script
       set -e
       rm -f /path/to/your/app/.meteor/local/db/mongod.lock
    end script
    exec /bin/su - ec2-user -c '/path/to/your/app/meteor_server.sh'
    post-stop script
        pkill -f meteor
    end script
    

    meteor_server.sh 脚本包含:

    cd /path/to/your/app/; meteor run -p 3000 --production
    

    确保 chmod +x meteor_server.sh 脚本并在 3 个位置更改应用程序的路径。该脚本在停止时还会终止所有流星任务,因此它仅适用于在您的服务器上运行单个流星应用程序。我使用 nginx 以这种方式快速运行了一个流星应用程序,但节点似乎消耗了大量内存。

    【讨论】:

      【解决方案3】:

      这是我的 meteorjs.conf 文件 - 工作正常。 我之前已经描述过所有问题,但是这个变体修复了它们。 希望它可以帮助某人:)

      我通过printenv得到的所有EXPORT变量

      # meteorjs - meteorjs job file
      
      description "MeteorJS"
      author "Alex Babichev"
      
      # When to start the service
      start on runlevel [2345]
      
      # When to stop the service
      stop on runlevel [016]
      
      # Automatically restart process if crashed
      respawn
      
      # Essentially lets upstart know the process will detach itself to the background
      expect fork
      
      chdir /home/dev/www/test
      
      script
      
      export MONGO_URL=mongodb://localhost:27017/meteor
      export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      export PWD=/home/sputnik
      export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
      export HOME=/home/sputnik
      
      echo "---- start ----"
      cd /home/dev/www/test
      exec mrt
      
      end script
      

      【讨论】:

      • 没有通过 mongo url 并将最后一行更改为:exec meteor -p domain.com:8080 也必须更改为 chmod +x /etc/init/meteorjs.conf 并且效果很好:) Thx
      • env HOME=/home/sputnik 如果您不喜欢脚本中的脚本。
      猜你喜欢
      • 1970-01-01
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 2018-03-29
      • 2016-01-10
      • 1970-01-01
      • 2012-04-24
      相关资源
      最近更新 更多