From ce18424bcb076dbb6a28073ad28b57719c931eec Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Sat, 24 Oct 2026 00:06:26 +0530 Subject: [PATCH] fix(service): recreate a stopped global service from the compose file on enable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ee service enable` started an existing stopped container with `docker start`, so it came back on whatever image and config it was created with. An EasyEngine upgrade leaves a stopped global service as it is (on its old image, with the old tag recorded) and only regenerates the global compose file with the new tag, so enabling it kept the old image; and where an upgrade's network cleanup had removed its network, `docker start` failed while the command still reported success. `ee service enable ` now runs `docker-compose up -d ` for a container that isn't running: an unchanged container is just started, one whose image or config no longer matches the compose file is recreated (Compose pulls a missing image), and a missing network is created. A failure is reported as an error instead of "Service … enabled." nginx-proxy already goes through `up -d`. Other callers of `init_global_container()` (site create, cron) keep `docker start`, so they never recreate a database or redis as a side effect. This also repairs hosts where an earlier upgrade left a stopped service on its old image. --- src/Service_Command.php | 3 ++- src/helper/service-utils.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Service_Command.php b/src/Service_Command.php index 9502f08..bf885b3 100644 --- a/src/Service_Command.php +++ b/src/Service_Command.php @@ -81,7 +81,8 @@ public function enable( $args, $assoc_args ) { EE::Log( 'Notice: Service nginx_proxy already enabled.' ); } } else { - $service_status = \EE\Service\Utils\init_global_container( $service ); + // Recreate, not `docker start`: an upgrade leaves a stopped service on its old image for this to move. + $service_status = \EE\Service\Utils\init_global_container( $service, '', true ); if ( $service_status ) { EE::success( sprintf( 'Service %s enabled.', $service ) ); } else { diff --git a/src/helper/service-utils.php b/src/helper/service-utils.php index 89bfe4d..9ab5512 100644 --- a/src/helper/service-utils.php +++ b/src/helper/service-utils.php @@ -76,8 +76,9 @@ function nginx_proxy_check() { * Function to start global conainer if it is not running. * * @param string $container Global container to be brought up. + * @param bool $recreate `up -d` a stopped container too, which recreates it when the compose file changed (e.g. its image). */ -function init_global_container( $service, $container = '' ) { +function init_global_container( $service, $container = '', $recreate = false ) { if ( empty( $container ) ) { $container = 'services_' . $service . '_1'; @@ -96,7 +97,14 @@ function init_global_container( $service, $container = '' ) { if ( IS_DARWIN && GLOBAL_DB === $service && ! $fs->exists( $db_conf_file ) ) { $fs->copy( SERVICE_TEMPLATE_ROOT . '/my.cnf.mustache', $db_conf_file ); } - \EE_DOCKER::boot_container( $container, \EE_DOCKER::docker_compose_with_custom() . ' up -d ' . $service ); + $up = \EE_DOCKER::docker_compose_with_custom() . ' up -d ' . $service; + if ( $recreate ) { + if ( ! EE::exec( $up ) ) { + EE::error( "There was some error in starting $container. Please check logs." ); + } + } else { + \EE_DOCKER::boot_container( $container, $up ); + } return true; } else { return false;