Restart apache gracefully from cron - or how to restart apache when not in the same container
-
Restarting the whole app would indeed also restart apache. But this is not what I want. I only want to send a USR1 signal, which is equivalent to 'apachectl graceful' as described here: https://httpd.apache.org/docs/2.4/logs.html#rotation
In my case, I want to import some custom logs (with different level of details based on the headers set) into Matomo. Before importing the log file, I want to rotate the logs and ask apache to reopen its log files.
-
As a matter of fact, I created a custom lamp package already. I also tried using the scheduler addon instead of the cron-entry in the app settings. But also that one seems to be run in a different container.
I could of course use supervisor to start things in parallel within my container. But my line of thought was to use the existing cron-mechanisms that Cloudron provides. Hence my question if anyone knows of alternative ways to accomplish the apache restart.
-
I went forward now by using supervisord. Instead of starting apache directly as init process, supervisor takes care of starting apache. My log rotation script gets started in parallel and thus has the ability to send signals to the apache process. This works as well of course, but is way more complex. My inital hope was to be able to utilize the scheduler/cron facilities of cloudron, but I could not figure out a way how to solve the problem mentioned above.
-
girish Staffreplied to hendrikvl on Jun 21, 2023, 3:39 AM last edited by girish Jun 21, 2023, 3:41 AM
@hendrikvl Not 100% sure if this is what you are asking but you want
apachectl graceful
to work ? Try something like:APACHE_CONFDIR="" source /etc/apache2/envvars apachectl graceful
With the above, I see the following in the logs:
[mpm_prefork:notice] [pid 1] AH00171: Graceful restart requested, doing restart [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.52 (Ubuntu) mod_perl/2.0.12 Perl/v5.34.0 configured -- resuming normal operations
-
Thanks for your replies, @girish, @robi. Both good ideas for further improvement, but they do not adress the main problem I encountered. 'apachectl graceful' is equivalent to the 'kill -s USR1' approach I described above.
My point was that the signal does not reach the apache process, if called from a separate cron-environment. I could solve this through the use of supervisord though.
-
@hendrikvl containers are isolated from each other, so you need to have one access the other to run commands. We do that all the time via ssh, right?
That's also what CTFreak can do.
-
hendrikvlreplied to robi on Jun 27, 2023, 7:47 AM last edited by hendrikvl Jun 27, 2023, 12:30 PM
@robi I know containers are isolated from each other. I was just surprised to figure out that cronjobs via the Cloudron UI oder the scheduler in the app manifest are run in a separated container. Hence my question how to signal apache from the outside.
But I solved it for me, by running a separate process within the same container -
robireplied to hendrikvl on Jun 27, 2023, 11:12 AM last edited by robi Jun 27, 2023, 11:12 AM
@hendrikvl cool, care to tell us exactly how you did it?
-
Sure, here is what I did:
I took the supervisord-setup of the tutorial-supervisor-app as a template. One process is apache, as in the default lamp-app. The other process I start is a custom bash-script which sleeps for a longer amount of time and then performs a log rotation including the "apachectl graceful" mentioned above. After that it exits and gets restarted by supervisord. -
great, now you can mark this as a question/solved from the top post menu.
-
-
12/14