mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
retry migration if incomplete (#2522)
This commit is contained in:
@@ -96,7 +96,18 @@ pub async fn init_postgres(datadir: impl AsRef<Path>) -> Result<(), Error> {
|
||||
|
||||
let pg_version_string = pg_version.to_string();
|
||||
let pg_version_path = db_dir.join(&pg_version_string);
|
||||
if tokio::fs::metadata(&pg_version_path).await.is_err() {
|
||||
if exists
|
||||
// maybe migrate
|
||||
{
|
||||
let incomplete_path = db_dir.join(format!("{pg_version}.migration.incomplete"));
|
||||
if tokio::fs::metadata(&incomplete_path).await.is_ok() // previous migration was incomplete
|
||||
&& tokio::fs::metadata(&pg_version_path).await.is_ok()
|
||||
{
|
||||
tokio::fs::remove_dir_all(&pg_version_path).await?;
|
||||
}
|
||||
if tokio::fs::metadata(&pg_version_path).await.is_err()
|
||||
// need to migrate
|
||||
{
|
||||
let conf_dir = Path::new("/etc/postgresql").join(pg_version.to_string());
|
||||
let conf_dir_tmp = {
|
||||
let mut tmp = conf_dir.clone();
|
||||
@@ -117,6 +128,10 @@ pub async fn init_postgres(datadir: impl AsRef<Path>) -> Result<(), Error> {
|
||||
old_version -= 1;
|
||||
let old_datadir = db_dir.join(old_version.to_string());
|
||||
if tokio::fs::metadata(&old_datadir).await.is_ok() {
|
||||
tokio::fs::File::create(&incomplete_path)
|
||||
.await?
|
||||
.sync_all()
|
||||
.await?;
|
||||
Command::new("pg_upgradecluster")
|
||||
.arg(old_version.to_string())
|
||||
.arg("main")
|
||||
@@ -135,6 +150,11 @@ pub async fn init_postgres(datadir: impl AsRef<Path>) -> Result<(), Error> {
|
||||
.invoke(ErrorKind::Filesystem)
|
||||
.await?;
|
||||
}
|
||||
tokio::fs::remove_file(&incomplete_path).await?;
|
||||
}
|
||||
if tokio::fs::metadata(&incomplete_path).await.is_ok() {
|
||||
unreachable!() // paranoia
|
||||
}
|
||||
}
|
||||
|
||||
Command::new("systemctl")
|
||||
|
||||
Reference in New Issue
Block a user