Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add force node stopping using SIGKILL in case of unsuccessful pg_ctl …#139

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
demonolock merged 1 commit intomasterfromfix-node-shutdown
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
23 changes: 21 additions & 2 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -330,8 +330,9 @@ def version(self):
"""
return self._pg_version

def _try_shutdown(self, max_attempts):
def _try_shutdown(self, max_attempts, with_force=False):
attempts = 0
node_pid = self.pid

# try stopping server N times
while attempts < max_attempts:
Expand All@@ -341,12 +342,30 @@ def _try_shutdown(self, max_attempts):
except ExecUtilException:
pass # one more time
except Exception:
# TODO: probably should kill stray instance
eprint('cannot stop node {}'.format(self.name))
break

attempts += 1

# If force stopping is enabled and PID is valid
if with_force and node_pid != 0:
# If we couldn't stop the node
p_status_output = self.os_ops.exec_command(cmd=f'ps -p {node_pid}', shell=True).decode('utf-8')
if self.status() != NodeStatus.Stopped and p_status_output and str(node_pid) in p_status_output:
try:
eprint(f'Force stopping node {self.name} with PID {node_pid}')
self.os_ops.kill(node_pid, signal.SIGKILL, expect_error=False)
except Exception:
# The node has already stopped
pass

# Check that node stopped
p_status_output = self.os_ops.exec_command(f'ps -p {node_pid}', shell=True, expect_error=True).decode('utf-8')
if p_status_output and str(node_pid) in p_status_output:
eprint(f'Failed to stop node {self.name}.')
else:
eprint(f'Node {self.name} has been stopped successfully.')

def _assign_master(self, master):
"""NOTE: this is a private method!"""

Expand Down
4 changes: 2 additions & 2 deletionstestgres/operations/local_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -293,10 +293,10 @@ def remove_file(self, filename):
return os.remove(filename)

# Processes control
def kill(self, pid, signal):
def kill(self, pid, signal, expect_error=False):
# Kill the process
cmd = "kill -{} {}".format(signal, pid)
return self.exec_command(cmd)
return self.exec_command(cmd, expect_error=expect_error)

def get_pid(self):
# Get current process id
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp