Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 541812 - www-server/apache-2.2 logrotate file does not support systemd
Summary: www-server/apache-2.2 logrotate file does not support systemd
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Lars Wendler (Polynomial-C) (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-01 15:10 UTC by Liam Dennehy
Modified: 2017-04-26 08:50 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Init-system-aware apache reload script (OpenRC/systemd) (apachereload,232 bytes, text/plain)
2015-03-01 15:18 UTC, Liam Dennehy
Details
Replace openrc reload with init-system-aware reload script (file_541812.txt,101 bytes, patch)
2015-03-01 15:22 UTC, Liam Dennehy
Details | Diff
/etc/logrotate.d/apache2 replace openrc reload with init-aware script (file_541812.txt,101 bytes, patch)
2015-03-01 15:23 UTC, Liam Dennehy
Details | Diff
OpenRC/Systemd detection and reload postrotate (file_541812.txt,352 bytes, text/plain)
2015-03-06 12:19 UTC, Liam Dennehy
Details
OpenRC/Systemd detection and reload postrotate (file_541812.txt,375 bytes, text/plain)
2015-03-09 15:23 UTC, Liam Dennehy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Liam Dennehy 2015-03-01 15:10:15 UTC
www-servers/apache-2.2.29 logrotate file is not aware of systemd, assuming daemons are controlled by OpenRC. this results in a failure to log to fresh log files in /var/log/apache2 after old files are rotated.

Reproducible: Always

Steps to Reproduce:
1. Wait for cron timer to launch (daily) on systemd-controlled system
2. existing log files are zipped and named appropriately
3. Empty log files are created
4. "systemctl reload apache2" causes log events to be written to new files
Actual Results:  
New log events do not write to new log files (remain zero-length)
Assume old log files are still present but deleted and being written to since apache process(es) still have open write handles

Expected Results:  
systemd should reload apache2
Events written to new log files
Comment 1 Liam Dennehy 2015-03-01 15:18:39 UTC
Created attachment 397782 [details]
Init-system-aware apache reload script (OpenRC/systemd)

I cannot find a simple method to detect either OpenRC or systemd-controlled system, but this method seems to work well. Strangely I have /run/openrc present on one systemd system, but not another, hence the double detection.
Comment 2 Liam Dennehy 2015-03-01 15:22:49 UTC
Created attachment 397784 [details, diff]
Replace openrc reload with init-system-aware reload script
Comment 3 Liam Dennehy 2015-03-01 15:23:59 UTC
Created attachment 397786 [details, diff]
/etc/logrotate.d/apache2 replace openrc reload with init-aware script
Comment 4 Mike Gilbert gentoo-dev 2015-03-04 23:42:59 UTC
For reference, the canonical way to check for systemd is this:

[ -d /run/systemd/system ]

I don't know the best way to check for openrc, but I don't think "[ $(ls /run/openrc/started | wc -l) -gt 0 ]" is it.

Regardless, I would recommend changing it to call apache or apachectl directly, bypassing openrc and systemd entirely.
Comment 5 Liam Dennehy 2015-03-06 12:19:39 UTC
Created attachment 398232 [details]
OpenRC/Systemd detection and reload postrotate
Comment 6 Liam Dennehy 2015-03-06 12:20:45 UTC
Comment on attachment 397782 [details]
Init-system-aware apache reload script (OpenRC/systemd)

No need for external script, five lines in the logrotate config will do.
Comment 7 Liam Dennehy 2015-03-06 12:22:19 UTC
Thanks for the feedback Mike.

I would have thought (as a newbie) that the init-system should be the point of all contact with services rather than interacting with daemons directly?

That in mind, a simple test [ -e /run/openrc/started/apache ] will only hit if apache2 is started by OpenRC; if the test fails then "/etc/init.d/apache2 reload" is useless since OpenRC is not present or apache2 is not started via OpenRC.

If [ -e /run/systemd/system ] then a systemctl reload apache2 will be appropriate, it does nothing if the service is not started.

This doesn't remove functionality, the original logrotate file uses OpenRC anyway, just falsely assuming it's always used so this hopefully assists systemd users.
Comment 8 Mike Gilbert gentoo-dev 2015-03-06 13:21:00 UTC
(In reply to Liam Dennehy from comment #7)
> I would have thought (as a newbie) that the init-system should be the point
> of all contact with services rather than interacting with daemons directly?

The user may have started apache without using any init system at all. I see no reason to call openrc or systemd just to get apache to re-open its log files.

If you insist in doing so despite this advice, please do not hard-code the path to systemctl. Just do "systemctl reload foo.service" and let logrotate find it in PATH.
Comment 9 Richard Freeman gentoo-dev 2015-03-06 13:33:26 UTC
(In reply to Liam Dennehy from comment #7)
> 
> I would have thought (as a newbie) that the init-system should be the point
> of all contact with services rather than interacting with daemons directly?
> 

I would tend to agree.  This logic would then be potentially extensible to any daemon.  For systemd I would use systemctl reload-or-restart <service> for this - since not all services necessarily support reloading.

One of the goals of systemd is to reduce the amount of clever scripting needed all over the place to catch error conditions or service-specific behaviors and such.

There is no reason that something like log rotation should require a lot of daemon-specific logic.
Comment 10 Liam Dennehy 2015-03-09 15:18:05 UTC
(In reply to Mike Gilbert from comment #8)

> If you insist in doing so despite this advice, please do not hard-code the
> path to systemctl. Just do "systemctl reload foo.service" and let logrotate
> find it in PATH.

I'm getting in that habit thanks to the requirement of systemd.service Exec{Start,Reload,Stop} command requirements that will fail if not given a complete path, of course it's not completely necessary.

> The user may have started apache without using any init system at all. I see
> no reason to call openrc or systemd just to get apache to re-open its log
> files.

Then this logrotate entry should do nothing - a reload in either OpenRC or systemd will take no action for a non-running service. Given this is the file that ships in the www-apps/apache-2.2 package it would be relied on by anyone simply starting their daemon the recommended way. If they're steeping outside the init-system to launch their processes then they should be left to their own devices on daemon management? At the very least, they will probably be editing their own logrotate file, and may have done other edits like custom log paths that the vanilla file will not catch - assuming they want the vanilla schedule.

However, the basic process of enabling and starting a service in systemd is now covered with this edit.
Comment 11 Liam Dennehy 2015-03-09 15:19:30 UTC
(In reply to Richard Freeman from comment #9)
> For systemd I would use systemctl reload-or-restart <service>
> for this - since not all services necessarily support reloading.

I didn't know that variant existed, thanks. However this would start a stopped service, whereas reload-or-try-restart would leave a stopped service stopped while restarting a running service.
Comment 12 Liam Dennehy 2015-03-09 15:23:01 UTC
Created attachment 398528 [details]
OpenRC/Systemd detection and reload postrotate

Conditional reload/restart for systemd, removed absolute path for systemctl
Comment 13 Liam Dennehy 2017-04-26 08:50:34 UTC
Assuming this is not being looked at, and have since moved on to Apache 2.4 so can not replicate for troubleshooting purposes.
Closing.