简体   繁体   English

Ubuntu 8.04 Hardy和node.js新贵脚本

[英]Ubuntu 8.04 Hardy and node.js upstart script

I am trying to write an upstart script for my ubuntu machine, which is version 8.04 "Hardy". 我正在尝试为版本8.04“ Hardy”的ubuntu计算机编写新贵的脚本。 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. 我已经按照以下站点上的说明进行操作: node.js的新贵,但似乎这些说明适用于当前版本的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. 我注意到/ etc / init目录在我的机器上不存在,首先尝试将脚本放在/etc/init.d目录中,然后创建/ etc / init目录并将其放置在该目录中。

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". 我将在下面发布我的暴发户脚本(与上面的网站基本相同,但路径有所更改),但是当我运行start jobname时,我只会收到一个错误“ 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. 现在,我正在使用“ nohup”命令来运行我的节点服务器,但是我想要一个更永久的解决方案。

Please, any help? 请帮忙吗?

SCRIPT 1: 脚本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: 脚本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

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/. 通过查看您提供的网站,我会说/ etc / init只是一个错字,应该是/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. 在大多数版本的Ubuntu中,从命令行运行'ls'时可执行文件会显示为绿色。 If you want to check if your file is executable run 'ls -l /etc/init.d/YOUR_SCRIPT' from the command line. 如果要检查文件是否可执行,请从命令行运行“ ls -l /etc/init.d/YOUR_SCRIPT”。 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. 您将看到以下内容:-rwxr-xr-x 1 root root 1342 2010-09-16 10:13 YOUR_SCRIPT x的意思是它是可执行的。 To set the executable flag if it is not set, run chmod u+x YOUR_SCRIPT 要设置可执行标志(如果未设置),请运行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. 我很确定对于较早版本的ubuntu,您需要在/etc/rc.d/rc3.d或/etc/rc3.d中具有脚本。 What linux does is run through rc0.d to rc5.d and execute every script in there. linux通过rc0.d到rc5.d运行并执行其中的每个脚本。 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. 从表面上看,ubuntu正在从此过渡到更简单的东西,因此,如果您有rc目录,则可能需要稍微编辑一下脚本。

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. 检查您的可执行标志,以及是否有rc目录,我们将继续进行。

May not be the best thing to start a process with sudo, but here's what I have setup on my local pc: 用sudo启动进程可能不是最好的方法,但这是我在本地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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM