Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions root/etc/services.d/plex/finish
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@

echo "Stopping Plex Media Server."

kill_pids() {
local signal="$1"
local pids="$2"
local pid

while IFS= read -r pid; do
if [ "$pid" != "" ]; then
kill "$signal" "$pid"
fi
done <<< "$pids"
}

# Ask nicely
pids="$(ps -ef | grep 'Plex Media Server' | grep -v grep | awk '{print $2}')"
kill -15 $pids
if [ "$pids" != "" ]; then
kill_pids -15 "$pids"
fi

sleep 5

# Stuck
pids="$(ps -ef | grep /usr/lib/plexmediaserver | grep -v grep | awk '{print $2}')"

if [ "$pids" != "" ]; then
kill -9 $pids
kill_pids -9 "$pids"
sleep 2
fi