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 PjbServerRestartCommand 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:restart') |
28
|
7 |
|
->setDescription( |
29
|
7 |
|
'Restart 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 |
|
Start the php java bridge server in the background. |
39
|
|
|
EOT |
40
|
1 |
|
); |
41
|
|
|
} |
42
|
1 |
|
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
44
|
1 |
|
{ |
45
|
|
|
$logger = $this->getConsoleLogger($output); |
46
|
|
|
|
47
|
1 |
|
$file = $input->getArgument('config-file'); |
48
|
|
|
|
49
|
|
|
// Test if config file exists |
50
|
|
|
if (!is_string($file) || !file_exists($file) || !is_readable($file)) { |
51
|
1 |
|
$msg = sprintf("Configuration file '%s' does not exists or is not readable'", (string) json_encode($file)); |
52
|
1 |
|
throw new \InvalidArgumentException($msg); |
53
|
1 |
|
} |
54
|
|
|
$params = include $file; |
55
|
1 |
|
$port = $params['port']; |
56
|
1 |
|
$config = new StandaloneServer\Config($params); |
57
|
|
|
|
58
|
1 |
|
$logger->notice("PJB server using port '$port' and config in '$file'"); |
59
|
1 |
|
$this->logServerConfig($logger, $config); |
60
|
|
|
|
61
|
1 |
|
$this->server = new StandaloneServer($config, $logger); |
62
|
|
|
$this->server->restart(); |
63
|
1 |
|
|
64
|
|
|
$logger->debug("Server output: \n" . $this->server->getOutput()); |
65
|
1 |
|
|
66
|
|
|
$output->writeln("Server successfully restarted on port $port"); |
67
|
|
|
|
68
|
|
|
return 0; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|