mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-24 06:39:58 +00:00
Add --destroy flag to "pg stop" CLI command
This commit is contained in:
@@ -420,8 +420,16 @@ impl PostgresNode {
|
||||
self.pg_ctl(&["restart"])
|
||||
}
|
||||
|
||||
pub fn stop(&self) -> Result<()> {
|
||||
self.pg_ctl(&["-m", "immediate", "stop"])
|
||||
pub fn stop(&self, destroy: bool) -> Result<()> {
|
||||
self.pg_ctl(&["-m", "immediate", "stop"])?;
|
||||
if destroy {
|
||||
println!(
|
||||
"Destroying postgres data directory '{}'",
|
||||
self.pgdata().to_str().unwrap()
|
||||
);
|
||||
fs::remove_dir_all(&self.pgdata())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn connstr(&self) -> String {
|
||||
@@ -453,7 +461,7 @@ impl Drop for PostgresNode {
|
||||
// and checking it here. But let just clean datadirs on start.
|
||||
fn drop(&mut self) {
|
||||
if self.is_test {
|
||||
let _ = self.stop();
|
||||
let _ = self.stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,16 @@ fn main() -> Result<()> {
|
||||
.subcommand(SubCommand::with_name("list"))
|
||||
.subcommand(SubCommand::with_name("create").arg(timeline_arg.clone()))
|
||||
.subcommand(SubCommand::with_name("start").arg(timeline_arg.clone()))
|
||||
.subcommand(SubCommand::with_name("stop").arg(timeline_arg.clone())),
|
||||
.subcommand(
|
||||
SubCommand::with_name("stop")
|
||||
.arg(timeline_arg.clone())
|
||||
.arg(
|
||||
Arg::with_name("destroy")
|
||||
.help("Also delete data directory (now optional, should be default in future)")
|
||||
.long("destroy")
|
||||
.required(false)
|
||||
)
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("remote")
|
||||
@@ -356,12 +365,13 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
|
||||
}
|
||||
("stop", Some(sub_m)) => {
|
||||
let timeline_name = sub_m.value_of("timeline").unwrap_or("main");
|
||||
let destroy = sub_m.is_present("destroy");
|
||||
|
||||
let node = cplane
|
||||
.nodes
|
||||
.get(timeline_name)
|
||||
.ok_or_else(|| anyhow!("postgres {} is not found", timeline_name))?;
|
||||
node.stop()?;
|
||||
// TODO: destroy data directory here
|
||||
node.stop(destroy)?;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
||||
Reference in New Issue
Block a user