Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] improve detection of agent process from pid #2005

Merged
merged 1 commit into from
Nov 16, 2015

Conversation

degemer
Copy link
Member

@degemer degemer commented Oct 27, 2015

Sometimes the agent fails to restart after a "hard" reboot because the pidfile
contains the pid of a non-datadog running process, and the only check the agent
did before this commit was to check if the pid was associated with a running
process.

This commit implements a new function is_my_process which verifies on Linux if the
psutil.Process.cmdline ("command line this process has been called with") is
the good one (corresponding to the current executable). This function is used
instead of pid_exists when psutil is installed and checks the pid contained
in the pidfile, thus solving the above-mentioned problem.


I tested it on Mac (both dmg install and source install), and Debian.

@degemer degemer added this to the 5.6.0 milestone Oct 27, 2015
else:
try:
command = psutil.Process(pid).cmdline() or []
except:
Copy link

Choose a reason for hiding this comment

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

You should avoid bare Exception btw

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, my bad. It only catches psutil errors now.

@remh remh modified the milestones: 5.7.0, 5.6.0 Oct 30, 2015
Sometimes the agent fails to restart after a "hard" reboot because the pidfile
contains the pid of a non-datadog running process, and the only check the agent
did before this commit was to check if the pid was associated with a running
process.

This commit implements a new function `is_my_process` which verifies on Linux if the
`psutil.Process.cmdline` ("command line this process has been called with") is
the good one (corresponding to the current executable). This function is used
instead of `pid_exists` when `psutil` is installed and checks the pid contained
in the pidfile, thus solving the above-mentioned problem.
@degemer degemer force-pushed the quentin/pidfile-check-agent-process branch from baa4328 to ef296d5 Compare November 3, 2015 09:00
@olivielpeau
Copy link
Member

Looking great, thanks! I've also tested it on FreeBSD and SmartOS and it works like a charm.

Let's :shipit:

yannmh added a commit that referenced this pull request Nov 16, 2015
…cess

[core] improve detection of agent process from pid
@yannmh yannmh merged commit 70e8a18 into master Nov 16, 2015
@yannmh yannmh deleted the quentin/pidfile-check-agent-process branch November 16, 2015 16:21
@remh remh modified the milestones: 5.6.3, 5.7.0, 5.6.0 Nov 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants