Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell SHOUTcast守护程序脚本运行不正常_Shell_Ubuntu_Daemon_Sh_Shoutcast - Fatal编程技术网

Shell SHOUTcast守护程序脚本运行不正常

Shell SHOUTcast守护程序脚本运行不正常,shell,ubuntu,daemon,sh,shoutcast,Shell,Ubuntu,Daemon,Sh,Shoutcast,我有一个运行在Ubuntu上的SHOUTcast服务器。服务器进程运行得很好,但我似乎无法使守护进程脚本正常运行。通过几篇教程,我发现我得出了以下结论: #!/bin/sh CONFIG="/home/apps/shout32/sc_plex.conf" DAEMON="/home/apps/shout32/sc_serv" case "$1" in start) echo "Starting SC..." $DAEMON $CONFIG > /

我有一个运行在Ubuntu上的SHOUTcast服务器。服务器进程运行得很好,但我似乎无法使守护进程脚本正常运行。通过几篇教程,我发现我得出了以下结论:

#!/bin/sh

CONFIG="/home/apps/shout32/sc_plex.conf"
DAEMON="/home/apps/shout32/sc_serv"

case "$1" in
    start)
        echo "Starting SC..."
        $DAEMON $CONFIG > /dev/null 2>&1 &
        ;;
    stop)
        echo "Stopping SC..."
        kill -9 `ps -C sc_serv -o pid --no-headers`
        ;;
    restart)
        echo "Rebooting SC..."
        kill -9 `ps -C sc_serv -o pid --no-headers`
        $DAEMON $CONFIG > /dev/null 2>&1 &
        ;;
    *)
        echo "usage: service sc32d {start | stop | restart}"
        exit 1
        ;;
esac
然而,这是行不通的。我不知道这意味着什么,所以我开始把它一行一行地分解。如果我删除了/dev/null文件(据我现在所知,它使程序在后台保持“静默”运行),我将收到以下消息,程序将关闭:

root@streams3:/etc/init.d# service sc32d start
Starting SC...
root@streams3:/etc/init.d# 2013-05-21 14:41:50  E       msg:<***>       logger could not open file logs/sc_serv.log
2013-05-21 14:41:50     I       msg:<***>       Logger shutdown

root@streams3:/etc/init.d#
root@streams3:/etc/init.d# ps -C sc_serv
  PID TTY          TIME CMD
root@streams3:/etc/init.d#
不幸的是,从我所做的简短的研究来看,“225号出口”听起来像是对超出可接受代码范围的代码的全面错误代码

整个问题中有趣的部分是:当我导航到/home/apps/shout32/文件夹并在那里运行命令时,没有完整的路径。。。该死的东西有用:

root@streams3:/home/apps/shout32# ./sc_serv sc_plex.conf > /dev/null 2>&1 &
[2] 2245
root@streams3:/home/apps/shout32#
root@streams3:/home/apps/shout32# ps -C sc_serv
  PID TTY          TIME CMD
 2245 pts/0    00:00:00 sc_serv
所以,由于脚本文件位于/etc/init.d/中,而不是应用程序所在的文件夹中,所以出现了一些问题?据我所知,我遵循出版的教程中的每一步,在Ubuntu中设置SHOUTcast,然后制作一个守护进程。。。我想我没有错过任何东西。我有一种感觉,这个解决方案要么就在我面前,要么就是有点让我不知所措

但任何帮助都将不胜感激


因此,根据下面的答案,我在脚本的START命令中添加了cd/home/apps/shout32/,还添加了pwd和ls。。。看看是否可以消除脚本找不到/log/目录的事实

现在我的脚本是:

CONFIG="/home/apps/shout32/sc_plex.conf"
DAEMON="/home/apps/shout32/sc_serv"

cd /home/apps/shout32/

case "$1" in
        start)
                echo "Starting SC..."
                cd /home/apps/shout32/
                pwd
                ls
                $DAEMON $CONFIG &
                ;;
        stop)
                echo "Stopping SC..."
                kill -9 `ps -C sc_serv -o pid --no-headers`
                ;;
        restart)
                echo "Rebooting SC..."
                kill -9 `ps -C sc_serv -o pid --no-headers`
                $DAEMON $CONFIG &
                ;;
        *)
                echo "usage: service sc32d {start | stop | restart}"
                exit 1
                ;;
esac
我明白了:

admin@streams3:/etc/init.d$ service sc32d start
Starting SC...
/home/apps/shout32
changes.txt     readme.txt                     sc_serv_debug.conf
config_builder  sc_plex.conf                   sc_serv_public.conf
control         sc_serv                        sc_serv_relay.conf
docs            sc_serv2_linux_07_31_2011.tar  sc_serv_simple.conf
logs            sc_serv_basic.conf             tos.txt
admin@streams3:/etc/init.d$ 2013-06-05 17:52:08      E       msg:<***>      logger could not open file logs/sc_serv.log
2013-06-05 17:52:08     I       msg:<***>       Logger shutdown
admin@streams3:/etc/init.d$service sc32d start
启动SC。。。
/主页/应用程序/首选项32
changes.txt readme.txt sc_serv_debug.conf
config_builder sc_plex.conf sc_serv_public.conf
控制sc_serv sc_serv_继电器.conf
docs sc_serv2_linux_07_31_2011.tar sc_serv_simple.conf
日志sc_serv_basic.conf tos.txt
admin@streams3:/etc/init.d$2013-06-05 17:52:08 E msg:logger无法打开文件logs/sc_serv.log
2013-06-05 17:52:08信息:记录器关闭

您的第二个代码段包含
记录器无法打开文件logs/sc_serv.log
。因此,它尝试写入一个文件
sc_serv.log
,该文件预期或希望在
logs
目录中创建,该目录预期位于当前目录中。这也解释了当您先将cd刻录到/home/apps/shout32/时,它会起作用。我猜有一个文件
/home/apps/shout32/logs/sc_serv.log

您可以配置该文件的位置吗?
你不能在脚本的开头添加一些
cd…
吗?

是的,在我自己的操作后的故障排除中,我确定这与/logs有关。确实有一个/home/apps/shout32/logs/sc_serv.log,我试图更改文件夹/文件上的权限等等。。。。然而,你的建议没有在我脑海中出现。我该如何指导脚本像在X目录中一样运行呢?哦!我明白你的意思,只要用cd/home/apps/shout32开始脚本就行了。。。。让我现在就去试试!我用结果更新了OP,运气不好。也许我完全误解了你的建议。不,不,你说得对,但显然没有用。也许守护进程
cd
s会进入另一个目录。奇怪的是,日志文件是用相对路径指定的,这是不寻常的。
$CONFIG
中有什么?有一个你永远不知道的相对路径。。。至少对于调试,我会指定一个故障保护绝对路径,如
logfile=/tmp/sc_serv.log
admin@streams3:/etc/init.d$ service sc32d start
Starting SC...
/home/apps/shout32
changes.txt     readme.txt                     sc_serv_debug.conf
config_builder  sc_plex.conf                   sc_serv_public.conf
control         sc_serv                        sc_serv_relay.conf
docs            sc_serv2_linux_07_31_2011.tar  sc_serv_simple.conf
logs            sc_serv_basic.conf             tos.txt
admin@streams3:/etc/init.d$ 2013-06-05 17:52:08      E       msg:<***>      logger could not open file logs/sc_serv.log
2013-06-05 17:52:08     I       msg:<***>       Logger shutdown