与rc.local中运行脚本:脚本工作,但不会在引导 [英] Run script with rc.local: script works, but not at boot
问题描述
我有需要在引导的并启动一个Node.js的剧本的WWW的数据用户下运行。在开发过程中我总是开始与脚本:
I have a node.js script which need to start at boot and run under the www-data user. During development I always started the script with:
su www-data -c 'node /var/www/php-jobs/manager.js
我看到到底发生了什么,在manager.js现在的作品太棒了。搜索SO我发现我有放置这在我的的/etc/rc.local
。另外,我学会了输出指向一个日志文件,并追加 2 - ;&放大器; 1
来stderr重定向到stdout,它应该是一个守护进程,最后性格是一个&放大器;
I saw exactly what happened, the manager.js works now great. Searching SO I found I had to place this in my /etc/rc.local
. Also, I learned to point the output to a log file and to append the 2>&1
to "redirect stderr to stdout" and it should be a daemon so the last character is a &
.
最后,我的的/etc/rc.local
是这样的:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
su www-data -c 'node /var/www/php-jobs/manager.js >> /var/log/php-jobs.log 2>&1 &'
exit 0
如果我运行这个自己(须藤的/etc/rc.local
):是的,它的作品!但是,如果我执行重新启动进程正在运行,没有节点,在
/var/log/php-jobs.log
不存在并且因此,manager.js不起作用。这是怎么回事?
If I run this myself (sudo /etc/rc.local
): yes, it works! However, if I perform a reboot no node
process is running, the /var/log/php-jobs.log
does not exist and thus, the manager.js does not work. What is happening?
推荐答案
我结束了<一个href=\"http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/\">upstart,工作正常。
这篇关于与rc.local中运行脚本:脚本工作,但不会在引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!