Newer
Older
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
<?php
namespace App\Command;
use App\Application;
use GetOpt\GetOpt;
use Hugga\Console;
class Daemon extends AbstractCommand
{
protected $name = 'daemon';
protected $description = 'Run the monitoring and control the fans';
public function __construct(Application $app, Console $console)
{
parent::__construct($app, $console);
}
public function handle(GetOpt $getOpt): int
{
if (posix_getuid() !== 0) {
$this->warn('This programm has to run as root');
return 1;
}
$fanConfig = $this->app->fanConfig;
try {
$fanConfig->readConfig();
} catch (\Throwable $e) {
$this->error('Unable to read config: ' . $e->getMessage());
return 2;
}
if (!$fanConfig->hasFans()) {
$this->error('No fans configured. Run config first');
return 3;
}
// @todo check that the fans are not in manual controll already
// prepare
$rules = $fanConfig->getRules();
// main loop
while (true) {
foreach ($rules as $rule) {
$rule->apply($this->console);
}
sleep(1);
}
}
}