Commit b365eaf4 authored by Denis Bonnenfant's avatar Denis Bonnenfant
Browse files

mise az jour

parent 69349b73
#!/bin/bash
version="3.9.4"
SSH="ssh -p 2222 root@deb.sambaedu.org"
if [ -z "$1" ]; then
paquet="sambaedu-wpkg"
fi
......@@ -11,7 +15,10 @@ cd ../sources
rm -f $debs
dch -U -i ""
debuild -us -uc -b
scp -P 2222 $debs root@wawadeb.crdp.ac-caen.fr:/root/se4
ssh -p 2222 root@wawadeb.crdp.ac-caen.fr "se4/se4.sh $version"
$SSH "mkdir -p /root/tmpse4"
scp -P 2222 $debs root@deb.sambaedu.org:/root/tmpse4
$SSH "for deb in \$(ls /root/tmpse4/*.deb); do echo \"traitement de \$deb\"; reprepro -C se4XP -b /var/www/debian includedeb stretch \$deb; done"
$SSH "rm -fr /root/tmpse4"
#ssh root@admin.sambaedu3.maison "apt-get update && apt-get -y upgrade $deb"
cd
......@@ -32,14 +32,21 @@ function update_xml_profiles($config)
{
$url_profiles = "/var/sambaedu/unattended/install/wpkg/profiles.xml";
$url_hosts = "/var/sambaedu/unattended/install/wpkg/hosts.xml";
while (apcu_fetch('profile_lock')) {
sleep(1);
}
apcu_add('profile_lock', 1, 300);
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWrite)
usleep(round(rand(0, 100) * 1000));
} while ((! $canWrite) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load($url_profiles);
if ($xml->load($url_profiles)) {
$profiles = $xml->documentElement->getElementsByTagName('profile');
$xml2 = new DOMDocument();
......@@ -86,7 +93,7 @@ function update_xml_profiles($config)
foreach ($hosts as $machine) {
if (isset($machine['memberof'])) {
$parcs = $machine['memberof'];
// if (count($parcs) > 0) {
// if (count($parcs) > 0) {
$new_profile = new DOMElement('profile');
$xml2->documentElement->appendChild($new_profile);
$new_profile->setAttribute("id", ldap_hostname($machine));
......@@ -115,22 +122,33 @@ function update_xml_profiles($config)
// }
}
}
$xml2->save($url_profiles);
$xml3->save($url_hosts);
apcu_delete('profile_lock');
$xml2->save($url_profiles);
flock($fp, LOCK_UN);
}
}
return fclose($fp);
} else {
return false;
}
}
function set_app_parcs($post_parc, $get_Appli, $liste_parcs, $url_profiles)
{
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWrite)
usleep(round(rand(0, 100) * 1000));
} while ((! $canWrite) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
while (apcu_fetch('profile_lock')) {
sleep(1);
}
apcu_add('profile_lock', 1, 300);
$xml->load($url_profiles);
$element = $xml->documentElement;
$profiles = $xml->documentElement->getElementsByTagName('profile');
......@@ -158,21 +176,32 @@ function set_app_parcs($post_parc, $get_Appli, $liste_parcs, $url_profiles)
}
}
$xml->save($url_profiles);
apcu_delete('profile_lock');
rewind($fp);
fwrite($fp, $xml->saveXML());
flock($fp, LOCK_UN);
fclose($fp);
}
}
return $result;
}
function set_app_postes($post_host, $get_Appli, $liste_parcs, $url_profiles)
{
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWrite)
usleep(round(rand(0, 100) * 1000));
} while ((! $canWrite) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
while (apcu_fetch('profile_lock')) {
sleep(1);
}
apcu_add('profile_lock', 1, 300);
$xml->load($url_profiles);
$element = $xml->documentElement;
$profiles = $xml->documentElement->getElementsByTagName('profile');
......@@ -199,22 +228,31 @@ function set_app_postes($post_host, $get_Appli, $liste_parcs, $url_profiles)
$result["out"] ++;
}
}
$xml->save($url_profiles);
apcu_delete('profile_lock');
rewind($fp);
fwrite($fp, $xml->saveXML());
flock($fp, LOCK_UN);
fclose($fp);
}
}
return $result;
}
function set_parc_apps($post_appli, $get_parc, $url_profiles)
{
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWrite)
usleep(round(rand(0, 100) * 1000));
} while ((! $canWrite) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
while (apcu_fetch('profile_lock')) {
sleep(1);
}
apcu_add('profile_lock', 1, 300);
$xml->load($url_profiles);
$element = $xml->documentElement;
$profiles = $xml->documentElement->getElementsByTagName('profile');
......@@ -240,22 +278,32 @@ function set_parc_apps($post_appli, $get_parc, $url_profiles)
}
}
}
$xml->save($url_profiles);
apcu_delete('profile_lock');
rewind($fp);
fwrite($fp, $xml->saveXML());
flock($fp, LOCK_UN);
fclose($fp);
}
}
return $result;
}
function clone_parc_apps($parc_source, $parc_cible, $url_profiles)
{
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWrite)
usleep(round(rand(0, 100) * 1000));
} while ((! $canWrite) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
while (apcu_fetch('profile_lock')) {
sleep(1);
}
apcu_add('profile_lock', 1, 300);
$xml->load($url_profiles);
$element = $xml->documentElement;
$profiles = $xml->documentElement->getElementsByTagName('profile');
......@@ -295,9 +343,12 @@ function clone_parc_apps($parc_source, $parc_cible, $url_profiles)
}
}
}
$xml->save($url_profiles);
apcu_delete('profile_lock');
rewind($fp);
fwrite($fp, $xml->saveXML());
flock($fp, LOCK_UN);
fclose($fp);
}
}
return $result;
}
......
......@@ -9,9 +9,21 @@
* @Licence Distribue sous la licence GPL
*/
/**
*
* @Repertoire: wpkg
* file: wpkg_lib_load_xml.php
*/
*/
if ($fp = fopen("/var/lock/wpkg.lock", 'w+')) {
$startTime = microtime();
do {
$canRead = flock($fp, LOCK_SH);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (! $canWRead)
usleep(round(rand(0, 100) * 1000));
} while ((! $canRead) and ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canRead) {
$xml_packages = simplexml_load_file($url_packages);
$xml_profiles = simplexml_load_file($url_profiles);
......@@ -20,4 +32,11 @@
$xml_hosts = simplexml_load_file($url_hosts);
$xml_forum = simplexml_load_file($url_forum);
flock($fp, LOCK_UN);
} else {
die ("erreur, impossible de lire les xml");
}
}
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment