public static int Main(string [] args) { var configurationManager = new ConfigurationManager(); if (!configurationManager.LoadCommandLineArgs(args)) { return(1); } // Show the help and exit. if (configurationManager.Help) { configurationManager.PrintHelp(); #if DEBUG Console.WriteLine("Press any key..."); Console.ReadKey(); #endif return(0); } // Show the version and exit. if (configurationManager.Version) { Version.Show(); return(0); } if (!configurationManager.LoadConfigFile()) { return(1); } configurationManager.SetupLogger(); #if DEBUG // Log everything while debugging Logger.Level = LogLevel.All; #endif Logger.Write(LogLevel.Debug, Assembly.GetExecutingAssembly().GetName().Name); string configDir = configurationManager.ConfigDir; if (String.IsNullOrEmpty(configDir)) { Logger.Write(LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter"); return(1); } var configDirInfo = new DirectoryInfo(configDir); if (!configDirInfo.Exists) { Logger.Write(LogLevel.Error, "The configuration directory \"{0}\" does not exist!", configDir); return(1); } Logger.Write(LogLevel.Debug, "Configuration directory exists, loading configuration files"); FileInfo[] configFiles = configDirInfo.GetFiles("*.xml"); ChildrenManager.StartChildren(configFiles, configurationManager); if (!configurationManager.Stoppable) { var sleep = new ManualResetEvent(false); sleep.WaitOne(); // Do androids dream of electric sheep? } Console.WriteLine("Hit Return to stop the server."); Console.ReadLine(); ChildrenManager.TermChildren(); ChildrenManager.KillChildren(); return(0); }
public static int Main(string [] args) { var configurationManager = new ConfigurationManager("mono-fpm"); if (!configurationManager.LoadCommandLineArgs(args)) { return(1); } // Show the help and exit. if (configurationManager.Help) { configurationManager.PrintHelp(); #if DEBUG Console.WriteLine("Press any key..."); Console.ReadKey(); #endif return(0); } // Show the version and exit. if (configurationManager.Version) { Version.Show(); return(0); } if (!configurationManager.LoadConfigFile()) { return(1); } configurationManager.SetupLogger(); #if DEBUG // Log everything while debugging Logger.Level = LogLevel.All; #endif Logger.Write(LogLevel.Debug, Assembly.GetExecutingAssembly().GetName().Name); string configDir = configurationManager.ConfigDir; string webDir = configurationManager.WebDir; if (String.IsNullOrEmpty(configDir) && (!Platform.IsUnix || String.IsNullOrEmpty(webDir))) { if (Platform.IsUnix) { Logger.Write(LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter or web directories with the --web-dir parameter."); } else { Logger.Write(LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter."); } return(1); } if (!String.IsNullOrEmpty(configDir)) { var configDirInfo = new DirectoryInfo(configDir); if (!configDirInfo.Exists) { Logger.Write(LogLevel.Error, "The configuration directory \"{0}\" does not exist!", configDir); } else { Logger.Write(LogLevel.Debug, "Configuration directory {0} exists, loading configuration files", configDir); FileInfo[] configFiles = configDirInfo.GetFiles("*.xml"); ChildrenManager.StartChildren(configFiles, configurationManager); } } if (Platform.IsUnix && !String.IsNullOrEmpty(webDir)) { var webDirInfo = new UnixDirectoryInfo(Path.GetFullPath(webDir)); if (!webDirInfo.Exists) { Logger.Write(LogLevel.Error, "The web directory \"{0}\" does not exist!", webDir); } else { Logger.Write(LogLevel.Debug, "Web directory {0} exists, starting children", webDir); IEnumerable <UnixDirectoryInfo> webDirs = from entry in webDirInfo.GetFileSystemEntries() let dir = entry as UnixDirectoryInfo where dir != null select dir; if (configurationManager.HttpdGroup == null) { Logger.Write(LogLevel.Error, "Couldn't autodetect the httpd group, you must specify it explicitly with --httpd-group"); return(1); } if (!CheckGroupExists(configurationManager.FpmGroup) || !CheckGroupExists(configurationManager.HttpdGroup) || !CheckUserExists(configurationManager.FpmUser)) { return(1); } ChildrenManager.StartAutomaticChildren(webDirs, configurationManager); } } Platform.SetIdentity(configurationManager.FpmUser, configurationManager.FpmGroup); if (!configurationManager.Stoppable) { var sleep = new ManualResetEvent(false); sleep.WaitOne(); // Do androids dream of electric sheep? } Console.WriteLine("Hit Return to stop the server."); Console.ReadLine(); ChildrenManager.TermChildren(); ChildrenManager.KillChildren(); return(0); }