mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-04 12:02:55 +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"])
|
self.pg_ctl(&["restart"])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&self) -> Result<()> {
|
pub fn stop(&self, destroy: bool) -> Result<()> {
|
||||||
self.pg_ctl(&["-m", "immediate", "stop"])
|
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 {
|
pub fn connstr(&self) -> String {
|
||||||
@@ -453,7 +461,7 @@ impl Drop for PostgresNode {
|
|||||||
// and checking it here. But let just clean datadirs on start.
|
// and checking it here. But let just clean datadirs on start.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.is_test {
|
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("list"))
|
||||||
.subcommand(SubCommand::with_name("create").arg(timeline_arg.clone()))
|
.subcommand(SubCommand::with_name("create").arg(timeline_arg.clone()))
|
||||||
.subcommand(SubCommand::with_name("start").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(
|
||||||
SubCommand::with_name("remote")
|
SubCommand::with_name("remote")
|
||||||
@@ -356,12 +365,13 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
|
|||||||
}
|
}
|
||||||
("stop", Some(sub_m)) => {
|
("stop", Some(sub_m)) => {
|
||||||
let timeline_name = sub_m.value_of("timeline").unwrap_or("main");
|
let timeline_name = sub_m.value_of("timeline").unwrap_or("main");
|
||||||
|
let destroy = sub_m.is_present("destroy");
|
||||||
|
|
||||||
let node = cplane
|
let node = cplane
|
||||||
.nodes
|
.nodes
|
||||||
.get(timeline_name)
|
.get(timeline_name)
|
||||||
.ok_or_else(|| anyhow!("postgres {} is not found", timeline_name))?;
|
.ok_or_else(|| anyhow!("postgres {} is not found", timeline_name))?;
|
||||||
node.stop()?;
|
node.stop(destroy)?;
|
||||||
// TODO: destroy data directory here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user