|
8 | 8 | "context"
|
9 | 9 | "fmt"
|
10 | 10 | "math"
|
| 11 | + "path" |
11 | 12 | "strings"
|
12 | 13 |
|
13 | 14 | corev1 "k8s.io/api/core/v1"
|
@@ -315,9 +316,28 @@ func startupCommand(
|
315 | 316 | parameters *ParameterSet,
|
316 | 317 | ) []string {
|
317 | 318 | version := fmt.Sprint(cluster.Spec.PostgresVersion)
|
318 |
| - logDir := parameters.Value("log_directory") |
| 319 | + dataDir := DataDirectory(cluster) |
319 | 320 | walDir := WALDirectory(cluster, instance)
|
320 | 321 |
|
| 322 | + // TODO: describe this? |
| 323 | + mkdirs := make([]string, 0, 6) |
| 324 | + mkdir := func(b, p string) { |
| 325 | + if path.IsAbs(p) { |
| 326 | + p = path.Clean(p) |
| 327 | + } else { |
| 328 | + p = path.Join(dataDir, p) |
| 329 | + } |
| 330 | + |
| 331 | + // Create directories unless they are in the empty Postgres data directory. |
| 332 | + mkdirs = append(mkdirs, |
| 333 | + `[[ `+shell.QuoteWord(p)+` != "${postgres_data_directory}"* || -f "${postgres_data_directory}/PG_VERSION" ]] &&`, |
| 334 | + `{ (`+shell.MakeDirectories(b, p)+`) || halt "$(permissions `+shell.QuoteWord(p)+` ||:)"; }`, |
| 335 | + ) |
| 336 | + } |
| 337 | + mkdir(dataMountPath, naming.PGBackRestPGDataLogPath) |
| 338 | + mkdir(dataMountPath, naming.PatroniPGDataLogPath) |
| 339 | + mkdir(dataDir, parameters.Value("log_directory")) |
| 340 | + |
321 | 341 | // If the user requests tablespaces, we want to make sure the directories exist with the
|
322 | 342 | // correct owner and permissions.
|
323 | 343 | tablespaceCmd := ""
|
@@ -445,14 +465,7 @@ chmod +x /tmp/pg_rewind_tde.sh
|
445 | 465 | `else (halt Permissions!); fi ||`,
|
446 | 466 | `halt "$(permissions "${postgres_data_directory}" ||:)"`,
|
447 | 467 |
|
448 |
| - // Create log directories. |
449 |
| - `(` + shell.MakeDirectories(dataMountPath, naming.PGBackRestPGDataLogPath) + `) ||`, |
450 |
| - `halt "$(permissions ` + naming.PGBackRestPGDataLogPath + ` ||:)"`, |
451 |
| - `(` + shell.MakeDirectories(dataMountPath, naming.PatroniPGDataLogPath) + `) ||`, |
452 |
| - `halt "$(permissions ` + naming.PatroniPGDataLogPath + ` ||:)"`, |
453 |
| - `(` + shell.MakeDirectories(DataDirectory(cluster), logDir) + `) ||`, |
454 |
| - // FIXME: This error prints the wrong directory when logDir is relative (the default). |
455 |
| - `halt "$(permissions ` + logDir + ` ||:)"`, |
| 468 | + strings.Join(mkdirs, "\n"), |
456 | 469 |
|
457 | 470 | // Copy replication client certificate files
|
458 | 471 | // from the /pgconf/tls/replication directory to the /tmp/replication directory in order
|
|
0 commit comments