我已经关注了一些帖子和教程,以便在服务器重启时创建一个启动meteor项目的脚本。我遵循了How to run meteor on startup on Ubuntu server
中提到的答案然后我给了" chmod +x meteor-server.sh
"脚本的可执行权限。
我尝试将此脚本放在/etc/init.d
和/etc/init
个文件夹中,但meteor项目不会在重启时启动。我使用 ubuntu 16.04 。
如果你能告诉我我所做的错,我将不胜感激。以下代码是我的" meteor.server.sh
"脚本文件。
# 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
答案 0 :(得分:2)
首先,已经有一个非常好的工具mupx允许您将流星项目部署到您自己的架构中,所以除非您有一个非常好的,否则没有必要自己做。
如果您确实需要手动部署,则需要执行几个步骤。我不打算介绍所有细节,因为您专门询问启动脚本,其余指令应该可以在Internet上轻松访问。
我在这里假设您已将应用程序的源代码放在您计划部署的服务器上。转到项目根目录并运行以下命令:
meteor build /path/to/your/build --directory
请注意,如果/path/to/your/build
存在,则会先递归删除,所以请小心。
转到/path/to/your/build/bundle/programs/server
并运行:
npm install
run.sh
脚本该文件可以是以下形式:
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
中。这里有几点说明:
MONGO_URL
形式假设您已在本地安装MongoDB。3000
。METEOR_SETTINGS
应该是您可能拥有的任何JSON.stringify(settings)
对象的settings
的输出。upstart
脚本通过我们迄今为止所做的所有准备工作,脚本可以像
一样简单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
。
答案 1 :(得分:1)
最后我开始工作了。我已经使用以下2个脚本在启动时运行meteor。 首先,我将此服务文件(meteor.service)放在/ etc / systemd / system
中 [Unit]
Description = My Meteor Application
[Service]
ExecStart=/etc/init.d/meteor.sh
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=meteor
[Install]
WantedBy=multi-user.target
我使用此服务调用了一个scipt。我把以下脚本(meteor.sh)放在/etc/init.d
中 #!/bin/sh -
description "Meteor Projects"
author "Janitha"
#start service on following run levels
start on runlevel [2345]
#stop service on following run levels
stop on runlevel [016]
#restart service if crashed
respawn
#set user/group to run as
setuid janitha
setgid janitha
chdir /home/janitha/projects/cricket_app
#export HOME (for meteor), change dir to plex requests dir, and run meteor
script
export HOME=/home/janitha
exec meteor
end script
我使用
使这两个文件都可执行 chmod +x meteor.service
chmod +x meteor.sh
我使用了以下两个命令来启用服务
systemctl daemon-reload
systemctl enable meteor.service
答案 2 :(得分:1)
我成功使用了这个配置
在/etc/init.d中添加一个名为meteor.sh的文件
#!/bin/sh
export HOME="/home/user"
cd /home/user/meteor/sparql-fedquest
meteor --allow-superuser
您必须向meteor.sh
授予执行权限sudo chmod 644 meteor.sh
此外,您必须在/ etc / systemd / system
中创建meteor.service[Unit]
Description =Portal of bibliographic resources of University of Cuenca
Author = Freddy Sumba
[Service]
ExecStart=/etc/init.d/meteor.sh
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=meteor
[Install]
WantedBy=multi-user.target
此外,您必须授予meteor.service
的权限$ sudo chmod 644 meteor.service
然后,我们需要在每次服务器重新启动时将服务添加到此启动
$ systemctl enable meteor.service
最后启动服务
$ service meteor start