feat(cluster): add Asterisk astdb.sqlite3 live contacts sync every 2min
This commit is contained in:
1 parent
3f29ac6d2e
commit
c9ce4d7c74
3 files changed
+31
-2
No files matched your search
@@ -464,11 +464,30 @@ class ClusterManager
|
||||
$this->db->exec('PRAGMA wal_checkpoint(FULL);');
|
||||
|
||||
$tmpArchive = '/tmp/nexus_cluster_sync_' . time() . '.tar.gz';
|
||||
$tmpAstdb = '/tmp/astdb_cluster_sync.sqlite3';
|
||||
$hasAstdb = false;
|
||||
|
||||
// Sauvegarde intègre et atomique de la base de contacts Asterisk (astdb.sqlite3)
|
||||
$astdbPath = '/var/lib/asterisk/astdb.sqlite3';
|
||||
if (file_exists($astdbPath) && is_readable($astdbPath)) {
|
||||
@unlink($tmpAstdb);
|
||||
shell_exec("sqlite3 " . escapeshellarg($astdbPath) . " \".backup " . escapeshellarg($tmpAstdb) . "\" 2>/dev/null || cp -f " . escapeshellarg($astdbPath) . " " . escapeshellarg($tmpAstdb) . " 2>/dev/null || true");
|
||||
if (file_exists($tmpAstdb) && filesize($tmpAstdb) > 0) {
|
||||
$hasAstdb = true;
|
||||
}
|
||||
}
|
||||
|
||||
$cmd = "tar -czf " . escapeshellarg($tmpArchive) . " -C /var/www/nexus-pbx/storage database.sqlite";
|
||||
if (is_dir('/var/lib/asterisk/sounds/custom')) {
|
||||
$cmd .= " -C /var/lib/asterisk/sounds custom";
|
||||
}
|
||||
if ($hasAstdb) {
|
||||
$cmd .= " -C /tmp astdb_cluster_sync.sqlite3";
|
||||
}
|
||||
shell_exec($cmd);
|
||||
if ($hasAstdb) {
|
||||
@unlink($tmpAstdb);
|
||||
}
|
||||
|
||||
if (!file_exists($tmpArchive) || filesize($tmpArchive) === 0) {
|
||||
@unlink($tmpArchive);
|
||||
@@ -599,6 +618,15 @@ class ClusterManager
|
||||
if (is_dir('/var/lib/asterisk/sounds')) {
|
||||
shell_exec("tar -xzf " . escapeshellarg($tmpArchive) . " -C /var/lib/asterisk/sounds custom 2>/dev/null || true");
|
||||
}
|
||||
// Restauration de l'astdb (contacts et IP actives des téléphones PJSIP)
|
||||
shell_exec("tar -xzf " . escapeshellarg($tmpArchive) . " -C /tmp astdb_cluster_sync.sqlite3 2>/dev/null || true");
|
||||
if (file_exists('/tmp/astdb_cluster_sync.sqlite3')) {
|
||||
copy('/tmp/astdb_cluster_sync.sqlite3', '/var/lib/asterisk/astdb.sqlite3');
|
||||
@chown('/var/lib/asterisk/astdb.sqlite3', 'asterisk');
|
||||
@chgrp('/var/lib/asterisk/astdb.sqlite3', 'asterisk');
|
||||
@chmod('/var/lib/asterisk/astdb.sqlite3', 0664);
|
||||
@unlink('/tmp/astdb_cluster_sync.sqlite3');
|
||||
}
|
||||
@unlink($tmpArchive);
|
||||
|
||||
// Réouverture de la connexion DB
|
||||
|
||||
Reference in new issue
Block a user