Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ci/image-tests/Checks/ApacheChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.');
}
}
7 changes: 4 additions & 3 deletions docker/apache/alpine/conf/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions docker/php-apache/8.2-alpine/conf/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions docker/php-apache/8.3-alpine/conf/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions docker/php-apache/8.4-alpine/conf/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions docker/php-apache/8.5-alpine/conf/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions provisioning/apache/alpine/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions provisioning/php-apache/alpine/bin/service.d/httpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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