如何设置rc.d脚本以在FreeBSD中启动Plex Media Server?

时间:2018-07-15 19:55:38

标签: sh freebsd plex

我的LG TV停止使用旧版本的Plex 1.3,因此我被迫更新到Plex 1.13

我正在监狱中的Nas4Free 0.9上运行我的Plex版本。

我能够下载并运行,但无法自动启动。由于某些原因,/ etc / local / rc.d中的plexmediaserver脚本失败。

其他人也有类似的问题。我只会以其他方式知道一些shell脚本,我会尝试自己修复它。

这是旧版Plex随附的当前脚本

#!/bin/sh
# Created by: KalleDK <plexmaintainer@k-moeller.dk>
#
# $FreeBSD: head/multimedia/plexmediaserver/files/plexmediaserver.in 409168 2016-02-19 11:41:13Z feld $
#
# PROVIDE: plexmediaserver
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the Plex Media Server:
#
# plexmediaserver_enable="YES"
#
# plexmediaserver_support_path="/usr/local/plexdata" # Plex data: logs, media metadata, settings, etc
#
# plexmediaserver_tmp="/var/tmp/plex" # configure tmp directory used for the transcoding process if desired
#
# plexmediaserver_maxplugins="6" # Maximum number of background plugin procs. May have to raise in rare cases.
#

. /etc/rc.subr

name=plexmediaserver
rcvar=plexmediaserver_enable
load_rc_config $name

: ${plexmediaserver_enable:=NO}
: ${plexmediaserver_support_path="/usr/local/plexdata"}
: ${plexmediaserver_user="plex"}
: ${plexmediaserver_group="plex"}
: ${plexmediaserver_maxplugins=6}

command=/usr/sbin/daemon
procname="/usr/local/share/plexmediaserver/Plex_Media_Server"
command_args="-f ${procname}"
pidfile=/var/run/plex/plex.pid
start_precmd=plex_precmd
stop_precmd=plex_stop_precmd
stop_postcmd=plex_stop_postcmd

plex_precmd()
{
    export SUPPORT_PATH="${plexmediaserver_support_path}"
    export HOME="${plexmediaserver_support_path}/Plex Media Server"
    export PYTHONHOME="/usr/local/share/plexmediaserver/Resources/Python"
    export SCRIPTPATH="/usr/local/share/plexmediaserver"
    export LD_LIBRARY_PATH="/usr/local/lib/compat:${SCRIPTPATH}"
    export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
    export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=${plexmediaserver_maxplugins}
    export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=${plexmediaserver_support_path}
    export PLEX_MEDIA_SERVER_PIDFILE=${pidfile}
    export PLEX_MEDIA_SERVER_LOG_DIR="${plexmediaserver_support_path}/Plex Media Server/Logs"
    export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"
    export LC_ALL="en_US.UTF-8"
    export LANG="en_US.UTF-8"
    ulimit -s 3000

    if [ ! -d ${pidfile%/*} ]; then
        echo "Option 1"
        install -d -o ${plexmediaserver_user} ${pidfile%/*};
    fi

    if [ ! -d "${plexmediaserver_support_path}/Plex Media Server" ]; then
        echo "Option 2"
        install -d -g ${plexmediaserver_group} -o ${plexmediaserver_user} "${plexmediaserver_support_path}/Plex Media Server";
    fi

    if [ ${plexmediaserver_tmp} ]; then
        "echo Option 3" 
        export TMPDIR=${plexmediaserver_tmp};
        install -d -g ${plexmediaserver_group} -o ${plexmediaserver_user} "${plexmediaserver_tmp}";
    fi
}

plex_stop_precmd()
{
    if [ -r ${pidfile} ]; then
        export _PLEXPID=$(check_pidfile ${pidfile} ${procname})
    fi
}

plex_stop_postcmd()
{
    _PLEX_CHILDREN=$(pgrep -g ${_PLEXPID})
    echo "Cleaning up leftover child processes."
    kill $sig_stop ${_PLEX_CHILDREN}
    wait_for_pids ${_PLEX_CHILDREN}
}

run_rc_command "$1"

0 个答案:

没有答案