-
Notifications
You must be signed in to change notification settings - Fork 14
/
scheduler.php
executable file
·41 lines (36 loc) · 1.17 KB
/
scheduler.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
#!/usr/bin/env php
<?php
// vim: set ai ts=4 sw=4 ft=php:
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2013 Schmooze Com Inc.
//
// Dashboard Scheduler.
// Runs every minute.
//
// Sleep to fix crazy issues with large VM hosting providers
sleep(random_int(1,30));
// Start quickly.
$bootstrap_settings['freepbx_auth'] = false; // Just in case.
$restrict_mods = true; // Takes startup from 0.2 seconds to 0.07 seconds.
include '/etc/freepbx.conf';
use Symfony\Component\Lock\Factory;
use Symfony\Component\Lock\Store\FlockStore;
$astrundir = \FreePBX::Config()->get('ASTRUNDIR');
if(!is_dir($astrundir) || !is_writable($astrundir)) {
echo "Asterisk Run Dir [".$astrundir."] is missing or not writable! Is Asterisk running?\n";
exit(1);
}
$lockStore = new FlockStore($astrundir);
$factory = new Factory($lockStore);
$lock = $factory->createLock('scheduler',60);
if (!$lock->acquire()) {
// Unable to lock, we're already running.
exit;
}
if(!$astman->connected()){
exit;
}
// Run the trigger
\FreePBX::Dashboard()->runTrigger();
// remove lockfile, and then close handle to release kernel lock
$lock->release();