blob: 3438faf400bc0574ce1c2f8066fa98fc1b2d9bd0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/bin/sh
# Created by: Created by: KalleDK <plexmaintainer@k-moeller.dk>
#
# $FreeBSD$
#
# PROVIDE: plexmediaserver_plexpass
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the Plex Media Server:
#
# plexmediaserver_plexpass_enable="YES"
#
# plexmediaserver_plexpass_support_path="%%SUPPORT_PATH%%" # Plex data: logs, media metadata, settings, etc
#
# plexmediaserver_plexpass_tmp="/tmp" # tmp directory used for the transcoding process
#
# plexmediaserver_plexpass_maxplugins="6" # Maximum number of background plugin procs. May have to raise in rare cases.
#
. /etc/rc.subr
name=plexmediaserver_plexpass
rcvar=plexmediaserver_plexpass_enable
load_rc_config $name
: ${plexmediaserver_plexpass_enable:=NO}
: ${plexmediaserver_plexpass_support_path="%%SUPPORT_PATH%%"}
: ${plexmediaserver_plexpass_user="%%USERS%%"}
: ${plexmediaserver_plexpass_group="%%GROUPS%%"}
: ${plexmediaserver_plexpass_maxplugins=6}
extra_commands=status
start_precmd=plex_precmd
start_cmd=plex_startcmd
status_cmd=plex_statuscmd
stop_cmd=plex_stopcmd
pidfile=/var/run/plex/plex.pid
plex_precmd()
{
export SUPPORT_PATH="${plexmediaserver_plexpass_support_path}"
export HOME="${plexmediaserver_plexpass_support_path}/Plex Media Server"
export PYTHONHOME="%%SCRIPT_PATH%%/Resources/Python"
export SCRIPTPATH="%%SCRIPT_PATH%%"
export LD_LIBRARY_PATH="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=${plexmediaserver_plexpass_maxplugins}
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=${plexmediaserver_plexpass_support_path}
export PLEX_MEDIA_SERVER_PIDFILE=${pidfile}
if ${plexmediaserver_tmp}; then export PLEX_MEDIA_SERVER_TMPDIR=${plexmediaserver_plexpass_tmp}; fi
export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"
export LC_ALL="C"
export LANG="C"
ulimit -s 3000
if [ ! -d ${pidfile%/*} ]; then
install -d -o ${plexmediaserver_plexpass_user} ${pidfile%/*};
fi
if [ ! -d "${plexmediaserver_plexpass_support_path}/Plex Media Server" ]; then
install -d -g ${plexmediaserver_plexpass_group} -o ${plexmediaserver_plexpass_user} "${plexmediaserver_plexpass_support_path}/Plex Media Server";
fi
}
plex_startcmd()
{
if [ -f "${pidfile}" ] && (pgrep -F ${pidfile} Plex >/dev/null); then
echo "${name} is already running with pid: $(cat ${pidfile})";
else
echo "Starting ${name}."
/usr/sbin/daemon -u ${plexmediaserver_plexpass_user} -f '%%SCRIPT_PATH%%/Plex Media Server'
fi
}
plex_statuscmd()
{
if [ -f "${pidfile}" ] && (pgrep -F ${pidfile} Plex >/dev/null); then
echo "${name} is running with pid: $(cat ${pidfile})";
else
echo "${name} is not running.";
exit 1;
fi
}
plex_stopcmd()
{
if [ -f "${pidfile}" ] && (pgrep -F ${pidfile} Plex >/dev/null); then
main_pid=$(cat ${pidfile});
child_pids=$(pgrep -P ${main_pid});
all_pids="${main_pid} ${child_pids}"
sig_stop=-QUIT;
kill ${sig_stop} ${all_pids};
wait_for_pids ${all_pids};
rm ${pidfile}
else
echo "${name} is not running.";
exit 1;
fi
}
run_rc_command "$1"
|