Skip to content

[Contrib] Logrotate #9866

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions contrib/logrotate/gitea.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Rotate Gitea logs
# Replace path to logs if you use different working directory

/var/lib/gitea/log/*.log, /var/lib/gitea/log/hooks/*.log {
daily
missingok
rotate 7
compress
notifempty
create 0660 git git
sharedscripts
postrotate
systemctl restart gitea.service
Copy link
Member

@silverwind silverwind Jan 20, 2020

Choose a reason for hiding this comment

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

This restart is unnecessary, it's probably enough to enable copytruncate and remove both the postrotate and create options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No no no,

Many application use restart-after-logrotate technique, and Gitea should too.

Copy link
Member

@silverwind silverwind Jan 21, 2020

Choose a reason for hiding this comment

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

That is a recipe for disaster. What if the application fails to restart? You certainly don't want logrotate to be able to cause a service outage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@silverwind hmm... logrotate should be blamed

endscript
}
32 changes: 32 additions & 0 deletions docs/content/doc/usage/logrotate-setup.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
date: "2020-01-19"
title: "Usage: Logrotate setup"
slug: "logrotate-setup"
weight: 12
toc: true
draft: false
menu:
sidebar:
parent: "usage"
name: "Logrotate setup"
weight: 12
identifier: "logrotate-setup"
---

## `logrotate` Setup

The `logrotate` utility automates log rotation. This is especially useful for larger Gitea instance with many users and repositories, where Gitea logs can grow quickly.

To use `logrotate`, install the package first. Make sure to set `LOG_ROTATE` and `DAILY_ROTATE` on your `app.ini` to `false`, as `logrotate` will do the job instead of built-in rotation. See also [Config Cheat Sheet](https://docs.gitea.io/en-us/config-cheat-sheet/#file-log-mode-log-file-log-file-or-mode-file).

Then copy [sample configuration](https://github.com/go-gitea/gitea/blob/master/contrib/logrotate/gitea.conf) to `/etc/logrotate.conf.d` and edit it to fit your Gitea instance.

As root, test the configuration by:

```
logrotate /etc/logrotate.conf --debug
```

Fix any errors if found.

Please note that `logrotate` doesn't have restart command as its next rotation job includes any new configurations.