Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. LAMP
  3. Restart apache gracefully from cron - or how to restart apache when not in the same container

Restart apache gracefully from cron - or how to restart apache when not in the same container

Scheduled Pinned Locked Moved Solved LAMP
14 Posts 4 Posters 2.1k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • nebulonN Offline
    nebulonN Offline
    nebulon
    Staff
    wrote on last edited by
    #4

    that seems very specific and maybe better to create your own lamp package for this. Also note that by default apache logs to stdout instead of a log file.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hendrikvl
      wrote on last edited by
      #5

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hendrikvl
        wrote on last edited by
        #6

        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.

        girishG 1 Reply Last reply
        0
        • H hendrikvl

          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.

          girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by girish
          #7

          @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
          
          1 Reply Last reply
          1
          • robiR Offline
            robiR Offline
            robi
            wrote on last edited by
            #8

            You could look into using the CTFreak app which can manage crontabs in any app, but you'll still need to be able to have it run the apachectl command, which is what @girish just figured out above.

            Conscious tech

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hendrikvl
              wrote on last edited by
              #9

              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.

              robiR 1 Reply Last reply
              0
              • H hendrikvl

                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.

                robiR Offline
                robiR Offline
                robi
                wrote on last edited by
                #10

                @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.

                Conscious tech

                H 1 Reply Last reply
                1
                • robiR robi

                  @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.

                  H Offline
                  H Offline
                  hendrikvl
                  wrote on last edited by hendrikvl
                  #11

                  @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 🙂

                  robiR 1 Reply Last reply
                  0
                  • H hendrikvl

                    @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 🙂

                    robiR Offline
                    robiR Offline
                    robi
                    wrote on last edited by robi
                    #12

                    @hendrikvl cool, care to tell us exactly how you did it?

                    Conscious tech

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hendrikvl
                      wrote on last edited by
                      #13

                      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.

                      1 Reply Last reply
                      1
                      • robiR Offline
                        robiR Offline
                        robi
                        wrote on last edited by
                        #14

                        great, now you can mark this as a question/solved from the top post menu.

                        Conscious tech

                        1 Reply Last reply
                        0
                        • nebulonN nebulon marked this topic as a question on
                        • nebulonN nebulon has marked this topic as solved on
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Bookmarks
                        • Search