Adding logging into the auto updater and also added more logging around the create inital user for #1604

pull/1614/head
tidusjar 7 years ago
parent 55c62772e4
commit 2e0f301680

@ -0,0 +1,7 @@
namespace Ombi.Updater
{
public interface IInstaller
{
void Start(StartupOptions opt);
}
}

@ -4,11 +4,19 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Extensions.Logging;
namespace Ombi.Updater
{
public class Installer
public class Installer : IInstaller
{
public Installer(ILogger<Installer> log)
{
_log = log;
}
private readonly ILogger<Installer> _log;
public void Start(StartupOptions opt)
{
// Kill Ombi Process
@ -19,23 +27,25 @@ namespace Ombi.Updater
while (p.FindProcessByName(opt.ProcessName).Any())
{
Thread.Sleep(500);
Console.WriteLine("Found another process called Ombi, KILLING!");
_log.LogDebug("Found another process called {0}, KILLING!", opt.ProcessName);
var proc = p.FindProcessByName(opt.ProcessName).FirstOrDefault();
if (proc != null)
{
Console.WriteLine($"[{proc.Id}] - {proc.Name} - Path: {proc.StartPath}");
_log.LogDebug($"[{proc.Id}] - {proc.Name} - Path: {proc.StartPath}");
p.Kill(proc.Id);
}
}
_log.LogDebug("Starting to move the files");
MoveFiles(opt);
_log.LogDebug("Files replaced");
// Start Ombi
StartOmbi(opt);
}
private void StartOmbi(StartupOptions options)
{
_log.LogDebug("Starting ombi");
var fileName = "Ombi.exe";
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@ -52,7 +62,7 @@ namespace Ombi.Updater
{
proc.Start();
}
_log.LogDebug("Ombi started, now exiting");
Environment.Exit(0);
}
@ -60,16 +70,25 @@ namespace Ombi.Updater
{
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
location = Path.GetDirectoryName(location);
_log.LogDebug("We are currently in dir {0}", location);
_log.LogDebug("Ombi is installed at {0}", options.ApplicationPath);
//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(location, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(location, options.ApplicationPath));
{
var newDir = dirPath.Replace(location, options.ApplicationPath);
Directory.CreateDirectory(newDir);
_log.LogDebug("Created dir {0}", newDir);
}
//Copy all the files & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(location, "*.*",
foreach (string currentPath in Directory.GetFiles(location, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(location, options.ApplicationPath), true);
{
var newFile = currentPath.Replace(location, options.ApplicationPath);
File.Copy(currentPath, newFile, true);
_log.LogDebug("Replaced file {0}", newFile);
}
}
}
}

@ -10,4 +10,20 @@
<PackageVersion></PackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
<PackageReference Include="Serilog" Version="2.4.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />
<PackageReference Include="Serilog.Sinks.File" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
</ItemGroup>
</Project>

@ -1,6 +1,13 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using ILogger = Serilog.ILogger;
namespace Ombi.Updater
{
@ -14,11 +21,44 @@ namespace Ombi.Updater
var options = CheckArgs(args);
var install = new Installer();
install.Start(options);
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
// Create service provider
var serviceProvider = serviceCollection.BuildServiceProvider();
// Run app
serviceProvider.GetService<IInstaller>().Start(options);
}
private static void ConfigureServices(IServiceCollection serviceCollection)
{
// Add logging
serviceCollection.AddSingleton(new LoggerFactory()
.AddConsole()
.AddSerilog()
.AddDebug());
serviceCollection.AddLogging();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(Path.Combine("Logs", "log-{Date}.txt"))
.Enrich.FromLogContext()
.CreateLogger();
// Build configuration
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.Build();
// Add access to generic IConfigurationRoot
serviceCollection.AddSingleton(configuration);
//// Add services
serviceCollection.AddTransient<IInstaller, Installer>();
}
private static StartupOptions CheckArgs(string[] args)
{
if(args.Length <= 1)

@ -30,6 +30,7 @@ using Ombi.Settings.Settings.Models.Notifications;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
using IdentityResult = Microsoft.AspNetCore.Identity.IdentityResult;
using OmbiIdentityResult = Ombi.Models.Identity.IdentityResult;
namespace Ombi.Controllers
@ -102,19 +103,34 @@ namespace Ombi.Controllers
var result = await UserManager.CreateAsync(userToCreate, user.Password);
if (result.Succeeded)
{
_log.LogInformation("Created User {0}", userToCreate.UserName);
await CreateRoles();
await UserManager.AddToRoleAsync(userToCreate, OmbiRoles.Admin);
_log.LogInformation("Created the roles");
var roleResult = await UserManager.AddToRoleAsync(userToCreate, OmbiRoles.Admin);
if (!roleResult.Succeeded)
{
LogErrors(roleResult);
}
else
{
_log.LogInformation("Added the Admin role");
}
}
if (!result.Succeeded)
{
foreach (var err in result.Errors)
{
_log.LogCritical(err.Description);
}
LogErrors(result);
}
return result.Succeeded;
}
private void LogErrors(IdentityResult result)
{
foreach (var err in result.Errors)
{
_log.LogCritical(err.Description);
}
}
private async Task CreateRoles()
{
await CreateRole(OmbiRoles.AutoApproveMovie);

@ -173,7 +173,7 @@ namespace Ombi
app.UsePathBase(settings.BaseUrl);
}
app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1, ServerTimeout = TimeSpan.FromDays(1)});
app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1, ServerTimeout = TimeSpan.FromDays(1), ShutdownTimeout = TimeSpan.FromDays(1)});
app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire",
new DashboardOptions
{

Loading…
Cancel
Save