public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) throw new ArgumentNullException ("configFiles"); if (configurationManager == null) throw new ArgumentNullException ("configurationManager"); foreach (var fileInfo in configFiles) { Logger.Write(LogLevel.Debug, "Loading {0}", fileInfo.Name); var childConfigurationManager = new ChildConfigurationManager(); string fullName = fileInfo.FullName; childConfigurationManager.LoadXmlConfig(fullName); string user = childConfigurationManager.User; string fastCgiCommand = configurationManager.FastCgiCommand; ChildInfo child; if (Platform.IsUnix) { if (String.IsNullOrEmpty(user)) { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name); user = UnixFileSystemInfo.GetFileSystemEntry(fullName).OwnerUser.UserName; } child = Spawner.RunAs(user, Spawner.SpawnChild, fullName, fastCgiCommand); } else { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name); child = Spawner.SpawnChild(fullName, fastCgiCommand); } children.Add(child); } }
static void PrepareChild(ConfigurationManager configurationManager, ChildConfigurationManager childConfigurationManager, string fullFilename, ChildInfo child) { if (childConfigurationManager.InstanceType == InstanceType.Static) { if (child.TrySpawn()) { Logger.Write(LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName(fullFilename)); Thread.Sleep(500); // TODO: improve this (it's used to wait for the child to be ready) } else { Logger.Write(LogLevel.Error, "Couldn't start child with config file {0}", fullFilename); } } else { Socket socket; if (FastCgi.Server.TryCreateSocket(childConfigurationManager, out socket)) { var server = new GenericServer <Connection> (socket, child); server.Start(configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) { throw new ArgumentNullException("configFiles"); } if (configurationManager == null) { throw new ArgumentNullException("configurationManager"); } foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) { continue; } var filename = fileInfo.Name; var childConfigurationManager = new ChildConfigurationManager("child-" + filename); Logger.Write(LogLevel.Debug, "Loaded {0} [{1}]", filename, childConfigurationManager.InstanceType.ToString().ToLowerInvariant()); string fullFilename = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig(fullFilename)) { continue; } var spawner = GetSpawner(configurationManager, filename, childConfigurationManager, fullFilename); var child = new ChildInfo { Spawner = spawner, OnDemandSock = childConfigurationManager.OnDemandSock, Name = fullFilename }; children.Add(child); PrepareChild(configurationManager, childConfigurationManager, fullFilename, child); } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) throw new ArgumentNullException ("configFiles"); if (configurationManager == null) throw new ArgumentNullException ("configurationManager"); foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) continue; Logger.Write (LogLevel.Debug, "Loading {0}", fileInfo.Name); var childConfigurationManager = new ChildConfigurationManager (); string configFile = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig (configFile)) continue; string user = childConfigurationManager.User; string fastCgiCommand = configurationManager.FastCgiCommand; Func<bool, Process> spawner; if (Platform.IsUnix) { if (String.IsNullOrEmpty (user)) { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name); user = UnixFileSystemInfo.GetFileSystemEntry (configFile).OwnerUser.UserName; } spawner = onDemand => Spawner.RunAs (user, Spawner.SpawnChild, configFile, fastCgiCommand, onDemand); } else { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name); spawner = onDemand => Spawner.SpawnChild (configFile, fastCgiCommand, onDemand); } var child = new ChildInfo { Spawner = spawner, ConfigurationManager = childConfigurationManager, Name = configFile, OnDemand = childConfigurationManager.InstanceType == InstanceType.Dynamic }; children.Add (child); if (child.OnDemand){ Socket socket; if (FastCgi.Server.TryCreateSocket (childConfigurationManager, out socket)) { var server = new GenericServer<Connection> (socket, child); server.Start (configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } else { if (child.TrySpawn ()) { Logger.Write (LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName (configFile)); } else { Logger.Write (LogLevel.Error, "Couldn't start child with config file {0}", configFile); } } } }
static Func<Process> GetSpawner (ConfigurationManager configurationManager, string filename, ChildConfigurationManager childConfigurationManager, string configFile) { Func<Process> spawner; if (childConfigurationManager.InstanceType == InstanceType.Ondemand) { if (String.IsNullOrEmpty (childConfigurationManager.ShimSocket)) throw new Exception ("You must specify a socket for the shim"); spawner = () => Spawner.SpawnOndemandChild (childConfigurationManager.ShimSocket); } else spawner = () => Spawner.SpawnStaticChild (configFile, configurationManager.FastCgiCommand); Action spawnShim = () => Spawner.SpawnShim (configurationManager, childConfigurationManager.ShimSocket, configFile); string user = childConfigurationManager.User; string group = childConfigurationManager.Group; if (String.IsNullOrEmpty (user)) { if (Platform.IsUnix) { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", filename); string owner = UnixFileSystemInfo.GetFileSystemEntry (configFile).OwnerUser.UserName; if (childConfigurationManager.InstanceType == InstanceType.Ondemand) Spawner.RunAs (owner, group, spawnShim) (); else spawner = Spawner.RunAs (owner, group, spawner); } else { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", filename); if (childConfigurationManager.InstanceType != InstanceType.Ondemand) spawnShim (); } } else { if (childConfigurationManager.InstanceType == InstanceType.Ondemand) Spawner.RunAs (user, group, spawnShim) (); else spawner = Spawner.RunAs (user, group, spawner); } return spawner; }
static void PrepareChild (ConfigurationManager configurationManager, ChildConfigurationManager childConfigurationManager, string fullFilename, ChildInfo child) { if (childConfigurationManager.InstanceType == InstanceType.Static) { if (child.TrySpawn ()) { Logger.Write (LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName (fullFilename)); Thread.Sleep (500); // TODO: improve this (it's used to wait for the child to be ready) } else Logger.Write (LogLevel.Error, "Couldn't start child with config file {0}", fullFilename); } else { Socket socket; if (FastCgi.Server.TryCreateSocket (childConfigurationManager, out socket)) { var server = new GenericServer<Connection> (socket, child); server.Start (configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) throw new ArgumentNullException ("configFiles"); if (configurationManager == null) throw new ArgumentNullException ("configurationManager"); foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) continue; var filename = fileInfo.Name; var childConfigurationManager = new ChildConfigurationManager ("child-" + filename); Logger.Write (LogLevel.Debug, "Loaded {0} [{1}]", filename, childConfigurationManager.InstanceType.ToString ().ToLowerInvariant ()); string fullFilename = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig (fullFilename)) continue; var spawner = GetSpawner (configurationManager, filename, childConfigurationManager, fullFilename); var child = new ChildInfo { Spawner = spawner, OnDemandSock = childConfigurationManager.OnDemandSock, Name = fullFilename }; children.Add (child); PrepareChild (configurationManager, childConfigurationManager, fullFilename, child); } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) { throw new ArgumentNullException("configFiles"); } if (configurationManager == null) { throw new ArgumentNullException("configurationManager"); } foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) { continue; } Logger.Write(LogLevel.Debug, "Loading {0}", fileInfo.Name); var childConfigurationManager = new ChildConfigurationManager(); string configFile = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig(configFile)) { continue; } string user = childConfigurationManager.User; string fastCgiCommand = configurationManager.FastCgiCommand; Func <bool, Process> spawner; if (Platform.IsUnix) { if (String.IsNullOrEmpty(user)) { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name); user = UnixFileSystemInfo.GetFileSystemEntry(configFile).OwnerUser.UserName; } spawner = onDemand => Spawner.RunAs(user, Spawner.SpawnChild, configFile, fastCgiCommand, onDemand); } else { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name); spawner = onDemand => Spawner.SpawnChild(configFile, fastCgiCommand, onDemand); } var child = new ChildInfo { Spawner = spawner, ConfigurationManager = childConfigurationManager, Name = configFile, OnDemand = childConfigurationManager.InstanceType == InstanceType.Dynamic }; children.Add(child); if (child.OnDemand) { Socket socket; if (FastCgi.Server.TryCreateSocket(childConfigurationManager, out socket)) { var server = new GenericServer <Connection> (socket, child); server.Start(configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } else { if (child.TrySpawn()) { Logger.Write(LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName(configFile)); } else { Logger.Write(LogLevel.Error, "Couldn't start child with config file {0}", configFile); } } } }
static Func <Process> GetSpawner(ConfigurationManager configurationManager, string filename, ChildConfigurationManager childConfigurationManager, string configFile) { Func <Process> spawner; if (childConfigurationManager.InstanceType == InstanceType.Ondemand) { if (String.IsNullOrEmpty(childConfigurationManager.ShimSocket)) { throw new Exception("You must specify a socket for the shim"); } spawner = () => Spawner.SpawnOndemandChild(childConfigurationManager.ShimSocket); } else { spawner = () => Spawner.SpawnStaticChild(configFile, configurationManager.FastCgiCommand); } Action spawnShim = () => Spawner.SpawnShim(configurationManager, childConfigurationManager.ShimSocket, configFile); string user = childConfigurationManager.User; string group = childConfigurationManager.Group; if (String.IsNullOrEmpty(user)) { if (Platform.IsUnix) { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", filename); string owner = UnixFileSystemInfo.GetFileSystemEntry(configFile).OwnerUser.UserName; if (childConfigurationManager.InstanceType == InstanceType.Ondemand) { Spawner.RunAs(owner, group, spawnShim) (); } else { spawner = Spawner.RunAs(owner, group, spawner); } } else { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", filename); if (childConfigurationManager.InstanceType != InstanceType.Ondemand) { spawnShim(); } } } else { if (childConfigurationManager.InstanceType == InstanceType.Ondemand) { Spawner.RunAs(user, group, spawnShim) (); } else { spawner = Spawner.RunAs(user, group, spawner); } } return(spawner); }