Skip to content

Conversation

@s3lph
Copy link
Contributor

@s3lph s3lph commented Feb 9, 2024

When daliserver writes a logfile, the logfile is never rotated and keeps on growing. On our system it has now reached ~6GB. This ended up filling the disk of our backup server, as we do daily backups with file-level deduplication: As the file was constantly appended to, it was never the same file, and every incremental backup contained a full copy of this file.

While trying to set up a logrotate config, I realized that daliserver did not yet contain any logic for re-opening the logfile, which is requried for logrotate to work. So this PR contains two things:

  • A logrotate config for the Debian package that signals the daliserver process with SIGHUP after log rotation
  • A signal handler for SIGHUP that re-opens the logfile by name.

Copy link
Owner

@onitake onitake left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Aside from my comments, I'd like to point out that daliserver also prints fatal and error messages to STDERR and all other messages to STDOUT.
If you're running daliserver in something that captures STDOUT/STDERR (such as systemd+journald), there's no need to enable the log file or syslog at all. I'd strongly recommend to use this instead.

@s3lph
Copy link
Contributor Author

s3lph commented Feb 9, 2024

I'd like to point out that daliserver also prints fatal and error messages to STDERR and all other messages to STDOUT. If you're running daliserver in something that captures STDOUT/STDERR (such as systemd+journald), there's no need to enable the log file or syslog at all. I'd strongly recommend to use this instead.

Nevertheless, the default behavior of the daliserver Debian package still is to use an init script, which starts dalisever with -f /var/log/daliserver.log. As long as this is the default behavior, it should also support log rotation.

I do however also agree that systemd+journald would be the better way forward, but that's a change I'd like to see in the daliserver Debian package itself, rather than manually installing a custom systemd unit alongside the package.

@s3lph s3lph requested a review from onitake February 9, 2024 18:07
@onitake
Copy link
Owner

onitake commented Feb 10, 2024

Nevertheless, the default behavior of the daliserver Debian package still is to use an init script, which starts dalisever with -f /var/log/daliserver.log. As long as this is the default behavior, it should also support log rotation.

I do however also agree that systemd+journald would be the better way forward, but that's a change I'd like to see in the daliserver Debian package itself, rather than manually installing a custom systemd unit alongside the package.

It's high time I make that switch, then. 🙂

Sorry, dear Devuan users...

@s3lph s3lph requested a review from onitake February 11, 2024 15:10
@s3lph
Copy link
Contributor Author

s3lph commented Feb 11, 2024

Sorry, dear Devuan users...

If you would want to make Devuan users happy, you could ship both /etc/init.d/daliserver and /lib/systemd/system/daliserver.service. Systemd won't use sysv-generator to generate a unit if one with the same name already exists. So if running under systemd, the native unit is used, whereas if running under an init system that uses /etc/init.d scripts the script is used.

@onitake
Copy link
Owner

onitake commented Feb 11, 2024

If you would want to make Devuan users happy, you could ship both /etc/init.d/daliserver and /lib/systemd/system/daliserver.service. Systemd won't use sysv-generator to generate a unit if one with the same name already exists. So if running under systemd, the native unit is used, whereas if running under an init system that uses /etc/init.d scripts the script is used.

Please take a look: #28

Copy link
Owner

@onitake onitake left a comment

Choose a reason for hiding this comment

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

With the changed logic, part of https://github.com/onitake/daliserver/pull/27/files#diff-f7dfb3ca741707d1a361d8cdd6f75f05bc99811daac01afaa258f43d4b71e4f6R165-R174 is now redundant and can be simplified. Please remove the extra fclose(), and fold the assignment to fp_logfile into the fopen() line. There's no need for an extra temp var.

@s3lph s3lph requested a review from onitake February 11, 2024 22:39
@s3lph
Copy link
Contributor Author

s3lph commented Feb 11, 2024

Please remove the extra fclose(), and fold the assignment to fp_logfile into the fopen() line. There's no need for an extra temp var.

Done.

Copy link
Owner

@onitake onitake left a comment

Choose a reason for hiding this comment

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

That looks good, thank you.

@onitake onitake merged commit 65dd2c7 into onitake:master Feb 11, 2024
@s3lph s3lph deleted the feat-logrotate branch February 11, 2024 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants