-
Notifications
You must be signed in to change notification settings - Fork 0
/
plexmediaserver-lib.pl
executable file
·133 lines (118 loc) · 2.83 KB
/
plexmediaserver-lib.pl
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/local/bin/perl
# plexmediaserver-lib.pl
# Common functions for the Plex daemon
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
# get_plex_version()
sub get_plex_version
{
my $version = &backquote_command("$config{'version_cmd'}");
}
# get_plex_stats()
sub get_plex_stats
{
my $plexstatus = &backquote_command('pgrep "Plex Media"');
}
# get_dlna_stats()
sub get_dlna_stats
{
my $dlnastatus = &backquote_command('pgrep "Plex DLNA"');
}
# get_tuner_stats()
sub get_tuner_stats
{
my $tunerstatus = &backquote_command('pgrep "Plex Tuner"');
}
# get_stat_icons()
sub get_stat_icons
{
my $okicon = "/images/ok.gif";
}
# get_local_ipaddress()
sub get_local_ipaddress
{
my $ipaddress = &to_ipaddress(get_system_hostname());
}
# Kill Plex related processes.
sub kill_plex_procs
{
my $killplexprocs = &backquote_command('pkill -U plex');
}
# restart_plex()
# Re-starts the Plex server, and returns an error message on failure or
# undef on success.
sub restart_plex
{
if ($config{'restart_cmd'}) {
local $out = &backquote_command("$config{'restart_cmd'} 2>&1 </dev/null");
return "<pre>$out</pre>" if ($?);
# Wait few secs for Plex services to populate.
sleep (3);
} else {
# Just kill plex related processes and start Plex.
&kill_plex_procs();
if ($config{'start_cmd'}) {
$out = &backquote_logged("$config{'start_cmd'} 2>&1 </dev/null");
if ($?) { return "<pre>$out</pre>"; }
# Wait few secs for Plex services to populate.
sleep (3);
}
}
return undef;
}
# stop_plex()
# Always use stop command whenever possible, otherwise
# try to kill the Plex server, returns an error message on failure or
# undef on success.
sub stop_plex
{
if ($config{'stop_cmd'}) {
local $out = &backquote_command("$config{'stop_cmd'} 2>&1 </dev/null");
return "<pre>$out</pre>" if ($?);
} else {
# Just kill Plex related processes.
&kill_plex_procs();
}
return undef;
}
# start_plex()
# Attempts to start the Plex server, returning undef on success or an error
# message on failure.
sub start_plex
{
# Remove PID file if invalid.
if (-f $config{'pid_file'} && !&check_pid_file($config{'pid_file'})) {
&unlink_file($config{'pid_file'});
}
if ($config{'start_cmd'}) {
$out = &backquote_logged("$config{'start_cmd'} 2>&1 </dev/null");
if ($?) { return "<pre>$out</pre>"; }
# Wait few secs for Plex services to populate.
sleep (3);
} else {
$out = &backquote_logged("$config{'plex_path'} 2>&1 </dev/null");
if ($?) { return "<pre>$out</pre>"; }
}
return undef;
}
# get_pid_file()
# Returns the Plex server PID file.
sub get_pid_file
{
$pidfile = $config{'pid_file'};
return $pidfile;
}
# get_plex_pid()
# Returns the PID of the running Plex process.
sub get_plex_pid
{
local $file = &get_pid_file();
if ($file) {
return &check_pid_file($file);
} else {
local ($rv) = &find_byname("Plex Media");
return $rv;
}
}
1;