Skip to content

Commit

Permalink
button to restart upstream services from status menu (#689)
Browse files Browse the repository at this point in the history
* button to restart upstream services from status menu
  • Loading branch information
orangewolf authored Jan 28, 2025
1 parent e7fd76c commit 5f21920
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 40 deletions.
22 changes: 20 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
FROM ghcr.io/samvera/hyku/base:d6ef0431 as hyku-base
FROM ghcr.io/samvera/hyku/base:d6ef0431 AS hyku-base
# The bunder and asset build are ONBUILD commands in the base. they still get run
# as if they were included right after the from line. See https://docs.docker.com/engine/reference/builder/#onbuild
RUN sed -i '/require .enumerator./d' /usr/local/bundle/gems/sass-3.7.4/lib/sass/util.rb
RUN ln -sf /app/samvera/branding /app/samvera/hyrax-webapp/public/branding
# Set environment variables for kubectl installation
ENV KUBECTL_VERSION=v1.27.3
USER root
# Determine the architecture and set the download URL accordingly
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "x86_64" ]; then \
ARCH="amd64"; \
elif [ "$ARCH" = "aarch64" ]; then \
ARCH="arm64"; \
elif [ "$ARCH" = "armv7l" ]; then \
ARCH="arm"; \
else \
echo "Unsupported architecture: $ARCH"; exit 1; \
fi && \
curl -LO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm kubectl
USER app

FROM hyku-base as hyku-worker
FROM hyku-base AS hyku-worker
CMD ./bin/worker
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ GIT
aws-sdk-sqs (~> 1)
rails (>= 4.2)

GIT
remote: https://github.com/notch8/iiif_print.git
revision: 5c5fa6880b3dc22beed738cfcba7af57b698ac36
branch: main
specs:
iiif_print (1.0.0)
blacklight_iiif_search (>= 1.0, < 3.0)
derivative-rodeo (~> 0.5)
hyrax (>= 2.5, < 6)
nokogiri (>= 1.13.2)
rdf-vocab (~> 3.0)

GIT
remote: https://github.com/samvera-labs/allinson_flex.git
revision: 581b58d57a90440f71d5d4ad8e1a9e4316ea92a3
Expand Down Expand Up @@ -133,18 +145,6 @@ GIT
iiif_manifest (1.3.1)
activesupport (>= 4)

GIT
remote: https://github.com/notch8/iiif_print.git
revision: 5c5fa6880b3dc22beed738cfcba7af57b698ac36
branch: main
specs:
iiif_print (1.0.0)
blacklight_iiif_search (>= 1.0, < 3.0)
derivative-rodeo (~> 0.5)
hyrax (>= 2.5, < 6)
nokogiri (>= 1.13.2)
rdf-vocab (~> 3.0)

GIT
remote: https://github.com/stanhu/omniauth-cas.git
revision: 4211e6d05941b4a981f9a36b49ec166cecd0e271
Expand Down
14 changes: 13 additions & 1 deletion app/controllers/status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ class StatusController < ApplicationController
authorize! :read, :admin_dashboard
end

def index
def show
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.system_status'), main_app.status_path
end

def update
@endpoint = Endpoint.find(params[:id])
result = if @endpoint.restart_command.present? && @endpoint.last_restart < 5.minutes.ago
`#{@endpoint.restart_command}`
else
t('.not_run')
end
@endpoint.update(last_restart: Time.zone.now)
flash[:notice] = t('.restart_result', result: result)
redirect_to status_path
end
end
21 changes: 20 additions & 1 deletion app/views/status/_service.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
<li class="list-group-item list-group-item-<%= status ? 'success' : 'danger' %>"><%= name %> <span class="badge"><%= status ? t(:'.ok') : t(:'.down') %></span></li>
<li class="list-group-item list-group-item-<%= status ? 'success' : 'danger' %>">
<div class="row">
<div class="col-xs-10">
<%= name %>
</div>
<div class="col-xs-1 text-right">
<span class="badge">
<%= status ? t(:'.ok') : t(:'.down') %>
</span>
</div>
<div class="col-xs-1 text-right">
<% if endpoint && endpoint.restart_command.present? %>
<% disabled = endpoint.last_restart > 5.minutes.ago %>
<%= button_to t('.restart'), status_path(id: endpoint.id), disabled: disabled, method: :patch, class: 'btn btn-danger btn-xs', title: disabled ? t('.five_minutes') : t('.restart_label') %>
<% else %>
<%= button_to t('.restart'), '/', disabled: true, class: 'btn btn-danger btn-xs', title: t('.no_command') %>
<% end %>
</div>
</div>
</li>
21 changes: 0 additions & 21 deletions app/views/status/index.html.erb

This file was deleted.

21 changes: 21 additions & 0 deletions app/views/status/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% content_for :page_header do %>
<h1><span class="fa fa-flag"></span> <%= t(:'hyrax.admin.sidebar.system_status') %></h1>
<% end %>

<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= t(:'.services') %></h3>
</div>
<div class="panel-body">
<ul class="list-group">
<%= render partial: 'service', locals: { name: 'Fedora', status: current_account.fcrepo_endpoint.ping, endpoint: current_account.fcrepo_endpoint } %>
<%= render partial: 'service', locals: { name: 'Solr', status: current_account.solr_endpoint.ping, endpoint: current_account.solr_endpoint } %>
<%= render partial: 'service', locals: { name: 'Redis', status: current_account.redis_endpoint.ping, endpoint: current_account.redis_endpoint } %>
<%= render partial: 'service', locals: { name: 'Database', status: ActiveRecord::Base.connection.active?, endpoint: nil } %>
</ul>
</div>
</div>
</div>
</div>
9 changes: 8 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,15 @@ en:
header: Manage Account
remove: Remove
status:
index:
show:
services: Services
update:
not_run: Command skipped because of it is missing or was run too recently.
restart_result: "Restart result was: %{result}"
service:
down: Down
ok: OK
restart: restart
five_minutes: You need to wait 5 minutes between restarts
restart_label: Restart endpoint
no_command: no command specified
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end
end

get 'status', to: 'status#index'
resource :status, only: [:show, :update], controller: 'status'

mount BrowseEverything::Engine => '/browse'
resource :site, only: [:update] do
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20250125001320_restart_for_endpoints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RestartForEndpoints < ActiveRecord::Migration[5.2]
def change
add_column :endpoints, :restart_command, :text
add_column :endpoints, :last_restart, :datetime, default: Time.now
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_12_03_010707) do
ActiveRecord::Schema.define(version: 2025_01_25_001320) do

# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
Expand Down Expand Up @@ -179,6 +179,7 @@
t.string "status_message", default: "Pending"
t.string "error_class"
t.index ["identifier", "importerexporter_id", "importerexporter_type"], name: "bulkrax_identifier_idx"
t.index ["importerexporter_id", "importerexporter_type", "id"], name: "index_bulkrax_entries_on_importerexporter_id_type_and_id"
t.index ["importerexporter_id", "importerexporter_type"], name: "bulkrax_entries_importerexporter_idx"
t.index ["type"], name: "index_bulkrax_entries_on_type"
end
Expand Down Expand Up @@ -385,6 +386,8 @@
t.binary "options"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "restart_command"
t.datetime "last_restart", default: "2025-01-25 00:47:14"
end

create_table "featured_collections", force: :cascade do |t|
Expand Down
27 changes: 27 additions & 0 deletions ops/production-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,30 @@ externalSolrPassword: $SOLR_ADMIN_PASSWORD
externalSolrHost: solr.solr.svc.cluster.local
externalSolrUser: admin
externalSolrCollection: "utk-hyku"


extraDeploy:
- |-
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: utk-hyku-production
name: deployment-manager
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: hyrax-deployment-manager-binding
namespace: default
subjects:
- kind: ServiceAccount
name: utk-hyku-production-hyrax
namespace: utk-hyku-production
roleRef:
kind: Role
name: deployment-manager
apiGroup: rbac.authorization.k8s.io

0 comments on commit 5f21920

Please sign in to comment.