首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >D:通过“启动-停止-守护进程”启动mplayer

D:通过“启动-停止-守护进程”启动mplayer
EN

Stack Overflow用户
提问于 2013-07-24 18:03:08
回答 1查看 3.3K关注 0票数 3

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

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

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

现在,我编写了以下脚本

代码语言:javascript
复制
# /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

但是有一些错误,因为当我尝试启动脚本时,播放机返回一个错误,但没有正确启动:

代码语言:javascript
复制
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,在关机中自动运行stop

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-25 09:20:23

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

代码语言:javascript
复制
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"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17841532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档