diff --git a/ci/image-tests/Checks/ApacheChecks.php b/ci/image-tests/Checks/ApacheChecks.php index 490e743ee..374511f26 100644 --- a/ci/image-tests/Checks/ApacheChecks.php +++ b/ci/image-tests/Checks/ApacheChecks.php @@ -7,6 +7,9 @@ use PHPUnit\Framework\Attributes\DataProvider; use Webdevops\Build\ImageTests\ImageTestCase; +use function sleep; +use function sprintf; + /** * Checks of the images with Apache: configuration layout, TLS files, modules, and Apache answering on port 80 and * 443. @@ -136,4 +139,25 @@ public function testApacheRuns(): void { $this->assertServiceRunning('apache'); } + + /** + * supervisorctl restart starts a new Apache, which reads a configuration added in the meantime, also when the pid + * file of the stopped one is left over and names a running process, here supervisord, as after an unclean exit. + */ + public function testSupervisorctlRestartsApache(): void + { + $container = $this->startContainer('apache-restart'); + $this->request('http://localhost/pi-number.html', container: $container); + $pidFile = self::image()->isAlpine() ? '/run/apache2/httpd.pid' : '/var/run/apache2/apache2.pid'; + $this->assertCommandSucceeds(sprintf( + "printf '%%s\n' 'Header always set X-Image-Test-Restart \"restarted\"' > /opt/docker/etc/httpd/conf.d/image-test-restart.conf && supervisorctl stop apache:apached && echo 1 > %s && supervisorctl start apache:apached", + $pidFile, + ), $container); + $this->waitFor(function () use ($container): void { + self::assertMatchesRegularExpression('/^X-Image-Test-Restart: restarted\r?$/mi', $this->stdout('curl --silent --head http://localhost/pi-number.html', $container)); + }); + $processId = $this->stdout('supervisorctl pid apache:apached', $container); + sleep(self::WAIT_SECONDS * 2); + self::assertSame($processId, $this->stdout('supervisorctl pid apache:apached', $container), 'Apache should keep running, not be restarted over and over.'); + } } diff --git a/docker/apache/alpine/conf/bin/service.d/httpd.sh b/docker/apache/alpine/conf/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/docker/apache/alpine/conf/bin/service.d/httpd.sh +++ b/docker/apache/alpine/conf/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/docker/php-apache/8.2-alpine/conf/bin/service.d/httpd.sh b/docker/php-apache/8.2-alpine/conf/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/docker/php-apache/8.2-alpine/conf/bin/service.d/httpd.sh +++ b/docker/php-apache/8.2-alpine/conf/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/docker/php-apache/8.3-alpine/conf/bin/service.d/httpd.sh b/docker/php-apache/8.3-alpine/conf/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/docker/php-apache/8.3-alpine/conf/bin/service.d/httpd.sh +++ b/docker/php-apache/8.3-alpine/conf/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/docker/php-apache/8.4-alpine/conf/bin/service.d/httpd.sh b/docker/php-apache/8.4-alpine/conf/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/docker/php-apache/8.4-alpine/conf/bin/service.d/httpd.sh +++ b/docker/php-apache/8.4-alpine/conf/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/docker/php-apache/8.5-alpine/conf/bin/service.d/httpd.sh b/docker/php-apache/8.5-alpine/conf/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/docker/php-apache/8.5-alpine/conf/bin/service.d/httpd.sh +++ b/docker/php-apache/8.5-alpine/conf/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/provisioning/apache/alpine/bin/service.d/httpd.sh b/provisioning/apache/alpine/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/provisioning/apache/alpine/bin/service.d/httpd.sh +++ b/provisioning/apache/alpine/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS diff --git a/provisioning/php-apache/alpine/bin/service.d/httpd.sh b/provisioning/php-apache/alpine/bin/service.d/httpd.sh index f88544c62..d82a14716 100644 --- a/provisioning/php-apache/alpine/bin/service.d/httpd.sh +++ b/provisioning/php-apache/alpine/bin/service.d/httpd.sh @@ -7,7 +7,8 @@ source /opt/docker/bin/config.sh includeScriptDir "/opt/docker/bin/service.d/httpd.d/" -# Apache gets grumpy about PID files pre-existing -rm -f /var/run/httpd/httpd.pid +# Apache does not start while its pid file from an earlier run names a running process +rm -f /run/apache2/httpd.pid -exec /usr/sbin/apachectl -DFOREGROUND $SERVICE_APACHE_OPTS +# httpd itself, not apachectl, which would run it as a child: supervisord has to stop and restart httpd +exec /usr/sbin/httpd -DFOREGROUND $SERVICE_APACHE_OPTS