在linux服务器中为meteor创建启动脚本 [英] Create a startup script for meteor in linux server
问题描述
我也遵循了一些帖子和教程来创建一个脚本来在服务器重启时启动流星项目.我遵循了中提到的答案:如何在启动时运行meteorUbuntu服务器
I have followed some posts and tutorials as well to create a script to start meteor project when server restart. i have followed answer mentioned in : How to run meteor on startup on Ubuntu server
然后我使用chmod +x metre-server.sh
"授予脚本可执行权限.
Then I gave executable permission to script with "chmod +x meteor-server.sh
".
我曾尝试将此脚本放在 /etc/init.d
和 /etc/init
文件夹中,但meteor 项目不会在重启时启动.我正在使用 ubuntu 16.04.
I have tried to put this script in /etc/init.d
and /etc/init
folders but meteor project does not start at the reboot. I'm using ubuntu 16.04.
如果您能告诉我我所做的错误,我将不胜感激.以下代码是我的meteor.server.sh
"脚本文件.
I would be grateful if you can show me the fault that i have done. Following code is my "meteor.server.sh
" script file.
# meteorjs - meteorjs job file
description "MeteorJS"
author "Jc"
# 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 /home/me/projects/cricket
echo ""
end script
# Start the process
exec meteor run -p 4000 --help -- production
推荐答案
首先,已经有一个非常好的工具 mupx 允许你将meteor 项目部署到你自己的架构中,所以真的没有必要自己动手,除非你有一个很好的.
First of all, there's already a very good tool mupx that allows you to deploy meteor projects to your own architecture, so there's really no need to do it by yourself unless you have a very good.
如果您确实需要手动部署,这将需要几个步骤.我不打算涵盖所有细节,因为您是专门询问启动脚本的,其余说明应该可以在 Internet 上轻松访问.
If you really need to deploy manually, this will take several steps. I am not going to cover all the details because you're specifically asking about the startup script and the remaining instruction should be easily accessible in the Internet.
- 除非您打算使用远程数据库,否则请安装 MongoDB.
- 安装 NodeJS.
- 安装反向代理服务器,例如Nginx 或 haproxy.
- 安装 Meteor,我们将仅将其用作构建工具.
我在这里假设您已经将应用的源代码放在您计划部署到的服务器上.转到您的项目根目录并运行以下命令:
I am assuming here that you already have the source code of your app put on the server to which you're planning to deploy. Go to your project root and run the following command:
meteor build /path/to/your/build --directory
请注意,如果 /path/to/your/build
存在,它将首先递归删除,所以要小心.
Please note that if /path/to/your/build
exists it will be recursively deleted first, so be careful with that.
转到 /path/to/your/build/bundle/programs/server
并运行:
npm install
4.准备一个 run.sh
脚本
文件可以是以下形式:
4. Prepare a run.sh
script
The file can be of the following form:
export MONGO_URL="mongodb://127.0.0.1:27017/appName"
export ROOT_URL="http://myapp.example.com"
export PORT=3000
export METEOR_SETTINGS="{}"
/usr/bin/env node /path/to/your/build/bundle/main.js
我假设你把它放在 /path/to/your/run.sh
中.这里有几个注意事项:
I will assume you put it in /path/to/your/run.sh
. A couple of notes here:
- 这种形式的
MONGO_URL
假设您在本地安装了 MongoDB. - 您需要指示您的反向代理服务器将您的应用流量指向端口
3000
. METEOR_SETTINGS
应该是您可能拥有的任何settings
对象的JSON.stringify(settings)
的输出.
- This form of
MONGO_URL
assumes you have MongoDB installed locally. - You will need to instruct your reverse proxy server to point your app trafic to port
3000
. METEOR_SETTINGS
should be the output ofJSON.stringify(settings)
of whateversettings
object you may have.
通过我们到目前为止所做的所有准备工作,脚本可以像
With all the preparations we've made so far, the script can be as simple as
description "node.js server"
start on (net-device-up and local-filesystems and runlevel [2345])
stop on runlevel [016]
respawn
script
exec /path/to/your/run.sh
end script
这个文件应该去/etc/init/appName.conf
.
这篇关于在linux服务器中为meteor创建启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!