Skip to content

fix: guard Plex finish kill when no PID is found#169

Open
OmarB97 wants to merge 2 commits into
plexinc:masterfrom
OmarB97:fix/guard-empty-finish-pids
Open

fix: guard Plex finish kill when no PID is found#169
OmarB97 wants to merge 2 commits into
plexinc:masterfrom
OmarB97:fix/guard-empty-finish-pids

Conversation

@OmarB97
Copy link
Copy Markdown

@OmarB97 OmarB97 commented May 18, 2026

Summary

Guard the initial kill -15 $pids call in root/etc/services.d/plex/finish so it only runs when a Plex Media Server PID was found.

Why

If Plex has already exited by the time the finish script runs, pids is empty and the shell executes kill -15 without a PID. That prints the kill: usage... message during container shutdown. The later SIGKILL block already guards against an empty PID list, so this makes the TERM path match the existing stuck-process path.

Validation

  • bash -n root/etc/services.d/plex/finish
  • Reproduced in a downstream Unraid container using plexinc/pms-docker:latest, where the shutdown logs showed kill: usage...; applying the guard removed that message while Plex restarted healthy.

@cilindrox cilindrox self-assigned this May 19, 2026
@cilindrox cilindrox requested a review from MarshallAsch May 19, 2026 19:41
Copy link
Copy Markdown
Member

@cilindrox cilindrox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @OmarB97 - some comments regarding improving the globbing/splitting of the unquoted vars.

Comment thread root/etc/services.d/plex/finish Outdated
pids="$(ps -ef | grep 'Plex Media Server' | grep -v grep | awk '{print $2}')"
kill -15 $pids
if [ "$pids" != "" ]; then
kill -15 $pids
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we quote the $pids var for safety here and on L18 below?

Suggested change
kill -15 $pids
kill -15 "$pids"

@cilindrox cilindrox changed the title Guard Plex finish kill when no PID is found fix: guard Plex finish kill when no PID is found May 22, 2026
@OmarB97
Copy link
Copy Markdown
Author

OmarB97 commented May 22, 2026

Thanks @OmarB97 - some comments regarding improving the globbing/splitting of the unquoted vars.

Thanks, pushed c506e49 to address this.

I quoted the PID handling, but used a small kill_pids helper instead of calling kill -15 "$pids" directly because the command substitution can return multiple newline-separated PIDs. Quoting the whole value in a direct kill call would turn multiple PIDs into one argument; the helper reads each PID line and calls kill "$signal" "$pid", so each PID is quoted safely while preserving multi-process behavior.

I applied the same path for both the SIGTERM and SIGKILL calls and checked it with bash -n plus a stubbed multi-PID helper test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants