Ubuntu 8.04 Hardy 和 node.js 新贵脚本

发布于 2024-12-06 08:48:32 字数 1383 浏览 3 评论 0原文

我正在尝试为我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遇见了你 2024-12-13 08:48:32

通过查看您提供的网站,我会说 /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.

贪了杯 2024-12-13 08:48:32

使用 sudo 启动进程可能不是最好的选择,但这是我在本地电脑上设置的内容:

#!upstart
description "node.js server"
author      "alessio"

start on startup
stop on shutdown

script
    export HOME="/ubuntu"

    exec sudo -u ubuntu /usr/bin/node /home/ubuntu/www/test.js 2>&1 >> /var/log/node.log
end script

希望这会有所帮助。

May not be the best thing to start a process with sudo, but here's what I have setup on my local pc:

#!upstart
description "node.js server"
author      "alessio"

start on startup
stop on shutdown

script
    export HOME="/ubuntu"

    exec sudo -u ubuntu /usr/bin/node /home/ubuntu/www/test.js 2>&1 >> /var/log/node.log
end script

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文