【发布时间】:2011-09-25 02:11:22
【问题描述】:
我正在尝试为我的 ubuntu 机器编写一个新贵脚本,它是 8.04 版“Hardy”。我已按照此站点上的说明进行操作:upstart for node.js 但似乎这些说明适用于当前版本的 ubuntu。
我注意到我的机器上不存在 /etc/init 目录,首先我尝试将脚本放在 /etc/init.d 目录中,然后我创建了 /etc/init 目录并将其放置在那里。
我将在下面发布我的 upstart 脚本(这与上面的网站基本相同,但有一些路径更改),但是当我运行 start jobname 时,我只收到一个错误“start: Unknown job: jobname”。因此,我将脚本更改为精简版,发布在下面,但我仍然得到相同的结果。
目前,我正在使用“nohup”命令来运行我的节点服务器,但我想要一个更持久的解决方案。
请帮忙?
脚本 1:
description "node.js chat server"
author "iandev ith3"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
respawn limit 99 5
script
# Not sure why $HOME is needed, but we found that it is:
export HOME="/root"
exec /root/local/node/bin/node /home/ian/chat.js >> /var/log/node.log 2>&1
end script
post-start script
# optionally put a script here that will notifiy you node has (re)started
# /root/bin/hoptoad.sh "node.js has started!"
end script
脚本 2:
description "node.js chat server"
author "iandev ith3"
script
exec /root/local/node/bin/node /home/ian/chat.js >> /var/log/node.log 2>&1
end script
【问题讨论】:
-
我最终只使用了 cron @reboot 来确保我的脚本在启动时运行,因为我永远无法启动或永远在服务器上工作。它解决了我的总体目标,但没有回答问题,所以我将其作为评论留下。 (以防人们有类似的问题但不知道 cron @reboot)
标签: javascript ubuntu node.js upstart