Skip to content
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

scripts: small refactorings #2485

Merged
merged 24 commits into from Mar 17, 2022
Merged

Conversation

georglauterbach
Copy link
Member

@georglauterbach georglauterbach commented Mar 14, 2022

Description

The commit descriptions are somewhat detailed. It basically boils down to:

  1. Cron scripts are now added with HEREDOCs
  2. Minor style adjustments

Type of change

  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

This was not actually needed (and not a good idea either - ask me how I
know: "warning: error loading certificate chain: key at index 1 in
/etc/dms/tls/key does not match the certificate" in my log due to my
custom Postfix `main.cf`). It turns out the _setup_ssl call would just
set the exact same files again, which does absolutely nothing (except
messing with custom configurations...).

I therefore removed this portion again. I left the checksum generation
for the files in the `_monitored_files_checksums` function because
restarting Postfix is desired.

Removing the test is also fine because

1. it was flawed to begin with
2. the changedetector functionality of detecting file changes is already
   tested in another test
We now use HEREDOCs to add new files to cron. This is, after testing the
alternatives of copying files, the best solution in my opinion. We have
munite control over the contents (especially when the content of the
cron files depends on environment variables). Moreover, we need not
adjust the `Dockerfile`.
The job could fail if no new fresh updates are available. This is
however not a reason to receive a new email telling me the job failed.
This commit provides a solution.
After reading the docs on the exit code, we can do better.
This is a bigger commit - it reworks the whole log functionality. The
old one was confusing and not adhering to common standards, i.e. not
following convention over configuration. With this commit, we use the
common standard log levels

4. TRACE
3. DEBUG
2. INFO
1. WARN
0. ERROR

to better provide the information to users and maintainers. With this
changes, `DMS_DEBUG` was removed and `LOG_LEVEL` introduced. `DMS_DEBUG`
is not usefule anymore (obviously), and replaced by the new `LOG_LEVEL`,
which defaults to `info`.

All scripts and tests were adjusted to use the new format. There is a
special log level (`always`) which is used only by `start-mailserver.sh`
to show the welcome messages independent of the log level.

I took some care when converting the "old" log levels. With this rework,
it should be easier to identify problems in logs and provide users with
a clear and straight forward log level variable which is easy to
understand.

This is not actually a breaking change, but I thought it is fitting for
the next major release `v11`.
We need not write up to loggers, sourcing the already present one is
fine. This simplifies the whole script.
@georglauterbach georglauterbach added priority/high area/scripts kind/improvement Improve an existing feature, configuration file or the documentation kind/update Update an existing feature, configuration file or the documentation labels Mar 14, 2022
@georglauterbach georglauterbach added this to the v11.0.0 milestone Mar 14, 2022
@georglauterbach georglauterbach self-assigned this Mar 14, 2022
@github-actions
Copy link
Contributor

Documentation preview for this PR is ready! 🎉

Built with commit: 75531fd

Copy link
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR overall! 👍

Feedback: Personal opinion - Not a fan of HEREDOC

Cron jobs to heredocs (relevant commit with commit message for context) is not something I'm fond of personally.

I prefer external files instead of embedded/inlined, ENV as a convenience isn't sufficient for me. We already write ENV to a file for other scripts to read and utilize. I'd rather cron jobs we add are all in a common location from a maintenance perspective, but I understand if the majority of maintainers prefer the heredoc approach instead and have no interest in fighting that decision.


Feedback: Log changes could have been covered in a separate PR

The log level change is rather large and seems it would have suited it's own PR rather than mixed in with the other changes covered (relevant commit covering the bulk of logging changes). I understand it's mostly isolated to the linked commit, but for review purposes separate PRs would have been nicer 😅

.github/ISSUE_TEMPLATE/bug_report.yml Outdated Show resolved Hide resolved
docs/content/config/environment.md Outdated Show resolved Hide resolved
docs/content/contributing/issues-and-pull-requests.md Outdated Show resolved Hide resolved
mailserver.env Outdated Show resolved Hide resolved
target/scripts/check-for-changes.sh Outdated Show resolved Hide resolved
test/linting/lint.sh Outdated Show resolved Hide resolved
test/mail_special_use_folders.bats Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
@georglauterbach georglauterbach mentioned this pull request Mar 15, 2022
8 tasks
@georglauterbach georglauterbach changed the title scripts: log update and script changes scripts: small refactorings Mar 15, 2022
@georglauterbach
Copy link
Member Author

Good PR overall! +1

Thanks!


All resolved :D


Feedback: Personal opinion - Not a fan of HEREDOC

Cron jobs to heredocs (relevant commit with commit message for context) is not something I'm fond of personally.

I prefer external files instead of embedded/inlined, ENV as a convenience isn't sufficient for me. We already write ENV to a file for other scripts to read and utilize. I'd rather cron jobs we add are all in a common location from a maintenance perspective, but I understand if the majority of maintainers prefer the heredoc approach instead and have no interest in fighting that decision.

I have to admit I disagree, obviously (otherwise I wouldn't have done it). I first tried your approach to see how it goes, but then I noticed that it is way more work to handle these scripts if they are not "inlined" into setup-stack.sh (with a HEREDOC). Moreover, we only actually have two cron scripts that are added. From experience with this project and writing many many lines of code, I would strongly advise against dedicated scripts.


Feedback: Log changes could have been covered in a separate PR

I agree. Therefore, I opened #2486.

target/scripts/helpers/error.sh Outdated Show resolved Hide resolved
target/scripts/helpers/error.sh Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
target/scripts/helpers/error.sh Outdated Show resolved Hide resolved
target/scripts/helpers/error.sh Outdated Show resolved Hide resolved
.github/ISSUE_TEMPLATE/bug_report.yml Outdated Show resolved Hide resolved
@casperklein
Copy link
Member

Feedback: Personal opinion - Not a fan of HEREDOC

Depends on the use-case IMO. Regarding the usage for our cron jobs, I think this is a good solution.

polarathene
polarathene previously approved these changes Mar 16, 2022
Copy link
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly some changes you still want to make, otherwise LGTM 👍

target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
test/mail_ssl_manual.bats Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Show resolved Hide resolved
@georglauterbach
Copy link
Member Author

Thanks for the good feedback, very much appreciated!

polarathene
polarathene previously approved these changes Mar 16, 2022
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
target/scripts/startup/setup-stack.sh Outdated Show resolved Hide resolved
Co-authored-by: Casper <casperklein@users.noreply.github.com>
@georglauterbach georglauterbach merged commit 321ae74 into master Mar 17, 2022
@georglauterbach georglauterbach deleted the fix/small-misc-script-enhancements branch March 17, 2022 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scripts kind/improvement Improve an existing feature, configuration file or the documentation kind/update Update an existing feature, configuration file or the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants