在 Ubuntu 中调试 /etc/init.d 启动脚本
我正在尝试通过 ubuntu 中的 /etc/init.d 启动自定义 dropr 消息队列轮询器。 所有 3 个脚本都非常简单,并且可以通过命令行完美运行,但由于某种原因,只有其中一个在服务器启动时真正起作用。全部都有 775 个权限,这很好用:
sudo /etc/init.d/app-poller.sh
这是一个示例脚本(必须以 www-data 用户身份运行):
[/etc/init.d]$ cat /etc/init.d/app-poller.sh
#!/bin/sh
su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"
我已经通过以下方式多次运行删除/重新输入 inittab 条目:
updates-rc.d -f app-poller.sh remove
updates-rc.d app-poller.sh defaults
rcconf 脚本还说一切都开始正常。 我已按照此处的所有说明进行操作: http://jonathonhill.net/2009-04-23/auto-start-a-shell-script-on-ubuntu-server/ 此处和此处:http://stringofthoughts.wordpress.com/2009/ 04/16/adding-removing-shell-scripts-ubuntu-810/
我在所有常见的嫌疑人中寻找输出(/var/log/messages、/var/log/daemons 等)...仍然没有线索。
非常想至少了解一下为什么会失败。任何人都知道我可以参考哪些日志文件来查看出了什么问题&为什么?
Have custom dropr message queue pollers I'm trying to start up via /etc/init.d in ubuntu.
All 3 scripts are super-simple one liners and work perfect via command line, but for some reason, only one of them actually works when the server boots up. All have 775 perms, and this works great:
sudo /etc/init.d/app-poller.sh
Here's an example script (has to run as www-data user):
[/etc/init.d]$ cat /etc/init.d/app-poller.sh
#!/bin/sh
su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"
I've run removed / re-entered the inittab entries several times via:
updates-rc.d -f app-poller.sh remove
updates-rc.d app-poller.sh defaults
rcconf script also says everything is starting fine.
I've followed all the instructions here: http://jonathonhill.net/2009-04-23/auto-start-a-shell-script-on-ubuntu-server/ here and here: http://stringofthoughts.wordpress.com/2009/04/16/adding-removing-shell-scripts-ubuntu-810/
And I've looked for output in all the usual suspects (/var/log/messages, /var/log/daemons, etc)... still no clue.
Would very much like to at least have some insight into why this is failing. Anyone know which logfiles I can reference to see what is going wrong & why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现在 /etc/init.d/scriptname 顶部附近添加以下内容就是我所需要的:
I found adding the following near the top of my /etc/init.d/scriptname was all I needed:
尝试在模拟启动时环境时调用 init 脚本:
如果您没有看到该命令的任何输出,请向脚本中添加一些调试输出。
Try calling the init-script while simulating the boottime environment:
Do add some debug output to your script if you don't see any output from that command.
使用 -x 在子 shell 中运行它。
http://tldp.org/LDP/Bash-Beginners-Guide/html /sect_02_03.html
Run it in a sub-shell with -x.
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
尝试将:
su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"
更改为:
/bin/su - www-data -c“/bin/bash -c '/path/to/dropr-server/daemons/app-poller.php'”
Try changing:
su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"
to:
/bin/su - www-data -c "/bin/bash -c '/path/to/dropr-server/daemons/app-poller.php'"