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
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.
Created attachment 397784 [details, diff] Replace openrc reload with init-system-aware reload script
Created attachment 397786 [details, diff] /etc/logrotate.d/apache2 replace openrc reload with init-aware script
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.
Created attachment 398232 [details] OpenRC/Systemd detection and reload postrotate
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.
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.
(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.
(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.
(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.
(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.
Created attachment 398528 [details] OpenRC/Systemd detection and reload postrotate Conditional reload/restart for systemd, removed absolute path for systemctl
Assuming this is not being looked at, and have since moved on to Apache 2.4 so can not replicate for troubleshooting purposes. Closing.