Example #1
0
        static void Main(string[] args)
        {
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var applicationPath = Assembly.GetEntryAssembly().Location;

            var options = new StartupOptions(Environment.GetCommandLineArgs());

            // Allow this to be specified on the command line.
            var customProgramDataPath = options.GetOption("-programdata");

            var appFolderPath = Path.GetDirectoryName(applicationPath);

            var appPaths = CreateApplicationPaths(appFolderPath, customProgramDataPath);

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

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

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

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            StartApplication(appPaths, logManager, options);
            NSApplication.Init();
            NSApplication.Main(args);
        }
Example #2
0
        public static void Main(string[] args)
        {
            var applicationPath = Assembly.GetEntryAssembly().Location;

            SetSqliteProvider();

            var options = new StartupOptions(Environment.GetCommandLineArgs());

            // Allow this to be specified on the command line.
            var customProgramDataPath = options.GetOption("-programdata");

            var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath);

            _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);

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                RunApplication(appPaths, logManager, options);

                _logger.Info("Disposing app host");

                if (_restartOnShutdown)
                {
                    StartNewInstance(options);
                }
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            var applicationPath = Assembly.GetEntryAssembly().Location;
            var appFolderPath   = Path.GetDirectoryName(applicationPath);

            SetSqliteProvider();

            var options = new StartupOptions(Environment.GetCommandLineArgs());

            // Allow this to be specified on the command line.
            var customProgramDataPath = options.GetOption("-programdata");

            var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath);

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

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

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

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            try
            {
                RunApplication(appPaths, logManager, options);
            }
            finally
            {
                logger.Info("Shutting down");

                _appHost.Dispose();
            }
        }
Example #4
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;

                logManager.ReloadLogger(LogSeverity.Debug);
                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);
                }
            }
        }
Example #5
0
        static void Main()
        {
            ApplicationPath = Assembly.GetEntryAssembly().Location;

            var environmentInfo = GetEnvironmentInfo();

            var appPaths = new ApplicationPaths(GetProgramDataPath(ApplicationPath), ApplicationPath);

            _appPaths = appPaths;

            using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "theater"))
            {
                _logManager = logManager;
                logManager.ReloadLogger(LogSeverity.Debug);
                logManager.AddConsoleOutput();

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

                logger.Info("Application path: {0}", ApplicationPath);

                ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                // Mutex credit: https://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c/229567

                // unique id for global mutex - Global prefix means it is global to the machine
                string mutexId = string.Format("Global\\{{{0}}}", "EmbyTheater");

                // Need a place to store a return value in Mutex() constructor call
                bool createdNew;

                // edited by MasonGZhwiti to prevent race condition on security settings via VanNguyen
                using (var mutex = new Mutex(false, mutexId, out createdNew))
                {
                    // edited by acidzombie24
                    var hasHandle = false;
                    try
                    {
                        // note, you may want to time out here instead of waiting forever
                        // edited by acidzombie24
                        hasHandle = mutex.WaitOne(5000, false);
                        if (hasHandle == false)
                        {
                            logger.Info("Exiting because another instance is already running.");
                            return;
                        }
                    }
                    catch (AbandonedMutexException)
                    {
                        // Log the fact that the mutex was abandoned in another process,
                        // it will still get acquired
                        hasHandle = true;
                        logger.Info("Mutex was abandoned in another process.");
                    }

                    using (new MutexHandle(mutex, hasHandle, _logger))
                    {
                        if (PerformUpdateIfNeeded(appPaths, environmentInfo, logger))
                        {
                            logger.Info("Exiting to perform application update.");
                            return;
                        }

                        RunApplication(appPaths, logManager, environmentInfo, new StartupOptions(Environment.GetCommandLineArgs()));
                    }
                }

                logger.Info("Shutdown complete");

                if (_restartOnShutdown)
                {
                    // This is artificial, but add some delay to ensure sockets are released.
                    var delay = environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows
                        ? 5000
                        : 60000;

                    var task = Task.Delay(delay);
                    Task.WaitAll(task);

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

                    Process.Start(restartCommandLine.Item1, restartCommandLine.Item2);
                }
            }
        }