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