-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1100 from griffithlab/maintenance-mode
Add rudimentary maintenance toggle admin utility
- Loading branch information
Showing
7 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'fileutils' | ||
|
||
module Actions | ||
class ToggleMaintenance | ||
include Actions::Transactional | ||
|
||
attr_reader :maintenance_mode_enabled, :maintenance_page, :backed_up_index_page, :index_file_path | ||
|
||
def initialize(maintenance_mode_enabled:) | ||
@maintenance_mode_enabled = maintenance_mode_enabled | ||
|
||
base_path = File.join(Rails.root, 'public') | ||
|
||
@maintenance_page = File.join(base_path, 'maintenance.html') | ||
@backed_up_index_page = File.join(base_path, 'index.html.actual') | ||
@index_file_path = File.join(base_path, 'index.html') | ||
end | ||
|
||
def execute | ||
if !File.exist?(index_file_path) | ||
raise StandardError.new("index.html does not exist. Unknown state.") | ||
end | ||
|
||
if maintenance_mode_enabled | ||
put_in_maintenance_mode | ||
else | ||
restore_production_mode | ||
end | ||
end | ||
|
||
private | ||
def put_in_maintenance_mode | ||
if !File.exist?(maintenance_page) | ||
raise StandardError.new("There doesn't seem to be a maintenance page available to use.") | ||
end | ||
if File.exist?(backed_up_index_page) | ||
raise StandardError.new("Site appears to already be in maintenance mode.") | ||
end | ||
|
||
FileUtils.mv(index_file_path, backed_up_index_page) | ||
FileUtils.cp(maintenance_page, index_file_path) | ||
end | ||
|
||
def restore_production_mode | ||
if !File.exist?(backed_up_index_page) | ||
raise StandardError.new("No backed up index.html found. Either the site is already live or we cannot restore.") | ||
end | ||
|
||
FileUtils.rm(index_file_path) | ||
FileUtils.mv(backed_up_index_page, index_file_path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class ActionWrapper | ||
AVAILABLE_ACTIONS = [ | ||
MergeAccounts | ||
MergeAccounts, | ||
ToggleMaintenanceMode | ||
] | ||
|
||
def self.name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class ToggleMaintenanceMode < ActionWrapper | ||
|
||
def self.name | ||
"Toggle Maintenance Mode" | ||
end | ||
|
||
def self.description | ||
"Turn on or off the maintenance page. Please do not touch this unless you're a developer. It will take down the site temporarily." | ||
end | ||
|
||
def self.inputs | ||
{ | ||
maintenance_mode_enabled: :boolean | ||
} | ||
end | ||
|
||
def action_class | ||
Actions::ToggleMaintenance | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!doctype html> | ||
<html class="no-js" lang="EN"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge" /> | ||
<title>Maintenance Page</title> | ||
<meta name="description" content="" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<style> | ||
html { | ||
background: linear-gradient( | ||
to bottom, | ||
#1b072e 0%, | ||
#370e5f 100% | ||
); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ | ||
background-repeat: no-repeat; | ||
min-height: 100%; | ||
min-width: 600px; | ||
width: 100%; | ||
height: auto; | ||
} | ||
|
||
a { | ||
color: white; | ||
} | ||
|
||
.logo { | ||
width: 100%; | ||
margin: 8em auto 0 auto; | ||
text-align: center; | ||
} | ||
|
||
.notice { | ||
margin: 5em auto; | ||
width: 100%; | ||
} | ||
.notice p { | ||
text-align: center; | ||
color: white; | ||
font-family: | ||
Segoe UI, | ||
Roboto, | ||
Helvetica Neue, | ||
Arial, | ||
Noto Sans, | ||
sans-serif; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="logo"> | ||
<img | ||
src="assets/images/CIViC_logo_for-dark-bg_LG_v5a.png" | ||
width="350" | ||
alt="CIViC - Clinical Interpretation of Variants in Cancer" | ||
/> | ||
</div> | ||
<div class="notice"> | ||
<p style="font-size: 150%; font-weight: bold"> | ||
CIViC is temporarily down for Maintenance. It will be back up shortly. | ||
</p> | ||
</div> | ||
</body> | ||
</html> |