Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow stopping specific services #290

Merged
merged 1 commit into from
Aug 18, 2021
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
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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 [<service>]` - Stops the containers or specified service.
* `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 status` - Displays the status of all containers.
Expand Down
33 changes: 21 additions & 12 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ protected function configure() {
optionally set the xdebug mode by assigning a value.
Passing --mutagen will start the server using Mutagen
for file sharing.
Stop the local development server:
stop
Stop the local development server or specific service:
stop [<service>]
Restart the local development server:
restart [--xdebug=<mode>] passing --xdebug restarts the server with xdebug enabled
restart [--xdebug=<mode>] [<service>] passing --xdebug restarts the server with xdebug enabled
Destroy the local development server:
destroy
View status of the local development server:
Expand Down Expand Up @@ -278,24 +278,33 @@ protected function start( InputInterface $input, OutputInterface $output ) {
protected function stop( InputInterface $input, OutputInterface $output ) {
$output->writeln( '<info>Stopping...</>' );

$compose = new Process( $this->get_compose_command( 'stop', true ), 'vendor', $this->get_env() );
$compose->setTty( posix_isatty( STDOUT ) );
$options = $input->getArgument( 'options' );
if ( isset( $options[0] ) ) {
$service = $options[0];
} else {
$service = '';
}

$compose = new Process( $this->get_compose_command( "stop $service", true ), 'vendor', $this->get_env() );
$compose->setTimeout( 0 );
$compose->setTty( posix_isatty( STDOUT ) );
$return_val = $compose->run( function ( $type, $buffer ) {
echo $buffer;
} );

$proxy = new Process( $this->get_compose_command( '-f proxy.yml stop' ), 'vendor/altis/local-server/docker' );
$proxy->setTimeout( 0 );
$proxy->setTty( posix_isatty( STDOUT ) );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
if ( $service === '' ) {
$proxy = new Process( $this->get_compose_command( '-f proxy.yml stop' ), 'vendor/altis/local-server/docker' );
$proxy->setTimeout( 0 );
$proxy->setTty( posix_isatty( STDOUT ) );
$proxy->run( function ( $type, $buffer ) {
echo $buffer;
} );
}

if ( $return_val === 0 ) {
$output->writeln( '<info>Stopped.</>' );
} else {
$output->writeln( '<error>Failed to stop services.</>' );
$output->writeln( '<error>Failed to stop service(s).</>' );
}

return $return_val;
Expand Down