-
Notifications
You must be signed in to change notification settings - Fork 1
/
OsRebootCommand.php
57 lines (49 loc) · 1.5 KB
/
OsRebootCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Droid\Plugin\Os\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\ProcessBuilder;
class OsRebootCommand extends Command
{
private $processBuilder;
public function __construct(ProcessBuilder $builder, $name = null)
{
$this->processBuilder = $builder;
return parent::__construct($name);
}
public function configure()
{
$this
->setName('os:reboot')
->setDescription('Initiate a reboot.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$p = $this->getProcess(array('shutdown', '-r', 'now', '&&', 'logout'));
$output->writeln('<info>I attempt to initiate a reboot.</info>');
if ($p->run()) {
$output->writeln(
sprintf(
'<error>I have failed to initiate a reboot. Code %d: %s</error>',
$p->getExitCode(),
$p->getErrorOutput()
)
);
return $p->getExitCode();
}
$output->writeln('<info>I have successfully initiated a reboot.</info>');
}
/**
* @return \Symfony\Component\Process\Process
*/
private function getProcess($arguments)
{
return $this
->processBuilder
->setArguments($arguments)
->getProcess()
;
}
}