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