Skip to content

Commit

Permalink
Adding reset button for deployex
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoesteves committed Oct 10, 2024
1 parent 3accbec commit 4ec76ef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
25 changes: 25 additions & 0 deletions lib/deployex/deployex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,29 @@ defmodule Deployex do
full deployments or hot-upgrades, depending on the package's content, while
leveraging OTP distribution for monitoring and data extraction.
"""

alias Deployex.OpSys

require Logger

### ==========================================================================
### Public Functions
### ==========================================================================
@doc """
This function forces DeployEx to terminate. If DeployEx is installed as a
systemd service, it will automatically restart.
"""
@spec force_terminate() :: :ok
def force_terminate do
Logger.warning("Deployex was requested to terminate, see you soon!!!")

:timer.sleep(300)

OpSys.run(
"kill -9 $(ps -ax | grep \"/opt/deployex/erts-*.*/bin/beam.smp\" | grep -v grep | awk '{print $1}') ",
[:sync, :stdout, :stderr]
)

:ok
end
end
18 changes: 16 additions & 2 deletions lib/deployex_web/live/applications/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ defmodule DeployexWeb.ApplicationsLive do
<%= if @live_action in [:restart] do %>
<Confirm.content id={"app-restart-modal-#{@selected_instance}"}>
<:header>Attention</:header>
<p>
<:header :if={@selected_instance == "0"}>
<p class="text-red-500 text-center italic-text">Attention - All apps will be terminated</p>
</:header>
<:header :if={@selected_instance != "0"}>
<p>Attention</p>
</:header>
<p :if={@selected_instance == "0"}>
Are you sure you want to restart deployex?
</p>
<p :if={@selected_instance != "0"}>
Are you sure you want to restart instance <%= "#{@selected_instance}" %>?
</p>
<:footer>
Expand Down Expand Up @@ -274,6 +282,12 @@ defmodule DeployexWeb.ApplicationsLive do
{:noreply, push_patch(socket, to: ~p"/applications/#{instance}/versions")}
end

def handle_event("restart", %{"id" => "0"}, socket) do
# NOTE: Say goodbye to your monitored applications
Deployex.force_terminate()
{:noreply, push_patch(socket, to: ~p"/applications")}
end

def handle_event("restart", %{"id" => instance}, socket) do
# Restart the application
Monitor.restart(instance |> String.to_integer())
Expand Down
25 changes: 4 additions & 21 deletions lib/deployex_web/live/components/app_card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ defmodule DeployexWeb.Components.AppCard do
status={@status}
version={@version}
instance={@instance}
supervisor={@supervisor}
restart_path={@restart_path}
/>
Expand Down Expand Up @@ -291,11 +290,7 @@ defmodule DeployexWeb.Components.AppCard do
default_spec_class = "font-mono text-sm text-center p-2 border-b-2 border-black rounded-t-lg"

class =
if assigns.supervisor do
default_spec_class
else
"flex items-center justify-between font-mono text-sm text-center p-2 border-b-2 border-black rounded-t-lg"
end
"flex items-center justify-between font-mono text-sm text-center p-2 border-b-2 border-black rounded-t-lg"

assigns =
assigns
Expand All @@ -306,28 +301,16 @@ defmodule DeployexWeb.Components.AppCard do
<%= cond do %>
<% @status == :running and @version != nil -> %>
<div class={[@class, "bg-gradient-to-t from-green-400 to-green-600"]}>
<.restart_buttom
:if={@supervisor == false}
instance={@instance}
restart_path={@restart_path}
/>
<.restart_buttom instance={@instance} restart_path={@restart_path} />
<%= @version %> [running]
</div>
<% @status == :pre_commands -> %>
<div class={[@class, "bg-gradient-to-t from-yellow-100 to-yellow-600"]}>
<.restart_buttom
:if={@supervisor == false}
instance={@instance}
restart_path={@restart_path}
/> [pre-commands]
<.restart_buttom instance={@instance} restart_path={@restart_path} /> [pre-commands]
</div>
<% @status == :starting and @version != nil -> %>
<div class={[@class, "bg-gradient-to-t from-yellow-400 to-yellow-600"]}>
<.restart_buttom
:if={@supervisor == false}
instance={@instance}
restart_path={@restart_path}
/>
<.restart_buttom instance={@instance} restart_path={@restart_path} />
<%= @version %> [starting]
</div>
<% true -> %>
Expand Down

0 comments on commit 4ec76ef

Please sign in to comment.