Skip to content

Commit

Permalink
add instance refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
pcaskey committed Jan 8, 2021
1 parent bbe4929 commit e5b7060
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Workbench/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,3 @@ volumes:
generated-config:
generated-metadata:
mariadb-data:


28 changes: 28 additions & 0 deletions Workbench/scripts/refreshListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('mq', 5672, 'guest', 'password');
$channel = $connection->channel();

$channel->queue_declare('refreshInstance', false, false, false, false);

echo " [*] Waiting for messages. To exit press CTRL+C\n";

$callback = function ($msg) {
echo ' [x] Received ', $msg->body, "\n";
if ($msg->body == "REFRESH_THIS_INSTANCE") {
echo "Received REFRESH message!\n";
shell_exec( "/csp-tap/InCommonTAP-Examples/Workbench/scripts/refresh-this-instance.sh" );
}
};

$channel->basic_consume('refreshInstance', '', false, true, false, false, $callback);

while ($channel->is_consuming()) {
$channel->wait();
}

$channel->close();
$connection->close();
?>
10 changes: 8 additions & 2 deletions Workbench/webproxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ FROM tier/shibboleth_sp:latest
ARG CSPHOSTNAME=localhost
ENV CSPHOSTNAME=$CSPHOSTNAME

RUN yum -y install cronie
RUN yum -y install cronie php composer php-bcmath
RUN composer require php-amqplib/php-amqplib
RUN composer install
RUN mkdir -p /var/www/html/refresh

#COPY container_files/httpd/httpd.conf /etc/httpd/conf/

COPY container_files/httpd/refresh/index.php /var/www/html/refresh/
COPY container_files/httpd/proxy.conf /etc/httpd/conf.d/
COPY container_files/httpd/shib.conf /etc/httpd/conf.d/
COPY container_files/httpd/ssl.conf /etc/httpd/conf.d/
Expand All @@ -22,6 +26,8 @@ COPY container_files/shibboleth/ /etc/shibboleth/
COPY container_files/system/setservername.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/setservername.sh

RUN mkdir -p /signalreload

# fix httpd logging for ssl logs
RUN sed -i 's/TransferLog logs\/ssl_access_log/TransferLog \/tmp\/logpipe/g' /etc/httpd/conf.d/ssl.conf \
&& sed -i 's/ErrorLog logs\/ssl_error_log/ErrorLog \/tmp\/logpipe/g' /etc/httpd/conf.d/ssl.conf
Expand Down
1 change: 1 addition & 0 deletions Workbench/webproxy/container_files/httpd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ <h3>Welcome to the InCommon TAP Workbench!</h3>
</ul>
<br /><br /><br />
<a href="https://__CSPHOSTNAME__/status" target="TAP-WB-STATUS">Container Status</a>
<a href="https://__CSPHOSTNAME__/refresh/" target="TAP-WB-REFRESH">Refresh this instance</a>


56 changes: 56 additions & 0 deletions Workbench/webproxy/container_files/httpd/refresh/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>Refresh Instance</title>
</head>
<body>
<img src="../csp_logo.jpg"><br/>
<?php
require_once '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

if ($_POST["confirm"] != "") {
$btn_disabled = true;
}
?>
<?php
if ($btn_disabled != true) { ?>

Are you sure you want to refresh this instance? It will be unavailable while refreshing.
<br /><br />
Please type in the hostname of this instance to confirm you want to refresh.
<br /><br />

<form method = "POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Confirmation: <input type="text" name="confirm" id="confirm" value="<?php echo $confirm;?>">
<br /><br />
<button type = "submit" id = "btn-submit">Confirm</button>
</form>
<?php
}

if ($_SERVER["REQUEST_METHOD"] === 'POST') {
if (strcmp($_POST["confirm"], getenv("CSPHOSTNAME")) == 0) {
echo "Your request to refresh this instance is confirmed. <br/><br/>The refresh will start immediately (" . date("h:i:sa") . " GMT).";


$connection = new AMQPStreamConnection('mq', 5672, 'guest', 'password');
$channel = $connection->channel();

$channel->queue_declare('refreshInstance', false, false, false, false);

$msg = new AMQPMessage('REFRESH_THIS_INSTANCE');
$channel->basic_publish($msg, '', 'refreshInstance');

$channel->close();
$connection->close();

} else {
echo "Invalid confirmation. Please re-try using your actual hostname.";
}
}
?>

</body>
</html>

0 comments on commit e5b7060

Please sign in to comment.