Esempio n. 1
0
        public static void Restart(StartupOptions startupOptions)
        {
            _logger.Info("Disposing app host");
            _appHost.Dispose();

            _logger.Info("Starting new instance");

            string module = startupOptions.GetOption("-restartpath");
            string commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty;

            if (string.IsNullOrWhiteSpace(module))
            {
                module = Environment.GetCommandLineArgs().First();
            }
            if (!startupOptions.ContainsOption("-restartargs"))
            {
                var args = Environment.GetCommandLineArgs()
                           .Skip(1)
                           .Select(NormalizeCommandLineArgument);

                commandLineArgsString = string.Join(" ", args.ToArray());
            }

            _logger.Info("Executable: {0}", module);
            _logger.Info("Arguments: {0}", commandLineArgsString);

            Process.Start(module, commandLineArgsString);

            _logger.Info("Calling Environment.Exit");
            Environment.Exit(0);
        }
Esempio n. 2
0
        private static void StartNewInstance(StartupOptions startupOptions)
        {
            _logger.Info("Starting new instance");

            string module = startupOptions.GetOption("-restartpath");
            string commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty;

            if (string.IsNullOrWhiteSpace(module))
            {
                module = Environment.GetCommandLineArgs().First();
            }
            if (!startupOptions.ContainsOption("-restartargs"))
            {
                var args = Environment.GetCommandLineArgs()
                           .Skip(1)
                           .Select(NormalizeCommandLineArgument)
                           .ToArray();

                commandLineArgsString = string.Join(" ", args);
            }

            _logger.Info("Executable: {0}", module);
            _logger.Info("Arguments: {0}", commandLineArgsString);

            Process.Start(module, commandLineArgsString);
        }
Esempio n. 3
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="options">The options.</param>
        private static void StartApplication(ServerApplicationPaths appPaths,
                                             ILogManager logManager,
                                             StartupOptions options)
        {
            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var fileSystem = new ManagedFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")), false, true);

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var nativeApp = new NativeApp();

            AppHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", nativeApp);

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(AppHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            Task.Run(() => StartServer(CancellationToken.None));
        }
Esempio n. 4
0
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
        {
            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = _ignoreCertificates;

            var fileSystem = new CommonFileSystem(logManager.GetLogger("FileSystem"), false, true);

            _appHost = new ApplicationHost(appPaths, logManager, false, false, options, fileSystem, "MBServer.Mono", false);

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(_appHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            var initProgress = new Progress <double>();

            var task = _appHost.Init(initProgress);

            Task.WaitAll(task);

            Console.WriteLine("Running startup tasks");

            task = _appHost.RunStartupTasks();
            Task.WaitAll(task);

            task = _applicationTaskCompletionSource.Task;

            Task.WaitAll(task);
        }
Esempio n. 5
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true, appPaths.TempDirectory);
            fileSystem.AddShortcutHandler(new LnkShortcutHandler());
            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths);

            _appHost = new WindowsAppHost(appPaths,
                logManager,
                options,
                fileSystem,
                new PowerManagement(),
                "emby.windows.zip",
                new EnvironmentInfo(),
                imageEncoder,
                new Server.Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")),
                new RecyclableMemoryStreamProvider(),
                new Networking.NetworkManager(logManager.GetLogger("NetworkManager")),
                GenerateCertificate,
                () => Environment.UserDomainName);

            var initProgress = new Progress<double>();

            if (!runService)
            {
                if (!options.ContainsOption("-nosplash")) ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }

            var task = _appHost.Init(initProgress);
            Task.WaitAll(task);

            task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                task = InstallVcredist2013IfNeeded(_appHost, _logger);
                Task.WaitAll(task);

                Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();

                task = ApplicationTaskCompletionSource.Task;
                Task.WaitAll(task);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var fileSystem = new WindowsFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")));

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var nativeApp = new WindowsApp(fileSystem)
            {
                IsRunningAsService = runService
            };

            _appHost = new ApplicationHost(appPaths,
                                           logManager,
                                           options,
                                           fileSystem,
                                           "emby.windows.zip",
                                           nativeApp);

            var initProgress = new Progress <double>();

            if (!runService)
            {
                if (!options.ContainsOption("-nosplash"))
                {
                    ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
                }

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }


            var task = _appHost.Init(initProgress);

            task = task.ContinueWith(new Action <Task>(a => _appHost.RunStartupTasks()));

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                task = InstallVcredistIfNeeded(_appHost, _logger);
                Task.WaitAll(task);

                SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();

                task = ApplicationTaskCompletionSource.Task;
                Task.WaitAll(task);
            }
        }
Esempio n. 7
0
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
        {
            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), false, false, appPaths.TempDirectory);

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            FileSystem = fileSystem;

            var environmentInfo = GetEnvironmentInfo();

            var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths);

            _appHost = new MonoAppHost(appPaths,
                                       logManager,
                                       options,
                                       fileSystem,
                                       new PowerManagement(),
                                       "emby.mono.zip",
                                       environmentInfo,
                                       imageEncoder,
                                       new Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")),
                                       new MemoryStreamProvider(),
                                       new NetworkManager(logManager.GetLogger("NetworkManager")),
                                       GenerateCertificate,
                                       () => Environment.UserName);

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(_appHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            var initProgress = new Progress <double>();

            var task = _appHost.Init(initProgress);

            Task.WaitAll(task);

            Console.WriteLine("Running startup tasks");

            task = _appHost.RunStartupTasks();
            Task.WaitAll(task);

            task = ApplicationTaskCompletionSource.Task;

            Task.WaitAll(task);
        }
Esempio n. 8
0
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
        {
            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var environmentInfo = GetEnvironmentInfo();

            var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, appPaths.TempDirectory);

            FileSystem = fileSystem;

            using (var appHost = new MonoAppHost(appPaths,
                                                 logManager,
                                                 options,
                                                 fileSystem,
                                                 new PowerManagement(),
                                                 "emby.mono.zip",
                                                 environmentInfo,
                                                 new NullImageEncoder(),
                                                 new SystemEvents(logManager.GetLogger("SystemEvents")),
                                                 new NetworkManager(logManager.GetLogger("NetworkManager"))))
            {
                if (options.ContainsOption("-v"))
                {
                    Console.WriteLine(appHost.ApplicationVersion.ToString());
                    return;
                }

                Console.WriteLine("appHost.Init");

                var initProgress = new Progress <double>();

                var task = appHost.Init(initProgress);

                Task.WaitAll(task);

                appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo);

                Console.WriteLine("Running startup tasks");

                task = appHost.RunStartupTasks();
                Task.WaitAll(task);

                task = ApplicationTaskCompletionSource.Task;

                Task.WaitAll(task);
            }
        }
Esempio n. 9
0
File: Main.cs Progetto: vvuk/Emby
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="options">The options.</param>
        private static void StartApplication(ServerApplicationPaths appPaths,
                                             ILogManager logManager,
                                             StartupOptions options)
        {
            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), false, false, appPaths.TempDirectory);

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            _fileSystem = fileSystem;

            var environmentInfo = GetEnvironmentInfo();

            var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger,
                                                                  logManager,
                                                                  fileSystem,
                                                                  options,
                                                                  () => AppHost.HttpClient,
                                                                  appPaths);

            AppHost = new MacAppHost(appPaths,
                                     logManager,
                                     options,
                                     fileSystem,
                                     new PowerManagement(),
                                     "Emby.Server.Mac.pkg",
                                     environmentInfo,
                                     imageEncoder,
                                     new Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")),
                                     new MemoryStreamProvider(),
                                     new NetworkManager(logManager.GetLogger("NetworkManager")),
                                     GenerateCertificate,
                                     () => Environment.UserName);

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(AppHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            Task.Run(() => StartServer(CancellationToken.None));
        }
Esempio n. 10
0
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
        {
            var environmentInfo = GetEnvironmentInfo(options);

            var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true);

            FileSystem = fileSystem;

            using (var appHost = new MonoAppHost(appPaths,
                                                 logManager,
                                                 options,
                                                 fileSystem,
                                                 new PowerManagement(),
                                                 "embyserver-mono_{version}.zip",
                                                 environmentInfo,
                                                 new NullImageEncoder(),
                                                 new SystemEvents(logManager.GetLogger("SystemEvents")),
                                                 new NetworkManager(logManager.GetLogger("NetworkManager"), environmentInfo)))
            {
                if (options.ContainsOption("-v"))
                {
                    Console.WriteLine(appHost.ApplicationVersion.ToString());
                    return;
                }

                Console.WriteLine("appHost.Init");

                appHost.Init();

                appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager);

                Console.WriteLine("Running startup tasks");

                var task = appHost.RunStartupTasks();
                Task.WaitAll(task);

                task = ApplicationTaskCompletionSource.Task;

                Task.WaitAll(task);
            }
        }
Esempio n. 11
0
File: Program.cs Progetto: w3fs/Emby
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
        {
            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var fileSystem = new ManagedFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")), false, false);

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var nativeApp = new NativeApp(options);

            _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "emby.mono.zip", nativeApp);

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(_appHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            var initProgress = new Progress <double>();

            var task = _appHost.Init(initProgress);

            Task.WaitAll(task);

            Console.WriteLine("Running startup tasks");

            task = _appHost.RunStartupTasks();
            Task.WaitAll(task);

            task = ApplicationTaskCompletionSource.Task;

            Task.WaitAll(task);
        }
Esempio n. 12
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="options">The options.</param>
        private static void StartApplication(ServerApplicationPaths appPaths,
                                             ILogManager logManager,
                                             StartupOptions options)
        {
            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            var environmentInfo = GetEnvironmentInfo();

            var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, appPaths.TempDirectory);

            _fileSystem = fileSystem;

            var imageEncoder = GetImageEncoder(appPaths, fileSystem, logManager);

            AppHost = new MacAppHost(appPaths,
                                     logManager,
                                     options,
                                     fileSystem,
                                     new PowerManagement(),
                                     "Emby.Server.Mac.pkg",
                                     environmentInfo,
                                     imageEncoder,
                                     new SystemEvents(logManager.GetLogger("SystemEvents")),
                                     new NetworkManager(logManager.GetLogger("NetworkManager")));

            if (options.ContainsOption("-v"))
            {
                Console.WriteLine(AppHost.ApplicationVersion.ToString());
                return;
            }

            Console.WriteLine("appHost.Init");

            Task.Run(() => StartServer(CancellationToken.None));
        }
Esempio n. 13
0
        public static void Main()
        {
            var options = new StartupOptions(Environment.GetCommandLineArgs());

            IsRunningAsService = options.ContainsOption("-service");

            if (IsRunningAsService)
            {
                //_canRestartService = CanRestartWindowsService();
            }

            var currentProcess = Process.GetCurrentProcess();

            ApplicationPath = currentProcess.MainModule.FileName;
            var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");

            var success = SetDllDirectory(architecturePath);

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);

            var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");

            logManager.ReloadLogger(LogSeverity.Debug);
            logManager.AddConsoleOutput();

            var logger = _logger = logManager.GetLogger("Main");

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            // Install directly
            if (options.ContainsOption("-installservice"))
            {
                logger.Info("Performing service installation");
                InstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then install
            if (options.ContainsOption("-installserviceasadmin"))
            {
                logger.Info("Performing service installation");
                RunServiceInstallation(ApplicationPath);
                return;
            }

            // Uninstall directly
            if (options.ContainsOption("-uninstallservice"))
            {
                logger.Info("Performing service uninstallation");
                UninstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then uninstall
            if (options.ContainsOption("-uninstallserviceasadmin"))
            {
                logger.Info("Performing service uninstallation");
                RunServiceUninstallation(ApplicationPath);
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            RunServiceInstallationIfNeeded(ApplicationPath);

            if (IsAlreadyRunning(ApplicationPath, currentProcess))
            {
                logger.Info("Shutting down because another instance of Emby Server is already running.");
                return;
            }

            if (PerformUpdateIfNeeded(appPaths, logger))
            {
                logger.Info("Exiting to perform application update.");
                return;
            }

            try
            {
                RunApplication(appPaths, logManager, IsRunningAsService, options);
            }
            finally
            {
                OnServiceShutdown();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var environmentInfo = new EnvironmentInfo();

            var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, appPaths.TempDirectory);

            FileSystem = fileSystem;

            using (var appHost = new WindowsAppHost(appPaths,
                                                    logManager,
                                                    options,
                                                    fileSystem,
                                                    new PowerManagement(),
                                                    UpdatePackageFileName,
                                                    environmentInfo,
                                                    new NullImageEncoder(),
                                                    new SystemEvents(logManager.GetLogger("SystemEvents")),
                                                    new Networking.NetworkManager(logManager.GetLogger("NetworkManager"))))
            {
                var initProgress = new Progress <double>();

                if (!runService)
                {
                    if (!options.ContainsOption("-nosplash"))
                    {
                        ShowSplashScreen(appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
                    }

                    // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                    SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                                 ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
                }

                var task = appHost.Init(initProgress);
                Task.WaitAll(task);

                if (!runService)
                {
                    task = InstallVcredist2013IfNeeded(appHost.HttpClient, _logger);
                    Task.WaitAll(task);

                    // needed by skia
                    task = InstallVcredist2015IfNeeded(appHost.HttpClient, _logger);
                    Task.WaitAll(task);
                }

                // set image encoder here
                appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, appHost.LocalizationManager);

                task = task.ContinueWith(new Action <Task>(a => appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);

                if (runService && IsServiceInstalled())
                {
                    StartService(logManager);
                }
                else
                {
                    Task.WaitAll(task);

                    HideSplashScreen();

                    ShowTrayIcon(appHost);
                }
            }
        }
Esempio n. 15
0
        public static void Main()
        {
            var options = new StartupOptions(Environment.GetCommandLineArgs());

            IsRunningAsService = options.ContainsOption("-service");

            var currentProcess = Process.GetCurrentProcess();

            ApplicationPath = currentProcess.MainModule.FileName;
            var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");

            var success = SetDllDirectory(architecturePath);

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);

            _appPaths = appPaths;

            using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"))
            {
                _logManager = logManager;

                var task = logManager.ReloadLogger(LogSeverity.Debug, CancellationToken.None);
                Task.WaitAll(task);

                logManager.AddConsoleOutput();

                var logger = _logger = logManager.GetLogger("Main");

                ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

                // Uninstall directly
                if (options.ContainsOption("-uninstallservice"))
                {
                    logger.Info("Performing service uninstallation");
                    UninstallService(ApplicationPath, logger);
                    return;
                }

                // Restart with admin rights, then uninstall
                if (options.ContainsOption("-uninstallserviceasadmin"))
                {
                    logger.Info("Performing service uninstallation");
                    RunServiceUninstallation(ApplicationPath);
                    return;
                }

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                if (IsAlreadyRunning(ApplicationPath, currentProcess))
                {
                    logger.Info("Shutting down because another instance of Emby Server is already running.");
                    return;
                }

                if (PerformUpdateIfNeeded(appPaths, logger))
                {
                    logger.Info("Exiting to perform application update.");
                    return;
                }

                RunApplication(appPaths, logManager, IsRunningAsService, options);

                logger.Info("Shutdown complete");

                if (_restartOnShutdown)
                {
                    logger.Info("Starting new server process");
                    var restartCommandLine = GetRestartCommandLine();

                    Process.Start(restartCommandLine.Item1, restartCommandLine.Item2);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        public static void Main()
        {
            var options = new StartupOptions();

            _isRunningAsService = options.ContainsOption("-service");

            var applicationPath = Process.GetCurrentProcess().MainModule.FileName;

            var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService);

            var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");

            logManager.ReloadLogger(LogSeverity.Debug);
            logManager.AddConsoleOutput();

            var logger = _logger = logManager.GetLogger("Main");

            BeginLog(logger, appPaths);

            // Install directly
            if (options.ContainsOption("-installservice"))
            {
                logger.Info("Performing service installation");
                InstallService(applicationPath, logger);
                return;
            }

            // Restart with admin rights, then install
            if (options.ContainsOption("-installserviceasadmin"))
            {
                logger.Info("Performing service installation");
                RunServiceInstallation(applicationPath);
                return;
            }

            // Uninstall directly
            if (options.ContainsOption("-uninstallservice"))
            {
                logger.Info("Performing service uninstallation");
                UninstallService(applicationPath, logger);
                return;
            }

            // Restart with admin rights, then uninstall
            if (options.ContainsOption("-uninstallserviceasadmin"))
            {
                logger.Info("Performing service uninstallation");
                RunServiceUninstallation(applicationPath);
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            RunServiceInstallationIfNeeded(applicationPath);

            var currentProcess = Process.GetCurrentProcess();

            if (IsAlreadyRunning(applicationPath, currentProcess))
            {
                logger.Info("Shutting down because another instance of Media Browser Server is already running.");
                return;
            }

            if (PerformUpdateIfNeeded(appPaths, logger))
            {
                logger.Info("Exiting to perform application update.");
                return;
            }

            try
            {
                RunApplication(appPaths, logManager, _isRunningAsService, options);
            }
            finally
            {
                OnServiceShutdown();
            }
        }