1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PjbServer\Tools\Console\Command; |
6
|
|
|
|
7
|
|
|
use PjbServer\Tools\StandaloneServer; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
class PjbServerStopCommand extends Command |
14
|
|
|
{ |
15
|
|
|
use LoggerTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var StandaloneServer |
19
|
|
|
*/ |
20
|
|
|
protected $server; |
21
|
|
|
|
22
|
|
|
/** |
23
|
7 |
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
7 |
|
protected function configure(): void |
26
|
7 |
|
{ |
27
|
|
|
$this->setName('pjbserver:stop') |
28
|
7 |
|
->setDescription( |
29
|
7 |
|
'Stop the standalone pjb server (java)' |
30
|
7 |
|
) |
31
|
7 |
|
->addArgument( |
32
|
|
|
'config-file', |
33
|
7 |
|
InputArgument::REQUIRED, |
34
|
7 |
|
'Configuration file, see ./dist/pjbserver.config.php.dist' |
35
|
|
|
) |
36
|
|
|
->setHelp( |
37
|
7 |
|
<<<'EOT' |
38
|
7 |
|
Stop the standalone php java bridge server (running in the background). |
39
|
|
|
EOT |
40
|
2 |
|
); |
41
|
|
|
} |
42
|
2 |
|
|
43
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
44
|
|
|
{ |
45
|
|
|
$logger = $this->getConsoleLogger($output); |
46
|
2 |
|
$file = $input->getArgument('config-file'); |
47
|
|
|
|
48
|
|
|
// Test if config file exists |
49
|
|
|
if (!file_exists($file) || !is_readable($file)) { |
|
|
|
|
50
|
2 |
|
$msg = "Configuration file '$file' does not exists or is not readable'"; |
51
|
2 |
|
throw new \InvalidArgumentException($msg); |
52
|
|
|
} |
53
|
2 |
|
$params = include $file; |
54
|
|
|
$port = $params['port']; |
55
|
2 |
|
|
56
|
2 |
|
$config = new StandaloneServer\Config($params); |
57
|
|
|
|
58
|
2 |
|
$logger->notice("Stopping the server on port '$port' and config file '$file'"); |
59
|
|
|
$this->logServerConfig($logger, $config); |
60
|
2 |
|
|
61
|
2 |
|
$this->server = new StandaloneServer($config, $logger); |
62
|
1 |
|
|
63
|
1 |
|
$pid_file = $this->server->getConfig()->getPidFile(); |
64
|
|
|
if (!file_exists($pid_file)) { |
65
|
|
|
$output->writeln("Server already stopped (pid_file '${pid_file}' not found)."); |
66
|
|
|
} else { |
67
|
|
|
$this->server->stop(); |
68
|
|
|
$output->writeln("Server running on port $port successfully stopped"); |
69
|
|
|
} |
70
|
1 |
|
|
71
|
|
|
return 0; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|