Ubuntu 8.04 Hardy 和 node.js 新贵脚本
我正在尝试为我的 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
I am trying to write an upstart script for my ubuntu machine, which is version 8.04 "Hardy". I have followed the instructions on this site: upstart for node.js but it seems like these instructions are for a current version of ubuntu.
I noticed that the /etc/init directory does not exist on my machine, first I tried putting the script in the /etc/init.d directory and then I created the /etc/init dir and placed it there.
I will post my upstart script below (which is basically the same as from the website above with some path changes), but when I run start jobname, I just get an error "start: Unknown job: jobname". So then I changed the script around to a slimmed down version, posted below, and still I get the same result.
For now, I am using the 'nohup' command to run my node server but I would like a more permanent solution.
Please, any help?
SCRIPT 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只要使用永远。 https://github.com/indexzero/forever
Just use Forever. https://github.com/indexzero/forever
通过查看您提供的网站,我会说 /etc/init 只是一个拼写错误,它应该是 /etc/init.d/。您可能需要检查的一些内容:
脚本上的可执行标志。大多数版本的 Ubuntu 可执行文件在从命令行运行“ls”时显示为绿色。如果您想检查文件是否可执行,请从命令行运行“ls -l /etc/init.d/YOUR_SCRIPT”。你会看到这样的东西:
-rwxr-xr-x 1 根 根 1342 2010-09-16 10:13 YOUR_SCRIPT
x 表示它是可执行的。
要设置可执行标志(如果未设置),请
我很确定对于旧版本的 ubuntu,您需要在 /etc/rc.d/rc3.d 或 /etc 中包含脚本/rc3.d。 linux所做的就是从rc0.d到rc5.d运行并执行其中的每个脚本。从表面上看,ubuntu 正在从这个转向更简单的东西,所以如果你有 rc 目录,你可能需要稍微编辑你的脚本。
无论如何,我认为我在这里变得有点复杂了。检查你的可执行标志,如果你有 rc 目录,我们将从那里继续。
From looking at the website you provided I'd say that the /etc/init was just a typo and it should be /etc/init.d/. Some things you may want to check:
executable flag on your scripts. With most versions of Ubuntu executable files show up green when running 'ls' from the command line. If you want to check if your file is executable run 'ls -l /etc/init.d/YOUR_SCRIPT' from the command line. You will see something like this:
-rwxr-xr-x 1 root root 1342 2010-09-16 10:13 YOUR_SCRIPT
The x's mean that it is executable.
To set the executable flag if it is not set, run chmod u+x YOUR_SCRIPT
I'm pretty sure for older versions of ubuntu you need to have the script in /etc/rc.d/rc3.d or /etc/rc3.d. What linux does is run through rc0.d to rc5.d and execute every script in there. From what it looks like, ubuntu is moving away from this to something simpler so if you have rc directories you may need to edit your script a little.
Anyway I think i'm getting a little over complicated here. Check your executable flag and if you have rc directories and we'll move on from there.
使用 sudo 启动进程可能不是最好的选择,但这是我在本地电脑上设置的内容:
希望这会有所帮助。
May not be the best thing to start a process with sudo, but here's what I have setup on my local pc:
Hope this helps.