Program.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. using System;
  2. using System.Diagnostics;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Reflection;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using CommandLine;
  14. using Emby.Drawing;
  15. using Emby.Server.Implementations;
  16. using Emby.Server.Implementations.HttpServer;
  17. using Emby.Server.Implementations.IO;
  18. using Emby.Server.Implementations.Networking;
  19. using Jellyfin.Drawing.Skia;
  20. using MediaBrowser.Common.Configuration;
  21. using MediaBrowser.Controller.Drawing;
  22. using MediaBrowser.Controller.Extensions;
  23. using Microsoft.AspNetCore.Hosting;
  24. using Microsoft.Extensions.Configuration;
  25. using Microsoft.Extensions.DependencyInjection;
  26. using Microsoft.Extensions.DependencyInjection.Extensions;
  27. using Microsoft.Extensions.Logging;
  28. using Microsoft.Extensions.Logging.Abstractions;
  29. using Serilog;
  30. using Serilog.Events;
  31. using Serilog.Extensions.Logging;
  32. using SQLitePCL;
  33. using ILogger = Microsoft.Extensions.Logging.ILogger;
  34. namespace Jellyfin.Server
  35. {
  36. /// <summary>
  37. /// Class containing the entry point of the application.
  38. /// </summary>
  39. public static class Program
  40. {
  41. /// <summary>
  42. /// The name of logging configuration file containing application defaults.
  43. /// </summary>
  44. public static readonly string LoggingConfigFileDefault = "logging.default.json";
  45. /// <summary>
  46. /// The name of the logging configuration file containing the system-specific override settings.
  47. /// </summary>
  48. public static readonly string LoggingConfigFileSystem = "logging.json";
  49. private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource();
  50. private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory();
  51. private static ILogger _logger = NullLogger.Instance;
  52. private static bool _restartOnShutdown;
  53. /// <summary>
  54. /// The entry point of the application.
  55. /// </summary>
  56. /// <param name="args">The command line arguments passed.</param>
  57. /// <returns><see cref="Task" />.</returns>
  58. public static Task Main(string[] args)
  59. {
  60. // For backwards compatibility.
  61. // Modify any input arguments now which start with single-hyphen to POSIX standard
  62. // double-hyphen to allow parsing by CommandLineParser package.
  63. const string Pattern = @"^(-[^-\s]{2})"; // Match -xx, not -x, not --xx, not xx
  64. const string Substitution = @"-$1"; // Prepend with additional single-hyphen
  65. var regex = new Regex(Pattern);
  66. for (var i = 0; i < args.Length; i++)
  67. {
  68. args[i] = regex.Replace(args[i], Substitution);
  69. }
  70. // Parse the command line arguments and either start the app or exit indicating error
  71. return Parser.Default.ParseArguments<StartupOptions>(args)
  72. .MapResult(StartApp, _ => Task.CompletedTask);
  73. }
  74. /// <summary>
  75. /// Shuts down the application.
  76. /// </summary>
  77. internal static void Shutdown()
  78. {
  79. if (!_tokenSource.IsCancellationRequested)
  80. {
  81. _tokenSource.Cancel();
  82. }
  83. }
  84. /// <summary>
  85. /// Restarts the application.
  86. /// </summary>
  87. internal static void Restart()
  88. {
  89. _restartOnShutdown = true;
  90. Shutdown();
  91. }
  92. private static async Task StartApp(StartupOptions options)
  93. {
  94. var stopWatch = new Stopwatch();
  95. stopWatch.Start();
  96. // Log all uncaught exceptions to std error
  97. static void UnhandledExceptionToConsole(object sender, UnhandledExceptionEventArgs e) =>
  98. Console.Error.WriteLine("Unhandled Exception\n" + e.ExceptionObject.ToString());
  99. AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionToConsole;
  100. ServerApplicationPaths appPaths = CreateApplicationPaths(options);
  101. // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
  102. Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);
  103. // Create an instance of the application configuration to use for application startup
  104. await InitLoggingConfigFile(appPaths).ConfigureAwait(false);
  105. IConfiguration startupConfig = CreateAppConfiguration(appPaths);
  106. // Initialize logging framework
  107. InitializeLoggingFramework(startupConfig, appPaths);
  108. _logger = _loggerFactory.CreateLogger("Main");
  109. // Log uncaught exceptions to the logging instead of std error
  110. AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionToConsole;
  111. AppDomain.CurrentDomain.UnhandledException += (sender, e)
  112. => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");
  113. // Intercept Ctrl+C and Ctrl+Break
  114. Console.CancelKeyPress += (sender, e) =>
  115. {
  116. if (_tokenSource.IsCancellationRequested)
  117. {
  118. return; // Already shutting down
  119. }
  120. e.Cancel = true;
  121. _logger.LogInformation("Ctrl+C, shutting down");
  122. Environment.ExitCode = 128 + 2;
  123. Shutdown();
  124. };
  125. // Register a SIGTERM handler
  126. AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
  127. {
  128. if (_tokenSource.IsCancellationRequested)
  129. {
  130. return; // Already shutting down
  131. }
  132. _logger.LogInformation("Received a SIGTERM signal, shutting down");
  133. Environment.ExitCode = 128 + 15;
  134. Shutdown();
  135. };
  136. _logger.LogInformation(
  137. "Jellyfin version: {Version}",
  138. Assembly.GetEntryAssembly()!.GetName().Version!.ToString(3));
  139. ApplicationHost.LogEnvironmentInfo(_logger, appPaths);
  140. // Make sure we have all the code pages we can get
  141. // Ref: https://docs.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider.instance?view=netcore-3.0#remarks
  142. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  143. // Increase the max http request limit
  144. // The default connection limit is 10 for ASP.NET hosted applications and 2 for all others.
  145. ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);
  146. // Disable the "Expect: 100-Continue" header by default
  147. // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
  148. ServicePointManager.Expect100Continue = false;
  149. Batteries_V2.Init();
  150. if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
  151. {
  152. _logger.LogWarning("Failed to enable shared cache for SQLite");
  153. }
  154. var appHost = new CoreAppHost(
  155. appPaths,
  156. _loggerFactory,
  157. options,
  158. new ManagedFileSystem(_loggerFactory.CreateLogger<ManagedFileSystem>(), appPaths),
  159. GetImageEncoder(appPaths),
  160. new NetworkManager(_loggerFactory.CreateLogger<NetworkManager>()));
  161. try
  162. {
  163. ServiceCollection serviceCollection = new ServiceCollection();
  164. await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false);
  165. var webHost = CreateWebHostBuilder(appHost, serviceCollection, startupConfig, appPaths).Build();
  166. // A bit hacky to re-use service provider since ASP.NET doesn't allow a custom service collection.
  167. appHost.ServiceProvider = webHost.Services;
  168. appHost.FindParts();
  169. Migrations.MigrationRunner.Run(appHost, _loggerFactory);
  170. try
  171. {
  172. await webHost.StartAsync().ConfigureAwait(false);
  173. }
  174. catch
  175. {
  176. _logger.LogError("Kestrel failed to start! This is most likely due to an invalid address or port bind - correct your bind configuration in system.xml and try again.");
  177. throw;
  178. }
  179. await appHost.RunStartupTasksAsync().ConfigureAwait(false);
  180. stopWatch.Stop();
  181. _logger.LogInformation("Startup complete {Time:g}", stopWatch.Elapsed);
  182. // Block main thread until shutdown
  183. await Task.Delay(-1, _tokenSource.Token).ConfigureAwait(false);
  184. }
  185. catch (TaskCanceledException)
  186. {
  187. // Don't throw on cancellation
  188. }
  189. catch (Exception ex)
  190. {
  191. _logger.LogCritical(ex, "Error while starting server.");
  192. }
  193. finally
  194. {
  195. appHost?.Dispose();
  196. }
  197. if (_restartOnShutdown)
  198. {
  199. StartNewInstance(options);
  200. }
  201. }
  202. private static IWebHostBuilder CreateWebHostBuilder(
  203. ApplicationHost appHost,
  204. IServiceCollection serviceCollection,
  205. IConfiguration startupConfig,
  206. IApplicationPaths appPaths)
  207. {
  208. var webhostBuilder = new WebHostBuilder()
  209. .UseKestrel(options =>
  210. {
  211. var addresses = appHost.ServerConfigurationManager
  212. .Configuration
  213. .LocalNetworkAddresses
  214. .Select(appHost.NormalizeConfiguredLocalAddress)
  215. .Where(i => i != null)
  216. .ToList();
  217. if (addresses.Any())
  218. {
  219. foreach (var address in addresses)
  220. {
  221. _logger.LogInformation("Kestrel listening on {IpAddress}", address);
  222. options.Listen(address, appHost.HttpPort);
  223. if (appHost.EnableHttps && appHost.Certificate != null)
  224. {
  225. options.Listen(
  226. address,
  227. appHost.HttpsPort,
  228. listenOptions => listenOptions.UseHttps(appHost.Certificate));
  229. }
  230. }
  231. }
  232. else
  233. {
  234. _logger.LogInformation("Kestrel listening on all interfaces");
  235. options.ListenAnyIP(appHost.HttpPort);
  236. if (appHost.EnableHttps && appHost.Certificate != null)
  237. {
  238. options.ListenAnyIP(
  239. appHost.HttpsPort,
  240. listenOptions => listenOptions.UseHttps(appHost.Certificate));
  241. }
  242. }
  243. })
  244. .ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(appPaths, startupConfig))
  245. .UseSerilog()
  246. .ConfigureServices(services =>
  247. {
  248. // Merge the external ServiceCollection into ASP.NET DI
  249. services.TryAdd(serviceCollection);
  250. })
  251. .UseStartup<Startup>();
  252. // Set up static content hosting unless it has been disabled via config
  253. if (!startupConfig.NoWebContent())
  254. {
  255. // Fail startup if the web content does not exist
  256. if (!Directory.Exists(appHost.ContentRoot) || !Directory.GetFiles(appHost.ContentRoot).Any())
  257. {
  258. throw new InvalidOperationException(
  259. "The server is expected to host web content, but the provided content directory is either " +
  260. $"invalid or empty: {appHost.ContentRoot}. If you do not want to host web content with the " +
  261. $"server, you may set the '{MediaBrowser.Controller.Extensions.ConfigurationExtensions.NoWebContentKey}' flag.");
  262. }
  263. // Configure the web host to host the static web content
  264. webhostBuilder.UseContentRoot(appHost.ContentRoot);
  265. }
  266. return webhostBuilder;
  267. }
  268. /// <summary>
  269. /// Create the data, config and log paths from the variety of inputs(command line args,
  270. /// environment variables) or decide on what default to use. For Windows it's %AppPath%
  271. /// for everything else the
  272. /// <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG approach</a>
  273. /// is followed.
  274. /// </summary>
  275. /// <param name="options">The <see cref="StartupOptions" /> for this instance.</param>
  276. /// <returns><see cref="ServerApplicationPaths" />.</returns>
  277. private static ServerApplicationPaths CreateApplicationPaths(StartupOptions options)
  278. {
  279. // dataDir
  280. // IF --datadir
  281. // ELSE IF $JELLYFIN_DATA_DIR
  282. // ELSE IF windows, use <%APPDATA%>/jellyfin
  283. // ELSE IF $XDG_DATA_HOME then use $XDG_DATA_HOME/jellyfin
  284. // ELSE use $HOME/.local/share/jellyfin
  285. var dataDir = options.DataDir;
  286. if (string.IsNullOrEmpty(dataDir))
  287. {
  288. dataDir = Environment.GetEnvironmentVariable("JELLYFIN_DATA_DIR");
  289. if (string.IsNullOrEmpty(dataDir))
  290. {
  291. // LocalApplicationData follows the XDG spec on unix machines
  292. dataDir = Path.Combine(
  293. Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
  294. "jellyfin");
  295. }
  296. }
  297. // configDir
  298. // IF --configdir
  299. // ELSE IF $JELLYFIN_CONFIG_DIR
  300. // ELSE IF --datadir, use <datadir>/config (assume portable run)
  301. // ELSE IF <datadir>/config exists, use that
  302. // ELSE IF windows, use <datadir>/config
  303. // ELSE IF $XDG_CONFIG_HOME use $XDG_CONFIG_HOME/jellyfin
  304. // ELSE $HOME/.config/jellyfin
  305. var configDir = options.ConfigDir;
  306. if (string.IsNullOrEmpty(configDir))
  307. {
  308. configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");
  309. if (string.IsNullOrEmpty(configDir))
  310. {
  311. if (options.DataDir != null
  312. || Directory.Exists(Path.Combine(dataDir, "config"))
  313. || RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  314. {
  315. // Hang config folder off already set dataDir
  316. configDir = Path.Combine(dataDir, "config");
  317. }
  318. else
  319. {
  320. // $XDG_CONFIG_HOME defines the base directory relative to which
  321. // user specific configuration files should be stored.
  322. configDir = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
  323. // If $XDG_CONFIG_HOME is either not set or empty,
  324. // a default equal to $HOME /.config should be used.
  325. if (string.IsNullOrEmpty(configDir))
  326. {
  327. configDir = Path.Combine(
  328. Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
  329. ".config");
  330. }
  331. configDir = Path.Combine(configDir, "jellyfin");
  332. }
  333. }
  334. }
  335. // cacheDir
  336. // IF --cachedir
  337. // ELSE IF $JELLYFIN_CACHE_DIR
  338. // ELSE IF windows, use <datadir>/cache
  339. // ELSE IF XDG_CACHE_HOME, use $XDG_CACHE_HOME/jellyfin
  340. // ELSE HOME/.cache/jellyfin
  341. var cacheDir = options.CacheDir;
  342. if (string.IsNullOrEmpty(cacheDir))
  343. {
  344. cacheDir = Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR");
  345. if (string.IsNullOrEmpty(cacheDir))
  346. {
  347. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  348. {
  349. // Hang cache folder off already set dataDir
  350. cacheDir = Path.Combine(dataDir, "cache");
  351. }
  352. else
  353. {
  354. // $XDG_CACHE_HOME defines the base directory relative to which
  355. // user specific non-essential data files should be stored.
  356. cacheDir = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
  357. // If $XDG_CACHE_HOME is either not set or empty,
  358. // a default equal to $HOME/.cache should be used.
  359. if (string.IsNullOrEmpty(cacheDir))
  360. {
  361. cacheDir = Path.Combine(
  362. Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
  363. ".cache");
  364. }
  365. cacheDir = Path.Combine(cacheDir, "jellyfin");
  366. }
  367. }
  368. }
  369. // webDir
  370. // IF --webdir
  371. // ELSE IF $JELLYFIN_WEB_DIR
  372. // ELSE <bindir>/jellyfin-web
  373. var webDir = options.WebDir;
  374. if (string.IsNullOrEmpty(webDir))
  375. {
  376. webDir = Environment.GetEnvironmentVariable("JELLYFIN_WEB_DIR");
  377. if (string.IsNullOrEmpty(webDir))
  378. {
  379. // Use default location under ResourcesPath
  380. webDir = Path.Combine(AppContext.BaseDirectory, "jellyfin-web");
  381. }
  382. }
  383. // logDir
  384. // IF --logdir
  385. // ELSE IF $JELLYFIN_LOG_DIR
  386. // ELSE IF --datadir, use <datadir>/log (assume portable run)
  387. // ELSE <datadir>/log
  388. var logDir = options.LogDir;
  389. if (string.IsNullOrEmpty(logDir))
  390. {
  391. logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
  392. if (string.IsNullOrEmpty(logDir))
  393. {
  394. // Hang log folder off already set dataDir
  395. logDir = Path.Combine(dataDir, "log");
  396. }
  397. }
  398. // Ensure the main folders exist before we continue
  399. try
  400. {
  401. Directory.CreateDirectory(dataDir);
  402. Directory.CreateDirectory(logDir);
  403. Directory.CreateDirectory(configDir);
  404. Directory.CreateDirectory(cacheDir);
  405. }
  406. catch (IOException ex)
  407. {
  408. Console.Error.WriteLine("Error whilst attempting to create folder");
  409. Console.Error.WriteLine(ex.ToString());
  410. Environment.Exit(1);
  411. }
  412. return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir, webDir);
  413. }
  414. /// <summary>
  415. /// Initialize the logging configuration file using the bundled resource file as a default if it doesn't exist
  416. /// already.
  417. /// </summary>
  418. private static async Task InitLoggingConfigFile(IApplicationPaths appPaths)
  419. {
  420. // Do nothing if the config file already exists
  421. string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, LoggingConfigFileDefault);
  422. if (File.Exists(configPath))
  423. {
  424. return;
  425. }
  426. // Get a stream of the resource contents
  427. // NOTE: The .csproj name is used instead of the assembly name in the resource path
  428. const string ResourcePath = "Jellyfin.Server.Resources.Configuration.logging.json";
  429. await using Stream? resource = typeof(Program).Assembly.GetManifestResourceStream(ResourcePath)
  430. ?? throw new InvalidOperationException($"Invalid resource path: '{ResourcePath}'");
  431. // Copy the resource contents to the expected file path for the config file
  432. await using Stream dst = File.Open(configPath, FileMode.CreateNew);
  433. await resource.CopyToAsync(dst).ConfigureAwait(false);
  434. }
  435. private static IConfiguration CreateAppConfiguration(IApplicationPaths appPaths)
  436. {
  437. return new ConfigurationBuilder()
  438. .ConfigureAppConfiguration(appPaths)
  439. .Build();
  440. }
  441. private static IConfigurationBuilder ConfigureAppConfiguration(this IConfigurationBuilder config, IApplicationPaths appPaths, IConfiguration? startupConfig = null)
  442. {
  443. // Use the swagger API page as the default redirect path if not hosting the jellyfin-web content
  444. var inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration;
  445. if (startupConfig != null && startupConfig.NoWebContent())
  446. {
  447. inMemoryDefaultConfig[HttpListenerHost.DefaultRedirectKey] = "swagger/index.html";
  448. }
  449. return config
  450. .SetBasePath(appPaths.ConfigurationDirectoryPath)
  451. .AddInMemoryCollection(inMemoryDefaultConfig)
  452. .AddJsonFile(LoggingConfigFileDefault, optional: false, reloadOnChange: true)
  453. .AddJsonFile(LoggingConfigFileSystem, optional: true, reloadOnChange: true)
  454. .AddEnvironmentVariables("JELLYFIN_");
  455. }
  456. /// <summary>
  457. /// Initialize Serilog using configuration and fall back to defaults on failure.
  458. /// </summary>
  459. private static void InitializeLoggingFramework(IConfiguration configuration, IApplicationPaths appPaths)
  460. {
  461. try
  462. {
  463. // Serilog.Log is used by SerilogLoggerFactory when no logger is specified
  464. Serilog.Log.Logger = new LoggerConfiguration()
  465. .ReadFrom.Configuration(configuration)
  466. .Enrich.FromLogContext()
  467. .Enrich.WithThreadId()
  468. .CreateLogger();
  469. }
  470. catch (Exception ex)
  471. {
  472. Serilog.Log.Logger = new LoggerConfiguration()
  473. .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}")
  474. .WriteTo.Async(x => x.File(
  475. Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
  476. rollingInterval: RollingInterval.Day,
  477. outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message}{NewLine}{Exception}"))
  478. .Enrich.FromLogContext()
  479. .Enrich.WithThreadId()
  480. .CreateLogger();
  481. Serilog.Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
  482. }
  483. }
  484. private static IImageEncoder GetImageEncoder(IApplicationPaths appPaths)
  485. {
  486. try
  487. {
  488. // Test if the native lib is available
  489. SkiaEncoder.TestSkia();
  490. return new SkiaEncoder(
  491. _loggerFactory.CreateLogger<SkiaEncoder>(),
  492. appPaths);
  493. }
  494. catch (Exception ex)
  495. {
  496. _logger.LogWarning(ex, "Skia not available. Will fallback to NullIMageEncoder.");
  497. }
  498. return new NullImageEncoder();
  499. }
  500. private static void StartNewInstance(StartupOptions options)
  501. {
  502. _logger.LogInformation("Starting new instance");
  503. var module = options.RestartPath;
  504. if (string.IsNullOrWhiteSpace(module))
  505. {
  506. module = Environment.GetCommandLineArgs()[0];
  507. }
  508. string commandLineArgsString;
  509. if (options.RestartArgs != null)
  510. {
  511. commandLineArgsString = options.RestartArgs ?? string.Empty;
  512. }
  513. else
  514. {
  515. commandLineArgsString = string.Join(
  516. ' ',
  517. Environment.GetCommandLineArgs().Skip(1).Select(NormalizeCommandLineArgument));
  518. }
  519. _logger.LogInformation("Executable: {0}", module);
  520. _logger.LogInformation("Arguments: {0}", commandLineArgsString);
  521. Process.Start(module, commandLineArgsString);
  522. }
  523. private static string NormalizeCommandLineArgument(string arg)
  524. {
  525. if (!arg.Contains(" ", StringComparison.OrdinalIgnoreCase))
  526. {
  527. return arg;
  528. }
  529. return "\"" + arg + "\"";
  530. }
  531. }
  532. }