Restart apache gracefully from cron - or how to restart apache when not in the same container
-
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.
-
@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.
-
@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 -
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. -
-