使用 rc.local 运行脚本:脚本有效,但在启动时无效 [英] Run script with rc.local: script works, but not at boot

查看:43
本文介绍了使用 rc.local 运行脚本:脚本有效,但在启动时无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 node.js 脚本,它需要在启动时启动 在 www-data 用户下运行.在开发过程中,我总是用以下方式启动脚本:

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 看起来像这样:

Finally, my /etc/rc.local looks like this:

#!/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

如果我自己运行它 (sudo/etc/rc.local):是的,它有效!但是,如果我执行重新启动没有 node 进程正在运行,/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?

推荐答案

我最终得到了 upstart,效果很好.

I ended up with upstart, which works fine.

这篇关于使用 rc.local 运行脚本:脚本有效,但在启动时无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆