-
Notifications
You must be signed in to change notification settings - Fork 625
Set correct permissions on the specified log directory #4226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when this is merged we
- always run the func to set collector params (but we don't set anything if collector is not on)
- create/set perms on the log dir depending on the log dir setting (which may be a relative path, e.g., when default is used)
- handle relative paths in our path func
internal/postgres/config.go
Outdated
`(` + shell.MakeDirectories(DataDirectory(cluster), logDir) + `) ||`, | ||
// FIXME: This error prints the wrong directory when logDir is relative (the default). | ||
`halt "$(permissions ` + logDir + ` ||:)"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The challenge here is that initdb
is only happy populating an empty data directory.
It is happy with this:
drwxrwxr-x. 2 postgres postgres Jul 31 17:04 pgdata/pg16
It is not happy with this:
drwxrwxr-x. 3 postgres postgres Jul 31 17:04 pgdata/pg16
drwxrwxr-x. 2 postgres postgres Jul 31 17:04 pgdata/pg16/log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is now a time to pull the thread on moving logs out of pgdata completely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much "almost." I'll think about this tomorrow.
5756ad3
to
eff8b68
Compare
eff8b68
to
354a00d
Compare
354a00d
to
9642615
Compare
This one is ready again. The parameter is still hard-coded when the gate is on, but configurable otherwise. The next PR after this will be validation and more configurability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always a little iffy when there's this much bash-in-go, but LGTM
`else (halt Permissions!); fi ||`, | ||
`halt "$(permissions "${tablespace_dir}" ||:)"`, | ||
}, "\n") | ||
mkdirs := make([]string, 0, 9+len(instance.TablespaceVolumes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something -- why 9+?
I see:
- postgres_data_directory
- tablespaces (the + in that make)
- logdir
- PatroniPGDataLogPath
- PGBackRestPGDataLogPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel weird when doing this. I have internalize "if you know the size before appending, use make" but I'm not finding a source for that.
I know that append
one at a time doubles capacity, so from 0 → 9 is five allocations... But who cares, right? gah.
internal/postgres/config.go
Outdated
if path.IsAbs(logDir) && !strings.HasPrefix(logDir, dataDir) { | ||
mkdirs = append(mkdirs, | ||
`(`+shell.MakeDirectories(dataMountPath, logDir)+`) ||`, | ||
`halt "$(permissions `+shell.QuoteWord(logDir)+` ||:)"`, | ||
) | ||
} else { | ||
mkdirs = append(mkdirs, | ||
`[[ ! -f `+shell.QuoteWord(path.Join(dataDir, "PG_VERSION"))+` ]] ||`, | ||
`(`+shell.MakeDirectories(dataDir, logDir)+`) ||`, | ||
`halt "$(permissions `+shell.QuoteWord(path.Join(dataDir, logDir))+` ||:)"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might need you to walk me through this, but
ll 383-385: if the logdir is absolute and isn't prefixed with datadir, we MakeDirectories with dataMountPath as the base -- but since the logdir abs path won't have the base as part of the path, MakeDirectories kinda ignores the base path/the output will not have any reference to that.
That is: if logdir is outside the datadir, create it with the correct permissions. (Passing "dataDir" into MakeDirectories was throwing me.)
ll 389-392:
- we have reached this because either the logdir path is relative or includes the datadir
- if the PG_VERSION file exists (and therefore initdb or similar has run?), we can then create our logdir without worrying about it interfering with initdb
Am I missing anything?
So if the version doesn't exist, we haven't run initdb/bootstrap; and then we'll run that at some time, and then re-run this startup command at some time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ll 383-385: if the logdir is absolute and isn't prefixed with datadir, we MakeDirectories with dataMountPath as the base -- but since the logdir abs path won't have the base as part of the path, MakeDirectories kinda ignores the base path/the output will not have any reference to that.
I'm not following the back half of this. What does base as part of the path
mean?
We don't pay attention to which volume the directory is on, true. If the absolute path is /volumes
then it does mkdir -p
and chmod
of one directory.
That is: if logdir is outside the datadir, create it with the correct permissions. (Passing "dataDir" into MakeDirectories was throwing me.)
These lines pass dataMountPath
.
Am I missing anything?
So if the version doesn't exist, we haven't run initdb/bootstrap; and then we'll run that at some time, and then re-run this startup command at some time?
That's right, and at some time
facts bug me, but all I've got is startup and bash atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, some of what I said was wrong, partly because I was mixing up /pgdata
and /pgdata/pg##
So:
- if logdir is not in datadir, we create the paths for logdir. And that's true where the log dir is in the pgdata dir or elsewhere. (The real distinction is that the logdir cannot be in
/pgdata/pg##
.) - and if the logdir is in datadir... yeah, "at some time" is what we've got right now.
The commands for these were intentionally similar, and now they are the same and documented together. Issue: PGO-2558
This function needed defined behavior for relative paths. For example, the default log directory for Postgres is just "log" which it interprets relative to the data directory. Issue: PGO-2558
Controllers ignored the specified "log_directory" when preparing directories for Postgres. This parameter can be specified when the OpenTelemetryLogs gate is disabled. A relative path of more than one directory continues to fail during bootstrap. This does not change what happens when the OpenTelemetryLogs gate is enabled. In that case, controllers override the spec with their own value and prepare that directory. Issue: PGO-2558
9642615
to
3ac69fe
Compare
Checklist:
Type of Changes:
What is the current behavior (link to any open issues here)?
Controllers ignore the specified "log_directory" when preparing directories for Postgres. This parameter can be specified when the OpenTelemetryLogs gate is disabled.
What is the new behavior (if this is a feature change)?
Controllers create the logs directory before starting Postgres.
Other Information:
Issue: PGO-2558