logrotate
Choose daily or default log rotation for the Apache and Nginx logs: with
1, rotate daily and keep 7 old logs; otherwise use the system's default schedule
- Command:
/go/logrotate - Category: Web server
- Required arguments: None
- Output: None
- Log:
/var/log/go/logrotate.log - Last updated: 2026-11-20
On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also
Overview
Web server logs grow all the time. A tool called logrotate renames old logs, starts fresh ones, and deletes the oldest. /go/logrotate decides how that is done for the web server logs under /var/log:
- Daily: each log is rotated every day and 7 old copies are kept, so you have about a week of history.
- Default: your server's normal logrotate schedule applies (set in
/etc/logrotate.conf, usually weekly with a few copies kept).
The command writes the setting into the logrotate configuration of Apache and Nginx, and records the choice in GoAdmio's configuration database. It works on whichever of those configurations already exist on the server.
It doesn't rotate anything right away. The new schedule applies the next time the system runs logrotate.
Quick start
# Rotate daily, keep 7 old logs
/go/logrotate 1
# Go back to the default schedule
/go/logrotate
Syntax
/go/logrotate [1]
| Form | Behavior |
|---|---|
/go/logrotate 1 |
Daily rotation, keeping 7 old logs. |
/go/logrotate |
Default rotation. |
/go/logrotate <anything else> |
Also default rotation. The value isn't checked. |
Arguments
| Position | Argument | Required | Default | Notes |
|---|---|---|---|---|
| 1 | 1 |
No | Default rotation | Only the exact value 1 turns on daily rotation. Any other value, including 7, daily, or 0, selects default rotation. |
There are no --option value pairs.
Output
The command prints nothing. To check the result:
# The saved choice: 1 means daily, 7 means default
sqlite3 /var/lib/sqlite/config.db "select ApacheLogRotate from Config"
# The rules written for your web server
cat /etc/logrotate.d/nginx
cat /etc/logrotate.d/apache2 # Debian and Ubuntu
cat /etc/logrotate.d/httpd # AlmaLinux, Rocky, CentOS, Red Hat, Fedora
| Mode | Value saved in the database | Rules written |
|---|---|---|
| Daily | 1 |
daily and rotate 7 |
| Default | 7 |
Neither line, so the system defaults are used |
Examples
# Keep a week of daily logs
/go/logrotate 1
# Return to the system's normal schedule
/go/logrotate
# Test the new rules without changing anything (dry run)
logrotate -d /etc/logrotate.d/nginx
# Force a rotation now to see it work
logrotate -f /etc/logrotate.d/nginx
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Permission denied |
The configuration files are written by your own shell, not by sudo. |
Run the command as root. |
| A web server's rules didn't change | Its file doesn't exist. Only files that already exist are changed, and none are created. | Check that the web server is installed and that its file is in /etc/logrotate.d/ (httpd, apache2, or nginx). |
| The saved value changed but no file did | The database is always updated, whether or not any file was found. | Same as the row above. |
| Logs don't rotate right after running it | Rotation only happens when the system next runs logrotate. | Wait for the scheduled run, or test with logrotate -f. |
| Old logs aren't compressed | The rules don't turn on compression. | Add compress to /etc/logrotate.conf. This command doesn't change that file. |
| The change doesn't affect per-site logs | Only the web server's own logs under /var/log/httpd, /var/log/apache2, and /var/log/nginx are covered. |
Handle other log folders separately. |
| Your own changes to those files are gone | The files are replaced completely every time. | See Known limitations. |
Details
How it works
flowchart TD
A["logrotate [1]"] --> B{"Argument is 1?"}
B -- "Yes" --> C["Save 1 in config database"]
B -- "No" --> D["Save 7 in config database"]
C --> E["For each of httpd, apache2, nginx rule files"]
D --> E
E --> F{"File exists?"}
F -- "Yes" --> G["Overwrite it with the daily or default rules"]
F -- "No" --> H["Skip it"]
- Logs the call to
/var/log/go/logrotate.log. - Saves
1(daily) or7(default) asApacheLogRotatein theConfigtable of/var/lib/sqlite/config.db. - If
/etc/logrotate.d/httpdexists, replaces it with rules for/var/log/httpd/*log. - If
/etc/logrotate.d/apache2exists, replaces it with rules for/var/log/apache2/*log. - If
/etc/logrotate.d/nginxexists, replaces it with rules for/var/log/nginx/*.log.
The rules written
Both modes write the same settings, except that the daily mode adds the first two lines of the table.
| Setting | Daily | Default | Meaning |
|---|---|---|---|
daily |
Yes | No | Rotate every day. |
rotate 7 |
Yes | No | Keep 7 old copies. |
missingok |
Yes | Yes | No error if a log file is missing. |
notifempty |
Yes | Yes | Don't rotate an empty log. |
sharedscripts |
Yes | Yes | Run the after-rotation step once for all matching logs. |
delaycompress |
Yes | Yes | If compression is turned on, wait one cycle before compressing the newest rotated log. |
After each rotation the web server is told to reopen its logs, so it writes to the new files:
| Web server | How it reopens logs |
|---|---|
| Apache (RHEL family) | systemctl reload httpd |
| Apache (Debian and Ubuntu) | apachectl graceful, if /var/run/apache2.pid exists |
| Nginx | nginx -s reopen, if /var/run/nginx.pid exists |
Files used
| File | Purpose |
|---|---|
/etc/logrotate.d/httpd |
Apache rules on AlmaLinux, Rocky, CentOS, Red Hat, and Fedora |
/etc/logrotate.d/apache2 |
Apache rules on Debian and Ubuntu |
/etc/logrotate.d/nginx |
Nginx rules |
/var/lib/sqlite/config.db |
Stores the chosen setting (ApacheLogRotate) |
/etc/logrotate.conf |
The system defaults used by "Default" mode. Not changed by this command. |
Known limitations
- The files are replaced, not edited. Settings you or the distribution added, such as
compress,create,su, or extraprerotatesteps, are removed. - Nginx has two blocks in the script, and only the second works. Both check for
/etc/logrotate.d/nginx, so the second one always overwrites the first. The final rules use/var/log/nginx/*.logandnginx -s reopenon every system. In that block, the fallback afterelsecan never succeed, which is harmless. - The files are written without
sudo. The command works only when run as root. - No validation. Any argument other than
1means default mode. The new rules are not tested withlogrotate -d. - The database column is named for Apache, but the choice applies to Nginx too.
- Nothing is applied immediately, and the web server isn't reloaded by this command.
See also
| Command | Description |
|---|---|
clean |
Delete old backups, trash, session files, and expired mail to free up disk space |
apache |
Switch the server from Nginx to Apache, or rebuild a domain's Apache virtual host |
nginx |
Convert a GoAdmio server from Apache to Nginx |
web |
Restart or reload the active web server |
reload |
Reload PHP-FPM and the active web server |