Skip to content

Commit

Permalink
Do not remove or stop proxy unless indicated
Browse files Browse the repository at this point in the history
Fixes #262
  • Loading branch information
roborourke committed Dec 7, 2021
1 parent fa2333a commit afcce1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
6 changes: 4 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ The subdomain used for the project can be configured via the `modules.local-serv
* `composer server start [--xdebug=<mode>] [--mutagen]` - Starts the containers.
* `--xdebug=<mode>` will enable Xdebug. The `mode` is optional and defaults to `debug`. Available values are `off`, `develop`, `debug`, `profile`, `coverage`, `gcstats` and `trace`.
* `--mutagen` will enable Mutagen for container file sharing.
* `composer server stop` - Stops the containers.
* `composer server stop [--clean]` - Stops the containers.
* `--clean` will also stop the proxy container, only use this if you have no other instances of Local Server
* `composer server restart [<service>]` - Restart a given container, or all containers if none is provided. Available values are `nginx`, `php`, `db`, `redis`, `cavalcade`, `tachyon`, `s3` and `elasticsearch`.
* `composer server destroy` - Stops and destroys all containers.
* `composer server destroy [--clean]` - Stops and destroys all containers.
* `--clean` will also destroy the proxy container, only use this if you have no other instances of Local Server
* `composer server status` - Displays the status of all containers.
* `composer server logs <service>` - Tail the logs from a given service, defaults to `php`, available options are `nginx`, `php`, `db`, `redis`, `cavalcade`, `tachyon`, `s3` and `elasticsearch`.
* `composer server shell` - Logs in to the PHP container.
Expand Down
12 changes: 12 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ You can also apply the setting live using the following command:
sysctl -w vm.max_map_count=262144
```

## Port 8080 already in use

Local Server uses [Traefik Proxy](https://doc.traefik.io/traefik/) to listen for requests and map them to the appropriate containers.

The proxy container runs on ports `80`, `8080` and `443` locally. This means if you are already running a service that uses any of those ports such as a built in Apache or nginx server you will need to stop those before you can start Local Server.

On MacOS try running `sudo apachectl stop`. To prevent the built in server from starting automatically when starting the Mac run `sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist`.

Conversely if you are trying to run another service but are encoutnering this problem you may need to stop Local Server fully.

To do this run `composer server stop --clean`, or `composer server destroy --clean`. Note that you should only do this if you have no other running instance of Local Server.

## Windows 10 Home Edition

Docker Desktop for Windows uses Windows-native Hyper-V virtualization and networking, which is not available in the Windows 10 Home edition. If you are using Windows 10 Home Edition you will need to use the [Local Chassis](docs://local-chassis) environment.
Expand Down
38 changes: 27 additions & 11 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ protected function configure() {
Passing --mutagen will start the server using Mutagen
for file sharing.
Stop the local development server:
stop
stop [--clean] passing --clean will also stop the proxy container
Restart the local development server:
restart [--xdebug=<mode>] passing --xdebug restarts the server with xdebug enabled
Destroy the local development server:
destroy
destroy [--clean] passing --clean will also destroy the proxy container
View status of the local development server:
status
Run WP CLI command:
Expand All @@ -78,7 +78,8 @@ protected function configure() {
EOT
)
->addOption( 'xdebug', null, InputOption::VALUE_OPTIONAL, 'Start the server with Xdebug', 'debug' )
->addOption( 'mutagen', null, InputOption::VALUE_NONE, 'Start the server with Mutagen file sharing' );
->addOption( 'mutagen', null, InputOption::VALUE_NONE, 'Start the server with Mutagen file sharing' )
->addOption( 'clean', null, InputOption::VALUE_NONE, 'Remove or stop the proxy container when destroying or stopping the server' );
}

/**
Expand Down Expand Up @@ -283,10 +284,13 @@ protected function stop( InputInterface $input, OutputInterface $output ) {
echo $buffer;
} );

$proxy = new Process( 'docker-compose -f proxy.yml stop', 'vendor/altis/local-server/docker' );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
if ( $input->hasParameterOption( '--clean' ) ) {
$output->writeln( '<info>Stopping proxy container...</>' );
$proxy = new Process( 'docker-compose -f proxy.yml stop', 'vendor/altis/local-server/docker' );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
}

if ( $return_val === 0 ) {
$output->writeln( '<info>Stopped.</>' );
Expand Down Expand Up @@ -318,10 +322,22 @@ protected function destroy( InputInterface $input, OutputInterface $output ) {
echo $buffer;
} );

$proxy = new Process( 'docker-compose -f proxy.yml down -v', 'vendor/altis/local-server/docker' );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
// Check whether to remove the proxy container too.
$remove_proxy = $input->hasParameterOption( '--clean' );
if ( ! $remove_proxy ) {
$question = new ConfirmationQuestion( "Do you want to remove the shared proxy container too?\n<comment>Warning:</> Only do this if you have no other instances of Local Server. [y/N] ", false );
if ( $helper->ask( $input, $output, $question ) ) {
$remove_proxy = true;
}
}

if ( $remove_proxy ) {
$output->writeln( '<error>Destroying proxy container...</>' );
$proxy = new Process( 'docker-compose -f proxy.yml down -v', 'vendor/altis/local-server/docker' );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
}

if ( $return_val === 0 ) {
$output->writeln( '<error>Destroyed.</>' );
Expand Down

0 comments on commit afcce1f

Please sign in to comment.