gpt4 book ai didi

ubuntu - init.d:​​ 通过 "start-stop-daemon"启动 mplayer

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:21 25 4
gpt4 key购买 nike

Ubuntu 机器上,我想像守护进程一样运行 MPlayer

在前台,以下配置正是我所需要的:

mplayer -slave -idle -input file=/tmp/mplayercontrol

现在,我编写了以下脚本:

# /etc/init.d/mplayerd
### BEGIN INIT INFO
# Provides: mplayer
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Should-Start: $time
# Should-Stop: $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the mplayer daemon
# Description: mplayer daemon
### END INIT INFO

CONTROLFILE="/tmp/mplayercontrol"
DAEMONUSER=jb

DAEMON=/usr/bin/mplayer
DAEMON_ARGS="-slave -idle -input file=$CONTROLFILE"
PIDFILE=/tmp/mplayerd.pid

start() {
echo "Starting mplayer..."

# Prepare fifo file
rm -rf $CONTROLFILE
mkfifo $CONTROLFILE
chmod a+rw $CONTROLFILE

start-stop-daemon --start --quiet --user $DAEMONUSER \
--make-pidfile --pidfile $PIDFILE --background \
--exec /bin/bash -- -c "$DAEMON $DAEMON_ARGS > /tmp/mplayerd.log 2>&1"

echo "Started for user: $DAEMONUSER."
}

stop() {
echo "Stopping mplayer..."
kill -9 `cat $PIDFILE`
# Cleanup fifo file
rm -rf $CONTROLFILE
}

status() {
if [ -z `cat $PIDFILE` ];
then
echo "mplayerd: not running."
else
echo "mplayerd: running."
fi
}


case "$1" in
start)
start
;;

stop)
stop
;;

restart|reload|force-reload)
stop
start
;;

status)
status
;;

*)
echo "Usage: /etc/init.d/mplayerd {start|stop|reload|force-reload|restart|status}"
exit 1

esac

exit 0

但是有些地方不对劲,因为当我尝试启动脚本时,播放器返回一个错误并且没有正确启动:

root@jb:/tmp# service mplayerd start
Starting mplayer...
Started for user: jb.
root@jb:/tmp#
root@jb:/tmp# cat /tmp/mplayerd.log
Cannot find HOME directory.
MPlayer 1.0rc4-4.4.3 (C) 2000-2010 MPlayer Team
root@jb:/tmp#

此外,如何在启动时自动运行/etc/inid.d/mplayerd stop,在关闭时自动运行stop ?

谢谢!

最佳答案

在 shell 命令之前声明 HOME=/home/$DAEMONUSER

start-stop-daemon --start --quiet --user $DAEMONUSER    \
--make-pidfile --pidfile $PIDFILE --background \
--exec /bin/bash -- -c "HOME=/home/$DAEMONUSER $DAEMON $DAEMON_ARGS > /tmp/mplayerd.log 2>&1"

关于ubuntu - init.d:​​ 通过 "start-stop-daemon"启动 mplayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17841532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com