Skip to content

Commit

Permalink
Merge pull request #290 from humanmade/stop-service-name
Browse files Browse the repository at this point in the history
Allow stopping specific services
  • Loading branch information
roborourke authored Aug 18, 2021
2 parents 3b34155 + 1f921ef commit d28292a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
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

0 comments on commit d28292a

Please sign in to comment.