core: improve updater to detect errors. resolves #8631 (#8661)

This commit is contained in:
Diego Heras
2020-05-16 01:43:42 +02:00
committed by GitHub
parent e00861b9ec
commit af9224ccbe
4 changed files with 41 additions and 17 deletions

View File

@@ -5,5 +5,6 @@ namespace Jackett.Common.Services.Interfaces
void StartUpdateChecker(); void StartUpdateChecker();
void CheckForUpdatesNow(); void CheckForUpdatesNow();
void CleanupTempDir(); void CleanupTempDir();
void CheckUpdaterLock();
} }
} }

View File

@@ -84,12 +84,23 @@ namespace Jackett.Common.Services
{ {
if (serverConfig.RuntimeSettings.NoUpdates) if (serverConfig.RuntimeSettings.NoUpdates)
{ {
logger.Info($"Updates are disabled via --NoUpdates."); logger.Info("Updates are disabled via --NoUpdates.");
return; return;
} }
if (serverConfig.UpdateDisabled && !forceupdatecheck) if (serverConfig.UpdateDisabled && !forceupdatecheck)
{ {
logger.Info($"Skipping update check as it is disabled."); logger.Info("Skipping update check as it is disabled.");
return;
}
if (Debugger.IsAttached)
{
logger.Info("Skipping checking for new releases as the debugger is attached.");
return;
}
var currentVersion = $"v{EnvironmentUtil.JackettVersion}";
if (currentVersion == "v0.0.0.0")
{
logger.Info("Skipping checking for new releases because we are runing in IDE.");
return; return;
} }
@@ -100,11 +111,6 @@ namespace Jackett.Common.Services
forceupdatecheck = true; forceupdatecheck = true;
var isWindows = System.Environment.OSVersion.Platform != PlatformID.Unix; var isWindows = System.Environment.OSVersion.Platform != PlatformID.Unix;
if (Debugger.IsAttached)
{
logger.Info($"Skipping checking for new releases as the debugger is attached.");
return;
}
var trayIsRunning = false; var trayIsRunning = false;
if (isWindows) if (isWindows)
@@ -136,9 +142,7 @@ namespace Jackett.Common.Services
if (releases.Count > 0) if (releases.Count > 0)
{ {
var latestRelease = releases.OrderByDescending(o => o.Created_at).First(); var latestRelease = releases.OrderByDescending(o => o.Created_at).First();
var currentVersion = $"v{GetCurrentVersion()}"; if (latestRelease.Name != currentVersion)
if (latestRelease.Name != currentVersion && currentVersion != "v0.0.0.0")
{ {
logger.Info($"New release found. Current: {currentVersion} New: {latestRelease.Name}"); logger.Info($"New release found. Current: {currentVersion} New: {latestRelease.Name}");
logger.Info($"Downloading release {latestRelease.Name} It could take a while..."); logger.Info($"Downloading release {latestRelease.Name} It could take a while...");
@@ -183,13 +187,6 @@ namespace Jackett.Common.Services
? Path.Combine(tempDirectory, "Jackett", "JackettUpdater") ? Path.Combine(tempDirectory, "Jackett", "JackettUpdater")
: Path.Combine(tempDirectory, "Jackett", "JackettUpdater.exe"); : Path.Combine(tempDirectory, "Jackett", "JackettUpdater.exe");
private string GetCurrentVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.ProductVersion;
}
private WebRequest SetDownloadHeaders(WebRequest req) private WebRequest SetDownloadHeaders(WebRequest req)
{ {
req.Headers = new Dictionary<string, string>() req.Headers = new Dictionary<string, string>()
@@ -234,6 +231,19 @@ namespace Jackett.Common.Services
} }
} }
public void CheckUpdaterLock()
{
// check .lock file to detect errors in the update process
var lockFilePath = Path.Combine(Path.GetDirectoryName(ExePath()), ".lock");
if (File.Exists(lockFilePath))
{
logger.Error("An error occurred during the last update. If this error occurs again, you need to reinstall " +
"Jackett following the documentation. If the problem continues after reinstalling, " +
"report the issue and attach the Jackett and Updater logs.");
File.Delete(lockFilePath);
}
}
private async Task<string> DownloadRelease(List<Asset> assets, bool isWindows, string version) private async Task<string> DownloadRelease(List<Asset> assets, bool isWindows, string version)
{ {
var variants = new Variants(); var variants = new Variants();
@@ -378,6 +388,11 @@ namespace Jackett.Common.Services
startInfo.Arguments += " --StartTray"; startInfo.Arguments += " --StartTray";
} }
// create .lock file to detect errors in the update process
var lockFilePath = Path.Combine(installLocation, ".lock");
if (!File.Exists(lockFilePath))
File.Create(lockFilePath).Dispose();
logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}"); logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}");
var procInfo = Process.Start(startInfo); var procInfo = Process.Start(startInfo);
logger.Info($"Updater started process id: {procInfo.Id}"); logger.Info($"Updater started process id: {procInfo.Id}");

View File

@@ -333,10 +333,13 @@ namespace Jackett.Server.Services
} }
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
// Load indexers // Load indexers
indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders()); indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders());
client.Init(); client.Init();
updater.CleanupTempDir(); updater.CleanupTempDir();
updater.CheckUpdaterLock();
} }
public void Start() => updater.StartUpdateChecker(); public void Start() => updater.StartUpdateChecker();

View File

@@ -424,6 +424,11 @@ namespace Jackett.Updater
} }
} }
// remove .lock file to detect errors in the update process
var lockFilePath = Path.Combine(options.Path, ".lock");
if (File.Exists(lockFilePath))
File.Delete(lockFilePath);
// kill pids after the update on UNIX // kill pids after the update on UNIX
if (!isWindows) if (!isWindows)
KillPids(pids); KillPids(pids);