bash 如何将 icecast 作为服务并重新启动它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42188137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make icecast as service and restart it?
提问by w3spi
I installed Icecast 2.4.3 on my server using direct downloadto get the latest version available.
我使用直接下载在我的服务器上安装了 Icecast 2.4.3以获得可用的最新版本。
In this way, I don't use the version distributed by my distribution (debian 8) and thus don't have the daemon activated by default.
通过这种方式,我不使用我的发行版 (debian 8) 分发的版本,因此默认情况下没有激活守护程序。
I found a script that I modified with my corresponding paths, but the execution is in error.
找到了一个脚本,用我对应的路径修改,但是执行出错。
The script icecast.sh
:
脚本icecast.sh
:
#!/bin/bash
#
# Init file for Icecast server daemon
#
# chkconfig: 345 55 25
# description: Icecast streaming mp3 server daemon
#
# processname: icecast
# config: /etc/icecast.xml
# pidfile: /var/run/icecast.pid
# source function library
# . /etc/rc.d/init.d/functions : returns an error on debian 8
. /lib/lsb/init-functions
# pull in sysconfig settings
[ -f /etc/sysconfig/icecast ] && . /etc/sysconfig/icecast
RETVAL=0
prog="icecast"
# Some functions to make the below more readable
PREFIX=/usr/local
PATH=$PATH:$PREFIX/bin
PIDFILE=/icecast/icecast.pid
CONF_FILE=/icecast/conf/icecast.xml
[ -f $PREFIX/bin/icecast ] || ( echo Failed to locate icecast binary: $PREFIX/bin/icecast && exit )
[ -f $CONF_FILE ] || ( echo Failed to locate icecast configuration file: $CONF_FILE && exit )
OPTIONS="-b -c $CONF_FILE"
start()
{
echo -n $"Starting $prog:"
ulimit -c unlimited # dump core for debugging purposes
ulimit -n 32768
daemon icecast icecast $OPTIONS
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/icecast
echo
pidof icecast > $PIDFILE
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog:"
killproc icecast -TERM
RETVAL=$?
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/icecast
echo
rm -f $PIDFILE
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog:"
killproc icecast -HUP
RETVAL=$?
echo
return $RETVAL
}
condrestart()
{
[ -e /var/lock/subsys/icecast ] && restart
return 0
}
case "" in
start)
start
;;
stop)
stop
;;
restart)
stop
# wait for listening sockets to clear
echo "Waiting 5 seconds before restarting..."
sleep 5
start
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status icecast
RETVAL=$?
;;
*)
echo $"Usage: # sh icecast.sh status
icecast.sh: line 93: status : unknow command
{start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
And the error I'm getting when I'm doing sh icecast.sh status
:
我在做的时候遇到的错误sh icecast.sh status
:
Q1: How do I fix this error?
Q1:我该如何解决这个错误?
Q2: How do I get a functional command like icecast restart service
?
Q2:我如何获得一个功能性的命令icecast restart service
?
Q3: What should I do to restart Icecast automatically if the server restarts itself?
Q3: 如果服务器自行重启,我应该怎么做才能自动重启 Icecast?
回答by TBR
The answer is to use the properpackage from either debian backportsor if you e.g. need TLS support the package from official Xiph.org repositories.
答案是使用来自debian backports的正确包,或者如果您需要 TLS 支持来自官方 Xiph.org 存储库的包。
This guarantees, that you will receive package updates without having to monitor releases yourself and figure out necessary changes.
这保证了您将收到包更新,而无需自己监控版本并找出必要的更改。
Also please note that the latest release for Linux/Unix at this time is 2.4.2, as 2.4.3 was a Windowsonly release. The code is identical if compiled for Linux/Unix.
另请注意,此时 Linux/Unix 的最新版本是2.4.2,因为 2.4.3 是仅适用于Windows 的版本。如果为 Linux/Unix 编译,代码是相同的。
回答by Alex Paramonov
- Install a package from you distro (
apt-get install icecast2
,yum install icecast
, whatever). Usually pakage manager also installs init scripts that will allow you start/stop Icecast. - Get your Icecast patht with
which icecast
orwhereis icecast
- Download Icecast, build it from source (like if you need to replace official Icecast with Icecast-kh branch or use your own compilation flags).
- Replace the original icecast binary from (2) with the one that you have build. It's always better to backup the original version, though.
/etc/inid/icecast restart
orsystemctr restart icecast
should work now with your version of Icecast.- To make sure your Icecast will start after reboot run
systemctl enable icecast
- 从安装包发行版(
apt-get install icecast2
,yum install icecast
,等等)。通常,包管理器还会安装初始化脚本,允许您启动/停止 Icecast。 - 使用
which icecast
或获取您的 Icecast 路径whereis icecast
- 下载 Icecast,从源代码构建它(比如如果你需要用 Icecast-kh 分支替换官方 Icecast 或使用你自己的编译标志)。
- 将 (2) 中的原始 icecast 二进制文件替换为您已构建的二进制文件。不过,最好备份原始版本。
/etc/inid/icecast restart
或者systemctr restart icecast
现在应该与您的 Icecast 版本一起使用。- 确保您的 Icecast 在重启后启动
systemctl enable icecast