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. Feature Requests
  3. "Run custom script after update" option for each app

"Run custom script after update" option for each app

Scheduled Pinned Locked Moved Feature Requests
5 Posts 3 Posters 742 Views 3 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.
    • LonkleL Offline
      LonkleL Offline
      Lonkle
      wrote on last edited by
      #1

      I would love for certain application (namely Wordpress WP-CLI) to run a bash script every time it's updated. I'm just going to build my own stack with a script like this, but I could see this kind of feature being useful for other users.

      Oh, and also, when updating Wordpress multisite, a script actually does need to be run after the update, I use this one:

      # Primary site's DB update
      wp core update-db
      
      # Core updates on multisite network
      if $( wp core is-installed --network ); then 
          wp core update-db --network
      fi
      
      # Handle WooCommerce database updates if installed
      if $( wp plugin is-installed woocommerce ); then 
          wp wc update
      fi
      
      # Handle WooCommerce database updates on multisite if installed
      if $( wp plugin is-installed woocommerce ) && $( wp core is-installed --network ); then 
          for site_id in $( wp site list --field=blog_id ); do
              site_url=$( wp site list --field=url --blog_id=${site_id} )
              if $( wp plugin is-active woocommerce --url=$site_url ); then
                  wp wc update --url=${site_url}
              fi
          done
      fi
      

      You're free to use that script. It's best to run it every update for multisite.

      1 Reply Last reply
      0
      • mehdiM Offline
        mehdiM Offline
        mehdi
        App Dev
        wrote on last edited by
        #2

        I think a good approach would be to add an environment variable containing the current app version to the ones set by Cloudron : https://docs.cloudron.io/custom-apps/guide/#environment-variables

        Using this, it would be trivial to put together a script which would write the current version number to a file, and on startup compare the env var to the file: if there's no file it's a new install, if there's a mismatch there has been an update, if they match it's just a restart.

        LonkleL 1 Reply Last reply
        1
        • mehdiM mehdi

          I think a good approach would be to add an environment variable containing the current app version to the ones set by Cloudron : https://docs.cloudron.io/custom-apps/guide/#environment-variables

          Using this, it would be trivial to put together a script which would write the current version number to a file, and on startup compare the env var to the file: if there's no file it's a new install, if there's a mismatch there has been an update, if they match it's just a restart.

          LonkleL Offline
          LonkleL Offline
          Lonkle
          wrote on last edited by
          #3

          @mehdi Brilliant way to do this. I'll start work on it. Especially since this has to be added for proper multisite updates anyway. I just wish the Developer edition allowed me to add a custom script when the Cloudron team updates it, if it did, I would run this every update, it's overkill for most but it works best for my flow:

          # Plugin updates
          wp plugin update --all
          wp plugin update --all --skip-plugins --skip-themes
          
          # Theme updates
          wp theme update --all
          wp theme update --all --skip-plugins --skip-themes
          
          # Core updates
          wp core update
          wp core update-db
          
          # Core updates on multisite network
          if $( wp core is-installed --network ); then 
              wp core update-db --network
          fi
          
          # Handle WooCommerce database updates if installed
          if $( wp plugin is-installed woocommerce ); then 
              wp wc update
          fi
          
          # Handle WooCommerce database updates on multisite if installed
          if $( wp plugin is-installed woocommerce ) && $( wp core is-installed --network ); then 
              for site_id in $( wp site list --field=blog_id ); do
                  site_url=$( wp site list --field=url --blog_id=${site_id} )
                  if $( wp plugin is-active woocommerce --url=$site_url ); then
                      wp wc update --url=${site_url}
                  fi
              done
          fi
          
          # Handle Elementor database updates if installed
          if $( wp plugin is-installed elementor ); then 
              wp elementor update db
              # Handle Elementor database updates on multisite
              if $( wp core is-installed --network ); then 
                  wp elementor update db --network
              fi
          fi
          
          # Handle redirection database updates if installed
          if $( wp plugin is-installed redirection ); then 
              wp redirection database upgrade
          fi
          
          
          1 Reply Last reply
          0
          • girishG Do not disturb
            girishG Do not disturb
            girish
            Staff
            wrote on last edited by
            #4

            If you are building a custom app, this is easy to do. Just track this in a file in /app/data , no? Some apps like EspoCRM do this already - For example, like https://git.cloudron.io/cloudron/espocrm-app/-/blob/master/start.sh#L84. It will be very hard to support "custom scripts" as it goes against our deployment ideas, but maybe we can add webhooks (which I think you have already created a separate topic for).

            LonkleL 1 Reply Last reply
            0
            • girishG girish

              If you are building a custom app, this is easy to do. Just track this in a file in /app/data , no? Some apps like EspoCRM do this already - For example, like https://git.cloudron.io/cloudron/espocrm-app/-/blob/master/start.sh#L84. It will be very hard to support "custom scripts" as it goes against our deployment ideas, but maybe we can add webhooks (which I think you have already created a separate topic for).

              LonkleL Offline
              LonkleL Offline
              Lonkle
              wrote on last edited by
              #5

              @girish Oh, absolutely with a custom app, I mentioned in the original post that I'm going to build my own Wordpress Stack to simply and only add this. But I saw benefit to other user's being able to script something post-update as that's literally the only thing my stack will do differently than the default Wordpress app (I'll have to integrate your updates into my stack manually each time so I still wish there was a way to run an external custom sh script post-installation).

              As you can see my custom script simply uses the CLI to upgrade all databases with any new required formatting if and only if any updated Wordpress core or updated plugin require it. When you update from the Cloudron interface, it simply updates all the files and Wordpress has this really annoying tendency to not upgrade the databases post-upgrade invisibly. The script above is the only way to make sure file versions and database versions stay in sync 100% of the time every update.

              This becomes nearly unavoidable if you want to support multisite in the future since the problem becomes more convoluted in that installation type so my script detects multisite installations and runs database upgrades accordingly with WP CLI commands or single site only commands if it's a single site.

              I actually think the script below should be an optional "automatic upgrade plugin and themes checkbox when updating Wordpress core" option for Wordpress installations as well, here's the WP CLI code for it:

              # Plugin updates
              wp plugin update --all
              wp plugin update --all --skip-plugins --skip-themes
              
              # Theme updates
              wp theme update --all
              wp theme update --all --skip-plugins --skip-themes
              
              1 Reply Last reply
              0
              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