Added basic restarting for instances running in docker
This commit is contained in:
@@ -19,4 +19,5 @@ public class Events
|
|||||||
public static EventHandler<Post> OnPostLiked;
|
public static EventHandler<Post> OnPostLiked;
|
||||||
public static EventHandler<PostComment> OnPostCommentCreated;
|
public static EventHandler<PostComment> OnPostCommentCreated;
|
||||||
public static EventHandler<PostComment> OnPostCommentDeleted;
|
public static EventHandler<PostComment> OnPostCommentDeleted;
|
||||||
|
public static EventHandler OnMoonlightRestart;
|
||||||
}
|
}
|
||||||
27
Moonlight/App/Services/Sys/MoonlightService.cs
Normal file
27
Moonlight/App/Services/Sys/MoonlightService.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Moonlight.App.Event;
|
||||||
|
using Moonlight.App.Extensions;
|
||||||
|
using Moonlight.App.Helpers;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Services.Sys;
|
||||||
|
|
||||||
|
public class MoonlightService // This service can be used to perform strictly panel specific actions
|
||||||
|
{
|
||||||
|
private readonly ConfigService ConfigService;
|
||||||
|
public WebApplication Application { get; set; } // Do NOT modify using a plugin
|
||||||
|
|
||||||
|
public MoonlightService(ConfigService configService)
|
||||||
|
{
|
||||||
|
ConfigService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Restart()
|
||||||
|
{
|
||||||
|
Logger.Info("Restarting moonlight");
|
||||||
|
|
||||||
|
// Notify all users that this instance will restart
|
||||||
|
await Events.OnMoonlightRestart.InvokeAsync();
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||||
|
|
||||||
|
await Application.StopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,10 +12,14 @@ using Moonlight.App.Services.Community;
|
|||||||
using Moonlight.App.Services.Interop;
|
using Moonlight.App.Services.Interop;
|
||||||
using Moonlight.App.Services.ServiceManage;
|
using Moonlight.App.Services.ServiceManage;
|
||||||
using Moonlight.App.Services.Store;
|
using Moonlight.App.Services.Store;
|
||||||
|
using Moonlight.App.Services.Sys;
|
||||||
using Moonlight.App.Services.Users;
|
using Moonlight.App.Services.Users;
|
||||||
using Moonlight.App.Services.Utils;
|
using Moonlight.App.Services.Utils;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
var configService = new ConfigService();
|
||||||
|
var moonlightService = new MoonlightService(configService);
|
||||||
|
|
||||||
Directory.CreateDirectory(PathBuilder.Dir("storage"));
|
Directory.CreateDirectory(PathBuilder.Dir("storage"));
|
||||||
Directory.CreateDirectory(PathBuilder.Dir("storage", "logs"));
|
Directory.CreateDirectory(PathBuilder.Dir("storage", "logs"));
|
||||||
|
|
||||||
@@ -77,10 +81,11 @@ builder.Services.AddSingleton<ServiceAdminService>();
|
|||||||
|
|
||||||
// Services
|
// Services
|
||||||
builder.Services.AddScoped<IdentityService>();
|
builder.Services.AddScoped<IdentityService>();
|
||||||
builder.Services.AddSingleton<ConfigService>();
|
builder.Services.AddSingleton(configService);
|
||||||
builder.Services.AddSingleton<SessionService>();
|
builder.Services.AddSingleton<SessionService>();
|
||||||
builder.Services.AddSingleton<BucketService>();
|
builder.Services.AddSingleton<BucketService>();
|
||||||
builder.Services.AddSingleton<MailService>();
|
builder.Services.AddSingleton<MailService>();
|
||||||
|
builder.Services.AddSingleton(moonlightService);
|
||||||
|
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
@@ -97,6 +102,7 @@ var config =
|
|||||||
builder.Logging.AddConfiguration(config.Build());
|
builder.Logging.AddConfiguration(config.Build());
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
moonlightService.Application = app;
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"http": {
|
"http": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5132",
|
"applicationUrl": "http://localhost:5132",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
|||||||
18
Moonlight/Shared/Components/Alerts/RestartAlert.razor
Normal file
18
Moonlight/Shared/Components/Alerts/RestartAlert.razor
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
@inject NavigationManager Navigation
|
||||||
|
|
||||||
|
<div class="w-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="text-start mb-8">
|
||||||
|
<h1 class="text-dark mb-3 fs-3x">
|
||||||
|
Restarting
|
||||||
|
</h1>
|
||||||
|
<div class="text-gray-400 fw-semibold fs-6">
|
||||||
|
The panel is restarting. This may take a moment
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex flex-stack">
|
||||||
|
<a href="javascript:location.reload()" class="btn btn-primary me-2 flex-shrink-0">Reconnect</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
@using Moonlight.App.Models.Abstractions
|
@using Moonlight.App.Models.Abstractions
|
||||||
@using Moonlight.App.Models.Enums
|
@using Moonlight.App.Models.Enums
|
||||||
@using Moonlight.Shared.Components.Auth
|
@using Moonlight.Shared.Components.Auth
|
||||||
|
@using Moonlight.App.Event
|
||||||
|
|
||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
@inject IdentityService IdentityService
|
@inject IdentityService IdentityService
|
||||||
@inject SessionService SessionService
|
@inject SessionService SessionService
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
|
@inject IJSRuntime JsRuntime
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var url = new Uri(Navigation.Uri);
|
var url = new Uri(Navigation.Uri);
|
||||||
@@ -23,13 +25,19 @@
|
|||||||
if (!IdentityService.Flags[UserFlag.MailVerified] && ConfigService.Get().Security.EnableEmailVerify)
|
if (!IdentityService.Flags[UserFlag.MailVerified] && ConfigService.Get().Security.EnableEmailVerify)
|
||||||
{
|
{
|
||||||
<OverlayLayout>
|
<OverlayLayout>
|
||||||
<MailVerify />
|
<MailVerify/>
|
||||||
</OverlayLayout>
|
</OverlayLayout>
|
||||||
}
|
}
|
||||||
else if (IdentityService.Flags[UserFlag.PasswordPending])
|
else if (IdentityService.Flags[UserFlag.PasswordPending])
|
||||||
{
|
{
|
||||||
<OverlayLayout>
|
<OverlayLayout>
|
||||||
<ChangePassword />
|
<ChangePassword/>
|
||||||
|
</OverlayLayout>
|
||||||
|
}
|
||||||
|
else if (RestartLock)
|
||||||
|
{
|
||||||
|
<OverlayLayout>
|
||||||
|
<RestartAlert/>
|
||||||
</OverlayLayout>
|
</OverlayLayout>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -48,19 +56,19 @@
|
|||||||
if (url.LocalPath == "/register")
|
if (url.LocalPath == "/register")
|
||||||
{
|
{
|
||||||
<OverlayLayout>
|
<OverlayLayout>
|
||||||
<Register />
|
<Register/>
|
||||||
</OverlayLayout>
|
</OverlayLayout>
|
||||||
}
|
}
|
||||||
else if (url.LocalPath == "/password-reset")
|
else if (url.LocalPath == "/password-reset")
|
||||||
{
|
{
|
||||||
<OverlayLayout>
|
<OverlayLayout>
|
||||||
<PasswordReset />
|
<PasswordReset/>
|
||||||
</OverlayLayout>
|
</OverlayLayout>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<OverlayLayout>
|
<OverlayLayout>
|
||||||
<Login />
|
<Login/>
|
||||||
</OverlayLayout>
|
</OverlayLayout>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +98,7 @@ else
|
|||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private bool Initialized = false;
|
private bool Initialized = false;
|
||||||
|
private bool RestartLock = false;
|
||||||
|
|
||||||
private Session? MySession;
|
private Session? MySession;
|
||||||
|
|
||||||
@@ -114,6 +123,12 @@ else
|
|||||||
MySession.UpdatedAt = DateTime.UtcNow;
|
MySession.UpdatedAt = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Events.OnMoonlightRestart += async (_, _) =>
|
||||||
|
{
|
||||||
|
RestartLock = true;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
<div class="d-flex flex-column flex-root" id="kt_app_root">
|
@* disable any reconnect screens *@
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#components-reconnect-modal
|
||||||
|
{
|
||||||
|
display: none !important;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="d-flex flex-column flex-root" id="kt_app_root">
|
||||||
<div class="d-flex flex-column flex-lg-row flex-column-fluid">
|
<div class="d-flex flex-column flex-lg-row flex-column-fluid">
|
||||||
<a href="/" class="d-block d-lg-none mx-auto py-20">
|
<a href="/" class="d-block d-lg-none mx-auto py-20">
|
||||||
<img alt="Logo" src="/metronic8/demo38/assets/media/logos/default.svg" class="theme-light-show h-25px">
|
<img alt="Logo" src="/metronic8/demo38/assets/media/logos/default.svg" class="theme-light-show h-25px">
|
||||||
|
|||||||
@@ -2,7 +2,19 @@
|
|||||||
|
|
||||||
@using Moonlight.App.Extensions.Attributes
|
@using Moonlight.App.Extensions.Attributes
|
||||||
@using Moonlight.App.Models.Enums
|
@using Moonlight.App.Models.Enums
|
||||||
|
@using Moonlight.App.Services
|
||||||
|
@using Moonlight.App.Services.Sys
|
||||||
|
|
||||||
@attribute [RequirePermission(Permission.AdminRoot)]
|
@attribute [RequirePermission(Permission.AdminRoot)]
|
||||||
|
|
||||||
<AdminSysNavigation Index="0" />
|
@inject MoonlightService MoonlightService
|
||||||
|
|
||||||
|
<AdminSysNavigation Index="0" />
|
||||||
|
|
||||||
|
<div class="row mt-5">
|
||||||
|
<div class="col-md-4 col-12">
|
||||||
|
<div class="card card-body">
|
||||||
|
<ConfirmButton OnClick="MoonlightService.Restart" Text="Restart" CssClasses="btn-danger" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user