"Run custom script after update" option for each app
-
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.
-
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.
-
@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
-
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).
-
@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