在 Ubuntu 中调试 /etc/init.d 启动脚本

发布于 2024-12-13 11:58:47 字数 1112 浏览 0 评论 0原文

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

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

发布评论

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

评论(4

风月客 2024-12-20 11:58:47

我发现在 /etc/init.d/scriptname 顶部附近添加以下内容就是我所需要的:

debug_me=true

if [[ $debug_me == true ]]; then

  # Close STDOUT
  exec 1<&-
  # Close STDERR
  exec 2<&-

  LOG_FILE=/home/myhome/scriptname.log

  # Open STDOUT as $LOG_FILE file for read and write.
  exec 1<>$LOG_FILE

  # Redirect STDERR to STDOUT
  exec 2>&1

  # Display shell commands with expanded args
  set -x

fi

I found adding the following near the top of my /etc/init.d/scriptname was all I needed:

debug_me=true

if [[ $debug_me == true ]]; then

  # Close STDOUT
  exec 1<&-
  # Close STDERR
  exec 2<&-

  LOG_FILE=/home/myhome/scriptname.log

  # Open STDOUT as $LOG_FILE file for read and write.
  exec 1<>$LOG_FILE

  # Redirect STDERR to STDOUT
  exec 2>&1

  # Display shell commands with expanded args
  set -x

fi
双手揣兜 2024-12-20 11:58:47

尝试在模拟启动时环境时调用 init 脚本:

env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" /etc/init.d/your-daemon start 

如果您没有看到该命令的任何输出,请向脚本中添加一些调试输出。

Try calling the init-script while simulating the boottime environment:

env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" /etc/init.d/your-daemon start 

Do add some debug output to your script if you don't see any output from that command.

-柠檬树下少年和吉他 2024-12-20 11:58:47

尝试将:

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'"

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