【问题标题】:Upstart - Job starts but then stops immediatelyUpstart - 作业开始但立即停止
【发布时间】:2014-07-25 09:35:41
【问题描述】:

我正在尝试设置一个新贵的工作,但由于某种原因它在开始后立即停止

我的价格是 6.5 美分

这是我的文件:

/ect/init/test-daemon.conf

start on startup
stop on shutdown
respawn

script
    sudo -u root php -f /usr/share/test_daemon.php
end script

/usr/share/test-daemon.php

<?php

    // The worker will execute every X seconds:
    $seconds = 2;

    // We work out the micro seconds ready to be used by the 'usleep' function.
    $micro = $seconds * 1000000;

    while(true){

        // Now before we 'cycle' again, we'll sleep for a bit...
        usleep($micro);
    }

然后我得到了这个文件:(我在一个记录事件的论坛上找到的)

/tmp/log.file

debug/ (/dev/fd/10):19735:Fri Jul 25 11:52:40 AST 2014:Job
test-daemon/ starting. Environment was: TERM=linux
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
PWD=/ JOB=test-daemon
SHLVL=1
UPSTART_INSTANCE=
UPSTART_EVENTS=starting
UPSTART_JOB=debug
INSTANCE=
_=/usr/bin/env

debug/ (/dev/fd/9):19775:Fri Jul 25 11:52:41 AST 2014:Job test-daemon/ stopping. Environment was:
TERM=linux
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
PWD=/
JOB=test-daemon
RESULT=ok
SHLVL=1
UPSTART_INSTANCE=
UPSTART_EVENTS=stopping
UPSTART_JOB=debug
INSTANCE=
_=/usr/bin/env

debug/ (/dev/fd/9):19779:Fri Jul 25 11:52:41 AST 2014:Job test-daemon/ stopping. Environment was:
TERM=linux
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
PWD=/
JOB=test-daemon
RESULT=failed
SHLVL=1
PROCESS=respawn
UPSTART_INSTANCE=
UPSTART_EVENTS=stopping
UPSTART_JOB=debug
INSTANCE=
_=/usr/bin/env

在日志文件中,我得到了更多的调试信息,但基本上上面重复了几次。

我通过运行start test-daemon 得到这个输出test-daemon start/running, process 20600

我知道 test-daemon.php 实际上并没有做任何事情......目前我只需要运行实际的工作,一旦修复了我的代码中的问题

所以从上面...有什么我做错了吗?因为只有在我运行stop test-daemon 时才应该停止工作,对吗?

任何建议将不胜感激:)

谢谢, 戴夫

【问题讨论】:

    标签: php daemon centos6 upstart


    【解决方案1】:

    我宁愿发表评论,但由于声誉限制较低,我不能发表评论。 我不熟悉这种发行版的味道,但你尝试过使用 nohup 吗? 像这样:

    nohup php -f /usr/share/test_daemon.php &amp;

    从服务进程中分离你的命令可能会杀死它。

    【讨论】:

    • 嗨@NaeiinDus,谢谢你的回复,这是我输入你的cmd时得到的:[1] 11512 root@server [~]# nohup:忽略输入并将输出附加到`nohup .out' 这是什么意思?
    • 抱歉,我检查了 nohup.out 文件...但它是空的?
    • nohup 的默认行为是将命令生成的所有输出重定向到文件 (nohup.out)。与"nohup [cmd] > ./nohup.out` 相同 由于nohup 用于创建后台程序,因此它也会忽略所有可能的输入(因此您无法使用STDIN 向其发送信息)。您的文件是正常的是空的,你的脚本没有输出任何东西 :) 尝试添加一个虚拟回声,你应该会看到一些东西。
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 2017-01-01
    相关资源
    最近更新 更多