的init.d脚本挂 [英] Init.d script hanging

查看:148
本文介绍了的init.d脚本挂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剧本的init.d,看起来像:

I have an init.d script that looks like:

#!/bin/bash
# chkconfig 345 85 60
# description: startup script for swapi
# processname: swapi

LDIR=/var/www/html/private/daemon
EXEC=swapi.php
PIDF=/var/run/swapi.pid
IEXE=/etc/init.d/swapi

### BEGIN INIT INFO
# Provides: swapi
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: startup script for swapi
# Description: startup script for swapi.php which processes actionq into switch
### END INIT INFO

if [ ! -f $LDIR/$EXEC ]
then
        echo "swapi was not found at $LDIR/$EXEC"
        exit
fi

case "$1" in
  start)
        if [ -f $PIDF ]
        then
                echo "swapi is currently running. Killing running process..."
                $IEXE stop
        fi
        $LDIR/$EXEC >> $LDIR/swapi.log & MYPID=$!
        echo $MYPID > $PIDF
        echo "swapi is now running."
        ;;
  stop)
        if [ -f $PIDF ]
        then
                echo "Stopping swapi."
                PID_2=`cat $PIDF`
                if [ ! -z "`ps -f -p $PID_2 | grep -v grep | grep 'swapi'`" ]
                then
                        kill -9 $PID_2
                fi
                rm -f $PIDF
        else
                echo "swapi is not running, cannot stop it. Aborting now..."
        fi
        ;;
  force-reload|restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Use: /etc/init.d/swapi {start|stop|restart|force-reload}"
        exit 1
esac

然后,我有一个存活的cronjob调用此如果PID下降。问题是,保活脚本挂起,每当我运行它像一个cron作业(即运行部分的/ var / www / html等/私营/ fivemin),(保活脚本在/ var / WWW是/ HTML /私营/ fivemin)

And then I have a keepalive cronjob that calls this if the pid goes down. Problem is that that keepalive script hangs whenever I run it like a cron job (ie. run-parts /var/www/html/private/fivemin), (the keepalive script being in /var/www/html/private/fivemin).

有没有在我的init.d脚本的东西时髦,我很想念?

Is there something funky in my init.d script that I am missing?

我一直在货架我的大脑在这个问题上几个小时吧!我在centos4 BTW。

I have been racking my brain on this problem for hours now! I am on centos4 btw.

感谢您的帮助。
-Eric

Thanks for any help. -Eric

编辑:

保活/的cronjob脚本简化测试,以一个简单的:

The keepalive/cronjob script was simplified for testing to a simple:

#!/usr/bin/php
<?

exec("/etc/init.d/swapi start");

?>

奇怪,这是从swapi.php输出误差投入相似,但我所有的输出被丢到了的init.d脚本swapi.log正常的cron输出的/ var / spool / mail中?

The strange this is the error output from swapi.php is put into /var/spool/mail like normal cron output except that I have all the output being dumped into the swapi.log in the init.d script?

当我从CLI运行keepalive.php(从/根),它的运作完全按照我希望它。

When I run keepalive.php from the cli (as root from /) it operates exactly as I would expect it to.

在运行保活的ps aux | grep的PHP是这样的:

When keepalive runs ps aux | grep php looks like:

root      4525  0.0  0.0  5416  584 ?        S    15:10   0:00 awk -v progname=/var/www/html/private/fivemin/keepalive.php progname {?????   print progname ":\n"?????   progname="";????       }????       { print; }
root      4527  0.7  1.4 65184 14264 ?       S    15:10   0:00 /usr/bin/php /var/www/html/private/daemon/swapi.php

如果我做了:

/etc/init.d/swapi stop

从CLI那么两个程序都不再列出。

from the cli then both programs are no longer listed.

Swapi ls -l命令如下:

Swapi ls -l looks like:

-rwxr-xr-x  1 5500 5500 33148 Aug 29 15:07 swapi.php

下面是crontab的样子:

Here is what the crontab looks like:

*/5 * * * * root run-parts /var/www/html/private/fivemin

下面是swapi.php的第一个比特

Here is the first bit of swapi.php

#!/usr/bin/php
<?
chdir(dirname( __FILE__ ));
include("../../config/db.php");
include("../../config/sql.php");
include("../../config/config.php");
include("config_local.php");
include("../../config/msg.php");

include("../../include/functions.php");

set_time_limit(0);
echo "starting @ ".date("Ymd.Gi")."...\n";
$actionstr  =   "";
while(TRUE){

我修改剧本的init.d,把上面的初始化变量声明,它并没有发挥作用。

I modified the init.d script and put init above the variable declarations, it did not make a difference.

推荐答案

答案是,庆典住打开,因为我的init.d脚本不是重定向stderr输出。我现在已经改成了

The answer was that bash was staying open because my init.d script was not redirecting the stderr output. I have now changed it to

$LDIR/$EXEC &> $LDIR/swapi.log & MYPID=$!

和现在的功能完好。

感谢大家的帮助!

这篇关于的init.d脚本挂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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