ENHANCEMENT: use posix signal to check if daemon is running

main
Jeroen De Meerleer 2 months ago
parent 14446527a3
commit 0b41d9d7b8
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
  1. 21
      composer.json
  2. 5
      composer.lock
  3. 2
      src/Command/DaemonCommand.php
  4. 3
      src/Controller/SiteController.php
  5. 22
      src/Service/DaemonHelpers.php
  6. 1
      src/Service/Secret.php
  7. 2
      templates/job/edit.html.twig

@ -10,6 +10,7 @@
"ext-intl": "*",
"ext-openssl": "*",
"ext-pcntl": "*",
"ext-posix": "*",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
@ -17,17 +18,17 @@
"pentatrion/vite-bundle": "^1.2",
"phpseclib/phpseclib": "^3.0",
"scienta/doctrine-json-functions": "~5.0.0",
"symfony/console": "6.0.*",
"symfony/dotenv": "6.0.*",
"symfony/console": "^6.0",
"symfony/dotenv": "^6.0",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.0.*",
"symfony/mailer": "6.0.*",
"symfony/proxy-manager-bridge": "6.0.*",
"symfony/runtime": "6.0.*",
"symfony/security-bundle": "6.0.*",
"symfony/translation": "6.0.*",
"symfony/twig-bundle": "6.0.*",
"symfony/yaml": "6.0.*"
"symfony/framework-bundle": "^6.0",
"symfony/mailer": "^6.0",
"symfony/proxy-manager-bridge": "^6.0",
"symfony/runtime": "^6.0",
"symfony/security-bundle": "^6.0",
"symfony/translation": "^6.0",
"symfony/twig-bundle": "^6.0",
"symfony/yaml": "^6.0"
},
"config": {
"allow-plugins": {

5
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5b6d0f7b3419f7248fa3262cfb27697e",
"content-hash": "aecbf4d55d46cef867071ac3db00627a",
"packages": [
{
"name": "doctrine/annotations",
@ -7162,7 +7162,8 @@
"ext-iconv": "*",
"ext-intl": "*",
"ext-openssl": "*",
"ext-pcntl": "*"
"ext-pcntl": "*",
"ext-posix": "*"
},
"platform-dev": [],
"plugin-api-version": "2.2.0"

@ -50,7 +50,7 @@ class DaemonCommand extends Command
throw new \InvalidArgumentException('Time limit has incorrect value');
}
$jobRepo->unlockJob();
touch($this->kernel->getCacheDir() . '/daemon-running.lock');
file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', posix_getpid());
while(1) {
if($endofscript !== false && time() > $endofscript) break;

@ -3,6 +3,7 @@
namespace App\Controller;
use App\Entity\Job;
use App\Service\DaemonHelpers;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -17,7 +18,7 @@ class SiteController extends AbstractController
$em = $doctrine->getManager();
$jobRepo = $em->getRepository(Job::class);
$return = [
"DaemonRunning" => file_exists($kernel->getCacheDir() . '/daemon-running.lock'),
"DaemonRunning" => DaemonHelpers::isProcessRunning($kernel->getCacheDir() . '/daemon-running.lock'),
"JobsTotal" => count($jobRepo->getAllJobs()),
"JobsDue" => count($jobRepo->getJobsDue()),
"JobsRunning" => count($jobRepo->getRunningJobs()),

@ -0,0 +1,22 @@
<?php
namespace App\Service;
class DaemonHelpers
{
/**
* https://stackoverflow.com/a/3111757
*
* Checks if process with pid in $pidFile is still running
*
* @param $pidFile
* @return bool
*/
public static function isProcessRunning($pidFile = '/var/run/myfile.pid') {
if (!file_exists($pidFile) || !is_file($pidFile)) return false;
$pid = file_get_contents($pidFile);
$return = posix_kill((int)$pid, 0);
if (!$return) unlink($pidFile);
return $return;
}
}

@ -3,7 +3,6 @@
namespace App\Service;
class Secret
{
static function encrypt($plaintext) {

@ -8,7 +8,7 @@
<div class="mb-3">
<label for="name">{{ 'job.addedit.generalinfo.name.label' | trans }}</label>
<input type="text" name="name" class="form-control" id="name" placeholder="{{ 'job.addedit.generalinfo.name.placeholder' | trans }}" value="{{ job.name }}">
<small id="name-help" class="form-text text-muted">{{ 'job.addedit.generalinfo.name.helptext' | trans }}]</small>
<small id="name-help" class="form-text text-muted">{{ 'job.addedit.generalinfo.name.helptext' | trans }}</small>
</div>
<div class="mb-3">
<label for="name">{{ 'job.addedit.generalinfo.interval.label' | trans }}</label>

Loading…
Cancel
Save