forked from engineerOfLies/rabbitmqphp_example
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrollback_qa.php
More file actions
64 lines (52 loc) · 1.68 KB
/
rollback_qa.php
File metadata and controls
64 lines (52 loc) · 1.68 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once('path.inc');
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
require_once('deploy_mysqlconnect.php');
function getLatestPassedVersion($bundleName) {
$db = getDeployDB();
$query = $db->prepare("SELECT version FROM Bundles WHERE bundle_name = ? AND status = 'passed' ORDER BY version DESC LIMIT 1");
$query->bind_param('s', $bundleName);
$query->execute();
$result = $query->get_result();
if ($row = $result->fetch_assoc()) {
return $row['version'];
} else {
return null;
}
}
if ($argc < 2) {
echo "Use: php rollback_qa.php (bundle_name)\n";
exit(1);
}
$bundleName = $argv[1];
$latestVersion = getLatestPassedVersion($bundleName);
if ($latestVersion === null) {
echo "Error: No 'passed' version found for bundle '$bundleName'.\n";
exit(1);
}
$installPath = '/var/www/html';
$client = new rabbitMQClient("testRabbitMQ.ini", "installMQ");
$request = [
'type' => 'install_bundle',
'bundle_name' => $bundleName,
'version' => $latestVersion,
'deploy_server' => '10.242.1.158',
'local_path' => '/var/qa/bundles',
'install_path' => $installPath,
'username' => 'omarh',
'ssh_key' => '../../.ssh/id_rsa',
];
$response = $client->send_request($request);
echo "Response: " . print_r($response, true) . "\n";
// restart apache
if ($response['status'] === 'success') {
$restartCommand = "sudo systemctl restart apache2";
exec($restartCommand, $restartOutput, $restartReturnVar);
if ($restartReturnVar === 0) {
echo "Apache restarted successfully.\n";
} else {
echo "Failed to restart Apache: " . implode("\n", $restartOutput) . "\n";
}
}
?>