问题描述
我在启动 Upstart 脚本时遇到问题.
I'm having trouble starting an Upstart script.
这是脚本(/etc/init/中的app.conf)
Here's the script (app.conf in /etc/init/)
description "node.js server"
author "kvz"
start on startup
stop on shutdown
script
# We found $HOME is needed. Without it, we ran into problems
export HOME="/root"
exec sudo -u /usr/local/bin/node \
/var/www/vhosts/travelseguro.com/node/app.js \
2>&1 >> /var/log/node.log
end script
当我运行 sudo start app
时,我得到:
When I run sudo start app
, I get:
开始:未知作业:应用
我怎样才能做到这一点?
How can I make this work?
推荐答案
我在基于 Redhat 的最新 Amazon (AWS) linux 上运行时遇到了同样的问题.
I was having the same problem running on the latest Amazon (AWS) linux which is Redhat based.
我在 /etc/init
中有我的 upstart 文件,名为 node.conf
并且当我运行 sudo start node
时,我会收到与您类似的错误 start: Unknown job: node
.
I have my upstart file in /etc/init
called node.conf
and when I ran sudo start node
I would get a similar error to you start: Unknown job: node
.
事实证明,如果您的 .conf
文件中存在错误,则作业不会启动.所以我首先注释掉所有的行,然后慢慢建立以找出错误.错误信息不是很清楚,看起来像 upstart 找不到你的 conf 文件.
It turns out that the job won't start if there's an error in your .conf
file. So I started out by commenting out all the lines and slowly building up to find the error. The error message isn't very clear and makes it look like upstart can't find your conf file.
尾随你的'/var/log/messages'将帮助你调试Upstart日志到那里(它可能在Ubuntu上的某个地方不同.我说init:/etc/init/node-upstart.conf:8: Unknown stanza
帮助我找到了它的底部.在我的特殊情况下,我错误地声明了变量.
Tailing your '/var/log/messages' will help you debug as Upstart logs to there (It may be somewhere different on Ubuntu. Mine said init: /etc/init/node-upstart.conf:8: Unknown stanza
which helped me get to the bottom of it. In my particular case I was declaring variables incorrectly.
请参阅 AskUbuntu 上的类似主题.
See on AskUbuntu for a similar thread.
这是我的编辑工作脚本:
<!-- language: lang-sh -->
#!upstart
# using upstart http://upstart.ubuntu.com/getting-started.html and node forever https://github.com/nodejitsu/forever/
# to run server
# redhat has additional sudo restrictions, you must comment out 'Default requiretty' from /etc/sudoers
#startup monitoring script derived from http://stackoverflow.com/questions/11084279/node-js-setup-for-easy-deployment-and-updating
description "node.js server"
author "jujhar"
env PROGRAM_NAME="node"
env FULL_PATH="/home/httpd/buto-middleman/public"
env FILE_NAME="forever.js"
env NODE_PATH="/usr/local/bin/node"
env USERNAME="springloops"
start on startup
stop on shutdown
script
export HOME="/root"
export NODE_ENV=staging #development/staging/production
echo $$ > /var/run/$PROGRAM_NAME.pid
cd $FULL_PATH
#exec sudo -u $USERNAME $NODE_PATH $FULL_PATH/$FILE_NAME >> /var/log/$PROGRAM_NAME.sys.log 2>&1
exec $NODE_PATH $FULL_PATH/$FILE_NAME >> /var/log/$PROGRAM_NAME.sys.log 2>&1
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/$PROGRAM_NAME.sys.log
end script
pre-stop script
rm /var/run/$PROGRAM_NAME.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/$PROGRAM_NAME.sys.log
end script
-- 编辑 2013-06-01 --
如果您像我一样使用 Centos 或 Amazon Linux,请查看这个 init.d 脚本.
If you're on Centos or Amazon Linux like me, take a look at this init.d script.
-- 编辑 2013-10-14 --
这是我实际使用的 init.d 脚本的链接到要点在 Amazon Linux(基于 Redhat)上生产.我只是将它保存在我的项目中的 init.d
文件夹下,然后在 /etc/init.d
文件夹中符号链接到它,现在它是一个守护进程/服务!
Here's a link to a gist of an init.d script that I actually use in production on Amazon Linux(Redhat Based). I simply keep it in my project under an init.d
folder and then symlink to it in the /etc/init.d
folder and now it's a daemon/service!
-- 编辑 2014-06-05 --
看看这个很棒的博客文章 作者 Jeff Dickey 在 Node.js 上使用 systemd 这比我们在这里做的所有事情都更干净、更容易(恕我直言).他还使用 Ansible 来控制他的集群(我很喜欢),但如果你还没有准备好,你不必走那么远.
Check out this awesome blog artcile by Jeff Dickey on Node.js in production using systemd which is much cleaner and easier than all the stuff we've been doing here (IMHO). He also uses Ansible to control his cluster (which I love) but you don't have to go that far if you're not ready.
这篇关于node.js 应用程序的新贵脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!