Skip to content

Commit

Permalink
Improve stop command
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiloNL committed Jan 10, 2023
1 parent 499aadc commit ff19010
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Commands/StopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StopCommand extends Command
*
* @var string
*/
protected $signature = 'stop';
protected $signature = 'stop {--force}';

/**
* The description of the command.
Expand All @@ -29,7 +29,7 @@ class StopCommand extends Command
public function handle(SupervisordRepository $repository)
{
$this->task('Stopping services', function () use ($repository) {
return $repository->stopSupervisord();
return $repository->stopSupervisord($this->option('force'));
});
}
}
14 changes: 12 additions & 2 deletions app/Repositories/SupervisordRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function startSupervisord()
exec($supervisordPath.' -c '.Storage::disk()->path('supervisord.conf'));
}

public function stopSupervisord()
public function stopSupervisord($force = false)
{
if (Storage::exists('supervisord.pid') === false) {
return true;
Expand All @@ -138,11 +138,21 @@ public function stopSupervisord()
posix_kill(Storage::get('supervisord.pid'), SIGTERM);

while (true) {
if (file_exists(Storage::path('supervisord.pid')) === false) {
try {
$this->getAllProcessInfo();
sleep(1);
} catch (SupervisordConnectionRefusedException $e) {
// Shutdown complete
break;
} catch (SupervisordShutdownStateException $e) {
// Shutting down
}
}

if($force) {
Storage::delete('supervisord.pid');
}

return true;
}

Expand Down

0 comments on commit ff19010

Please sign in to comment.