public void Initalize() { try { var x = Environment.OSVersion; var runtimedir = RuntimeEnvironment.GetRuntimeDirectory(); logger.Info("Environment version: " + Environment.Version.ToString() + " (" + runtimedir + ")"); logger.Info("OS version: " + Environment.OSVersion.ToString() + (Environment.Is64BitOperatingSystem ? " (64bit OS)" : "") + (Environment.Is64BitProcess ? " (64bit process)" : "")); Variants variants = new Variants(); Variants.JackettVariant variant = variants.GetVariant(); logger.Info("Jackett variant: " + variant.ToString()); try { ThreadPool.GetMaxThreads(out int workerThreads, out int completionPortThreads); logger.Info("ThreadPool MaxThreads: " + workerThreads + " workerThreads, " + completionPortThreads + " completionPortThreads"); } catch (Exception e) { logger.Error("Error while getting MaxThreads details: " + e); } logger.Info("App config/log directory: " + configService.GetAppDataFolder()); try { var issuefile = "/etc/issue"; if (File.Exists(issuefile)) { using (StreamReader reader = new StreamReader(issuefile)) { string firstLine = reader.ReadLine(); if (firstLine != null) { logger.Info("issue: " + firstLine); } } } } catch (Exception e) { logger.Error(e, "Error while reading the issue file"); } Type monotype = Type.GetType("Mono.Runtime"); if (monotype != null && !DotNetCoreUtil.IsRunningOnDotNetCore) { MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); var monoVersion = "unknown"; if (displayName != null) { monoVersion = displayName.Invoke(null, null).ToString(); } logger.Info("mono version: " + monoVersion); var monoVersionO = new Version(monoVersion.Split(' ')[0]); if (monoVersionO.Major < 5 || (monoVersionO.Major == 5 && monoVersionO.Minor < 8)) { //Hard minimum of 5.8 //5.4 throws a SIGABRT, looks related to this which was fixed in 5.8 https://bugzilla.xamarin.com/show_bug.cgi?id=60625 logger.Error("Your mono version is too old. Please update to the latest version from http://www.mono-project.com/download/"); Environment.Exit(2); } if (monoVersionO.Major < 5 || (monoVersionO.Major == 5 && monoVersionO.Minor < 8)) { string notice = "A minimum Mono version of 5.8 is required. Please update to the latest version from http://www.mono-project.com/download/"; _notices.Add(notice); logger.Error(notice); } try { // Check for mono-devel // Is there any better way which doesn't involve a hard cashes? var mono_devel_file = Path.Combine(runtimedir, "mono-api-info.exe"); if (!File.Exists(mono_devel_file)) { var notice = "It looks like the mono-devel package is not installed, please make sure it's installed to avoid crashes."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking for mono-devel"); } try { // Check for ca-certificates-mono var mono_cert_file = Path.Combine(runtimedir, "cert-sync.exe"); if (!File.Exists(mono_cert_file)) { var notice = "The ca-certificates-mono package is not installed, HTTPS trackers won't work. Please install it."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking for ca-certificates-mono"); } try { Encoding.GetEncoding("windows-1255"); } catch (NotSupportedException e) { logger.Debug(e); logger.Error(e.Message + " Most likely the mono-locale-extras package is not installed."); Environment.Exit(2); } // check if the certificate store was initialized using Mono.Security.X509.X509StoreManager.TrustedRootCertificates.Count try { var monoSecurity = Assembly.Load("Mono.Security"); Type monoX509StoreManager = monoSecurity.GetType("Mono.Security.X509.X509StoreManager"); if (monoX509StoreManager != null) { var TrustedRootCertificatesProperty = monoX509StoreManager.GetProperty("TrustedRootCertificates"); var TrustedRootCertificates = (ICollection)TrustedRootCertificatesProperty.GetValue(null); logger.Info("TrustedRootCertificates count: " + TrustedRootCertificates.Count); if (TrustedRootCertificates.Count == 0) { var CACertificatesFiles = new string[] { "/etc/ssl/certs/ca-certificates.crt", // Debian based "/etc/pki/tls/certs/ca-bundle.c", // RedHat based "/etc/ssl/ca-bundle.pem", // SUSE }; var notice = "The mono certificate store is not initialized.<br/>\n"; var logSpacer = " "; var CACertificatesFile = CACertificatesFiles.Where(f => File.Exists(f)).FirstOrDefault(); var CommandRoot = "curl -sS https://curl.haxx.se/ca/cacert.pem | cert-sync /dev/stdin"; var CommandUser = "******"; if (CACertificatesFile != null) { CommandRoot = "cert-sync " + CACertificatesFile; CommandUser = "******" + CACertificatesFile; } notice += logSpacer + "Please run the following command as root:<br/>\n"; notice += logSpacer + "<pre>" + CommandRoot + "</pre><br/>\n"; notice += logSpacer + "If you don't have root access or you're running MacOS, please run the following command as the jackett user (" + Environment.UserName + "):<br/>\n"; notice += logSpacer + "<pre>" + CommandUser + "</pre>"; _notices.Add(notice); logger.Error(Regex.Replace(notice, "<.*?>", String.Empty)); } } } catch (Exception e) { logger.Error(e, "Error while chekcing the mono certificate store"); } } } catch (Exception e) { logger.Error("Error while getting environment details: " + e); } try { if (Environment.UserName == "root") { var notice = "Jackett is running with root privileges. You should run Jackett as an unprivileged user."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking the username"); } //Warn user that they are using an old version of Jackett try { DateTime compiledData = BuildDate.GetBuildDateTime(); if (compiledData < DateTime.Now.AddMonths(-3)) { string version = configService.GetVersion(); string notice = $"Your version of Jackett v{version} is very old. Multiple indexers are likely to fail when using an old version. Update to the latest version of Jackett."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking build date of Jackett.Common"); } CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Load indexers indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders()); client.Init(); updater.CleanupTempDir(); }
public void Initalize() { logger.Info("Starting Jackett " + configService.GetVersion()); try { var x = Environment.OSVersion; var runtimedir = RuntimeEnvironment.GetRuntimeDirectory(); logger.Info("Environment version: " + Environment.Version.ToString() + " (" + runtimedir + ")"); logger.Info("OS version: " + Environment.OSVersion.ToString() + (Environment.Is64BitOperatingSystem ? " (64bit OS)" : "") + (Environment.Is64BitProcess ? " (64bit process)" : "")); try { int workerThreads; int completionPortThreads; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); logger.Info("ThreadPool MaxThreads: " + workerThreads + " workerThreads, " + completionPortThreads + " completionPortThreads"); } catch (Exception e) { logger.Error("Error while getting MaxThreads details: " + e); } try { var issuefile = "/etc/issue"; if (File.Exists(issuefile)) { using (StreamReader reader = new StreamReader(issuefile)) { string firstLine; firstLine = reader.ReadLine(); if (firstLine != null) { logger.Info("issue: " + firstLine); } } } } catch (Exception e) { logger.Error(e, "Error while reading the issue file"); } Type monotype = Type.GetType("Mono.Runtime"); if (monotype != null) { MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); var monoVersion = "unknown"; if (displayName != null) { monoVersion = displayName.Invoke(null, null).ToString(); } logger.Info("mono version: " + monoVersion); var monoVersionO = new Version(monoVersion.Split(' ')[0]); if (monoVersionO.Major < 4) { logger.Error("Your mono version is to old (mono 3 is no longer supported). Please update to the latest version from http://www.mono-project.com/download/"); Engine.Exit(2); } else if (monoVersionO.Major == 4 && monoVersionO.Minor == 2) { var notice = "mono version 4.2.* is known to cause problems with Jackett. If you experience any problems please try updating to the latest mono version from http://www.mono-project.com/download/ first."; _notices.Add(notice); logger.Error(notice); } try { // Check for mono-devel // Is there any better way which doesn't involve a hard cashes? var mono_devel_file = Path.Combine(runtimedir, "mono-api-info.exe"); if (!File.Exists(mono_devel_file)) { var notice = "It looks like the mono-devel package is not installed, please make sure it's installed to avoid crashes."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking for mono-devel"); } try { // Check for ca-certificates-mono var mono_cert_file = Path.Combine(runtimedir, "cert-sync.exe"); if (!File.Exists(mono_cert_file)) { if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5) { var notice = "The ca-certificates-mono package is not installed, HTTPS trackers won't work. Please install it."; _notices.Add(notice); logger.Error(notice); } else { logger.Info("The ca-certificates-mono package is not installed, it will become mandatory once mono >= 4.8 is used."); } } } catch (Exception e) { logger.Error(e, "Error while checking for ca-certificates-mono"); } try { Encoding.GetEncoding("windows-1255"); } catch (NotSupportedException e) { logger.Debug(e); logger.Error(e.Message + " Most likely the mono-locale-extras package is not installed."); Engine.Exit(2); } if (Engine.WebClientType == typeof(HttpWebClient) || Engine.WebClientType == typeof(HttpWebClient2)) { // check if the certificate store was initialized using Mono.Security.X509.X509StoreManager.TrustedRootCertificates.Count try { var monoSecurity = Assembly.Load("Mono.Security"); Type monoX509StoreManager = monoSecurity.GetType("Mono.Security.X509.X509StoreManager"); if (monoX509StoreManager != null) { var TrustedRootCertificatesProperty = monoX509StoreManager.GetProperty("TrustedRootCertificates"); var TrustedRootCertificates = (ICollection)TrustedRootCertificatesProperty.GetValue(null); logger.Info("TrustedRootCertificates count: " + TrustedRootCertificates.Count); if (TrustedRootCertificates.Count == 0) { var CACertificatesFiles = new string[] { "/etc/ssl/certs/ca-certificates.crt", // Debian based "/etc/pki/tls/certs/ca-bundle.c", // RedHat based "/etc/ssl/ca-bundle.pem", // SUSE }; var notice = "The mono certificate store is not initialized.<br/>\n"; var logSpacer = " "; var CACertificatesFile = CACertificatesFiles.Where(f => File.Exists(f)).FirstOrDefault(); var CommandRoot = "curl -sS https://curl.haxx.se/ca/cacert.pem | cert-sync /dev/stdin"; var CommandUser = "******"; if (CACertificatesFile != null) { CommandRoot = "cert-sync " + CACertificatesFile; CommandUser = "******" + CACertificatesFile; } notice += logSpacer + "Please run the following command as root:<br/>\n"; notice += logSpacer + "<pre>" + CommandRoot + "</pre><br/>\n"; notice += logSpacer + "If you don't have root access or you're running MacOS, please run the following command as the jackett user (" + Environment.UserName + "):<br/>\n"; notice += logSpacer + "<pre>" + CommandUser + "</pre>"; _notices.Add(notice); logger.Error(Regex.Replace(notice, "<.*?>", String.Empty)); } } } catch (Exception e) { logger.Error(e, "Error while chekcing the mono certificate store"); } } } } catch (Exception e) { logger.Error("Error while getting environment details: " + e); } try { if (Environment.UserName == "root") { var notice = "Jackett is running with root privileges. You should run Jackett as an unprivileged user."; _notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error(e, "Error while checking the username"); } CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Load indexers indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders()); client.Init(); updater.CleanupTempDir(); }
public void Initalize() { try { var x = Environment.OSVersion; var runtimedir = RuntimeEnvironment.GetRuntimeDirectory(); logger.Info($"Environment version: {Environment.Version} ({runtimedir})"); logger.Info($"OS version: {Environment.OSVersion}" + (Environment.Is64BitOperatingSystem ? " (64bit OS)" : "") + (Environment.Is64BitProcess ? " (64bit process)" : "")); var variants = new Variants(); var variant = variants.GetVariant(); logger.Info($"Jackett variant: {variant}"); try { var issueFile = "/etc/issue"; if (File.Exists(issueFile)) { using (var reader = new StreamReader(issueFile)) { var firstLine = reader.ReadLine(); if (firstLine != null) { logger.Info($"File {issueFile}: {firstLine}"); } } } } catch (Exception e) { logger.Error($"Error while reading the issue file\n{e}"); } try { var dockerMsg = "No"; const string cgroupFile = "/proc/1/cgroup"; if ((File.Exists(cgroupFile) && File.ReadAllText(cgroupFile).Contains("/docker/")) || File.Exists("/.dockerenv")) { // this file is created in the Docker image build // https://github.com/linuxserver/docker-jackett/pull/105 const string dockerImageFile = "/etc/docker-image"; dockerMsg = File.Exists(dockerImageFile) ? "Yes (image build: " + File.ReadAllText(dockerImageFile).Trim() + ")" : "Yes (image build: unknown)"; } logger.Info($"Running in Docker: {dockerMsg}"); } catch (Exception e) { logger.Error($"Error while reading the Docker cgroup file.\n{e}"); } try { ThreadPool.GetMaxThreads(out var workerThreads, out var completionPortThreads); logger.Info( "ThreadPool MaxThreads: " + workerThreads + " workerThreads, " + completionPortThreads + " completionPortThreads"); } catch (Exception e) { logger.Error("Error while getting MaxThreads details: " + e); } logger.Info("App config/log directory: " + configService.GetAppDataFolder()); logger.Info($"Using proxy: {config.ProxyType}"); logger.Info("Using FlareSolverr: " + (string.IsNullOrEmpty(config.FlareSolverrUrl) ? "No" : config.FlareSolverrUrl)); var monotype = Type.GetType("Mono.Runtime"); if (monotype != null && !DotNetCoreUtil.IsRunningOnDotNetCore) { var displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); var monoVersion = "unknown"; if (displayName != null) { monoVersion = displayName.Invoke(null, null).ToString(); } logger.Info("Mono version: " + monoVersion); var monoVersionO = new Version(monoVersion.Split(' ')[0]); if (monoVersionO.Major < 5 || (monoVersionO.Major == 5 && monoVersionO.Minor < 8)) { //Hard minimum of 5.8 //5.4 throws a SIGABRT, looks related to this which was fixed in 5.8 https://bugzilla.xamarin.com/show_bug.cgi?id=60625 logger.Error( "Your Mono version is too old. Please update to the latest version from http://www.mono-project.com/download/"); Environment.Exit(2); } if (monoVersionO.Major < 5 || (monoVersionO.Major == 5 && monoVersionO.Minor < 8)) { const string notice = "A minimum Mono version of 5.8 is required. Please update to the latest version from http://www.mono-project.com/download/"; notices.Add(notice); logger.Error(notice); } try { // Check for mono-devel // Is there any better way which doesn't involve a hard cashes? var monoDevelFile = Path.Combine(runtimedir, "mono-api-info.exe"); if (!File.Exists(monoDevelFile)) { const string notice = "It looks like the mono-devel package is not installed, please make sure it's installed to avoid crashes."; notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error($"Error while checking for mono-devel.\n{e}"); } try { // Check for ca-certificates-mono var monoCertFile = Path.Combine(runtimedir, "cert-sync.exe"); if (!File.Exists(monoCertFile)) { const string notice = "The ca-certificates-mono package is not installed, HTTPS trackers won't work. Please install it."; notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error($"Error while checking for ca-certificates-mono.\n{e}"); } try { Encoding.GetEncoding("windows-1255"); } catch (NotSupportedException e) { logger.Error($"Most likely the mono-locale-extras package is not installed.\n{e}"); Environment.Exit(2); } if (monoVersionO.Major < 6) { //We don't check on Mono 6 since Mono.Security was removed // check if the certificate store was initialized using Mono.Security.X509.X509StoreManager.TrustedRootCertificates.Count try { var monoSecurity = Assembly.Load("Mono.Security"); var monoX509StoreManager = monoSecurity.GetType("Mono.Security.X509.X509StoreManager"); if (monoX509StoreManager != null) { var trustedRootCertificatesProperty = monoX509StoreManager.GetProperty("TrustedRootCertificates"); var trustedRootCertificates = (ICollection)trustedRootCertificatesProperty.GetValue(null); logger.Info($"TrustedRootCertificates count: {trustedRootCertificates.Count}"); if (trustedRootCertificates.Count == 0) { var caCertificatesFiles = new[] { "/etc/ssl/certs/ca-certificates.crt", // Debian based "/etc/pki/tls/certs/ca-bundle.c", // RedHat based "/etc/ssl/ca-bundle.pem", // SUSE }; const string logSpacer = " "; var notice = "The mono certificate store is not initialized.<br/>\n"; var caCertificatesFile = caCertificatesFiles.Where(File.Exists).FirstOrDefault(); var commandRoot = "curl -sS https://curl.haxx.se/ca/cacert.pem | cert-sync /dev/stdin"; var commandUser = "******"; if (caCertificatesFile != null) { commandRoot = "cert-sync " + caCertificatesFile; commandUser = "******" + caCertificatesFile; } notice += logSpacer + "Please run the following command as root:<br/>\n"; notice += logSpacer + "<pre>" + commandRoot + "</pre><br/>\n"; notice += logSpacer + "If you don't have root access or you're running MacOS, please run the following command as the jackett user (" + Environment.UserName + "):<br/>\n"; notice += logSpacer + "<pre>" + commandUser + "</pre>"; notices.Add(notice); logger.Error(Regex.Replace(notice, "<.*?>", string.Empty)); } } } catch (Exception e) { logger.Error($"Error while chekcing the mono certificate store.\n{e}"); } } } } catch (Exception e) { logger.Error("Error while getting environment details: " + e); } try { if (Environment.UserName == "root") { var notice = "Jackett is running with root privileges. You should run Jackett as an unprivileged user."; notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error($"Error while checking the username.\n{e}"); } //Warn user that they are using an old version of Jackett try { var compiledData = BuildDate.GetBuildDateTime(); if (compiledData < DateTime.Now.AddMonths(-3)) { var version = configService.GetVersion(); var notice = $"Your version of Jackett {version} is very old. Multiple indexers are likely to fail when using an old version. Update to the latest version of Jackett."; notices.Add(notice); logger.Error(notice); } } catch (Exception e) { logger.Error($"Error while checking build date of Jackett.Common.\n{e}"); } //Alert user that they no longer need to use Mono try { var variants = new Variants(); var variant = variants.GetVariant(); if (variant == Variants.JackettVariant.Mono) { var process = new Process { StartInfo = { FileName = "uname", Arguments = "-m", UseShellExecute = false, RedirectStandardOutput = true } }; process.Start(); var output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); logger.Debug($"uname output was: {output}"); output = output.ToLower(); if (output.Contains("armv7") || output.Contains("armv8") || output.Contains("x86_64")) { isDotNetCoreCapable = true; } } } catch (Exception e) { logger.Debug($"Unable to get architecture.\n{e}"); } CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Load indexers indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders()); client.Init(); updater.CleanupTempDir(); updater.CheckUpdaterLock(); }