Skip to content
Snippets Groups Projects
Verified Commit ddea5393 authored by Thomas Flori's avatar Thomas Flori
Browse files

implement pid check and add install script

parent 70aeef2d
No related branches found
No related tags found
No related merge requests found
Pipeline #645 canceled with stages
......@@ -8,6 +8,8 @@ use Hugga\Console;
class Daemon extends AbstractCommand
{
const PID_PATH = '/run/fan-ctrl.pid';
protected $name = 'daemon';
protected $description = 'Run the monitoring and control the fans';
......@@ -23,6 +25,13 @@ class Daemon extends AbstractCommand
$this->warn('This programm has to run as root');
return 1;
}
if (file_exists(self::PID_PATH) && posix_getpgid((int)file_get_contents(self::PID_PATH))) {
$this->warn('Fan Control is already running');
return 1;
}
file_put_contents(self::PID_PATH, posix_getpid());
$fanConfig = $this->app->fanConfig;
try {
$fanConfig->readConfig();
......
......@@ -7,9 +7,10 @@
"ulrichsg/getopt-php": "^4.0",
"filp/whoops": "^2.14",
"monolog/monolog": "^1.9",
"mossadal/math-parser": "^1.3",
"ext-pcntl": "*",
"php": ">=7.4",
"mossadal/math-parser": "^1.3"
"ext-posix": "*",
"php": ">=7.4"
},
"autoload": {
"psr-4": {
......
<?php
return [
'fans' => [
[
'name' => 'exhaust fans',
'type' => 'App\\Model\\Fan\\HwmonFan',
'options' => [
'hwmon' => 'nct6798',
'fan' => 'fan1',
'pwm' => 'pwm1',
'start' => 70,
'max' => 200,
],
],
[
'name' => 'cpu fan',
'type' => 'App\\Model\\Fan\\HwmonFan',
'options' => [
'hwmon' => 'nct6798',
'fan' => 'fan2',
'pwm' => 'pwm2',
'start' => 40,
'max' => 255,
],
],
[
'name' => 'radiator fans',
'type' => 'App\\Model\\Fan\\HwmonFan',
'options' => [
'hwmon' => 'nct6798',
'fan' => 'fan3',
'pwm' => 'pwm3',
'start' => 60,
'max' => 255,
],
],
[
'name' => 'bottom fans',
'type' => 'App\\Model\\Fan\\HwmonFan',
'options' => [
'hwmon' => 'nct6798',
'fan' => 'fan4',
'pwm' => 'pwm4',
'start' => 65,
'max' => 160,
],
],
[
'name' => 'water pump',
'type' => 'App\\Model\\Fan\\HwmonFan',
'options' => [
'hwmon' => 'nct6798',
'fan' => 'fan6',
'pwm' => 'pwm6',
'start' => 20,
'max' => 128,
],
],
],
'sensors' => [
[
'name' => 'cpu',
'type' => 'App\\Model\\Sensor\\HwmonSensor',
'options' => [
'hwmon' => 'k10temp',
'temp' => 'temp1',
],
],
[
'name' => 'gpu',
'type' => 'App\\Model\\Sensor\\CommandSensor',
'options' => [
'command' => 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader',
'conversion' => NULL,
],
],
],
'rules' => [
[
'fans' => [
'exhaust fans',
'cpu fan',
'bottom fans',
],
'sensor' => 'cpu',
'type' => 'App\\Model\\Rule\\CurveRule',
'options' => [
'alwaysOn' => true,
'points' => [
0 => 55,
60 => 80,
100 => 90,
],
],
],
[
'fans' => [
'radiator fans',
'water pump',
],
'sensor' => 'gpu',
'type' => 'App\\Model\\Rule\\CurveRule',
'options' => [
'alwaysOn' => true,
'points' => [
0 => 35,
60 => 55,
100 => 90,
],
],
],
],
];
#!/usr/bin/env bash
set -e
installTarget=/usr/share/fan-ctrl-php
# check for php and composer
if ! which php > /dev/null 2>&1 || ! which composer > /dev/null 2>&1; then
echo 'php and composer have to be installed in order to run fan-ctrl-php'
exit 1;
fi
# copy app, bin, composer.json, composer.lock to /usr/share/fan-ctrl-php
mkdir -p $installTarget
cp -r app bin composer.json composer.lock $installTarget
# install composer dependencies
pushd $installTarget
composer install -no
popd
# create symlink to bin/fan-ctrl in /usr/bin/
ln -s $installTarget/bin/fan-ctrl /usr/bin/fan-ctrl
# install fan-ctrl.service in /etc/systemd/system/
{
echo '[Unit]'
echo 'Description=A fan control service written in php'
echo ''
echo '[Service]'
echo 'User=root'
echo 'WorkingDirectory='$installTarget
echo 'ExecStart=/usr/bin/fan-ctrl daemon'
echo 'Restart=always'
echo ''
echo '[Install]'
echo 'WantedBy=multi-user.target'
} > /etc/systemd/system/fan-ctrl.service
echo Fan Control PHP successfully installed. Enable the service with \$ systemctl enable fan-ctrl.service
if ! test -f /etc/fan-ctrl.php; then
echo To create a configuration file and test the fans use \$ fan-ctrl config
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment