From 710fe02d0b7ab1c7b56cf86b33ab53752c510958 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 26 Oct 2021 17:54:20 +0300 Subject: [PATCH] Return success on 'zenith stop' if the page server is already stopped. --- control_plane/src/storage.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/control_plane/src/storage.rs b/control_plane/src/storage.rs index e89620555b..92de4752dc 100644 --- a/control_plane/src/storage.rs +++ b/control_plane/src/storage.rs @@ -198,9 +198,21 @@ impl PageServerNode { bail!("pageserver failed to start in {} seconds", RETRIES); } + /// + /// Stop the server. + /// + /// If 'immediate' is true, we use SIGQUIT, killing the process immediately. + /// Otherwise we use SIGTERM, triggering a clean shutdown + /// + /// If the page server is not running, returns success + /// pub fn stop(&self, immediate: bool) -> anyhow::Result<()> { - let pid = read_pidfile(&self.pid_file())?; - let pid = Pid::from_raw(pid); + let pid_file = self.pid_file(); + if !pid_file.exists() { + println!("Pageserver is already stopped"); + return Ok(()) + } + let pid = Pid::from_raw(read_pidfile(&pid_file)?); if immediate { println!("Stop pageserver immediately"); if kill(pid, Signal::SIGQUIT).is_err() {