Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static void StartAutomaticChildren(IEnumerable <UnixDirectoryInfo> webDirs, ConfigurationManager configurationManager)
        {
            if (webDirs == null)
            {
                throw new ArgumentNullException("webDirs");
            }
            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            string shimSocketDir;
            string frontSocketDir;
            string backSocketDir;

            CreateAutomaticDirs(configurationManager.FpmGroup, configurationManager.HttpdGroup, out shimSocketDir, out frontSocketDir, out backSocketDir);
            foreach (UnixDirectoryInfo directoryInfo in webDirs)
            {
                if (directoryInfo == null)
                {
                    continue;
                }

                var user    = directoryInfo.OwnerUser.UserName;
                var group   = directoryInfo.OwnerGroup.GroupName;
                var dirname = directoryInfo.Name;

                if (directoryInfo.OwnerUserId < 100)
                {
                    Logger.Write(LogLevel.Debug, "Directory {0} skipped because owned by {1}:{2} ({3}:{4})",
                                 dirname, user, group, directoryInfo.OwnerUserId, directoryInfo.OwnerGroupId);
                    continue;                     // Skip non-user directories
                }

                string shimSocket  = Path.Combine(shimSocketDir, dirname);
                string frontSocket = Path.Combine(frontSocketDir, dirname);
                string backSocket  = Path.Combine(backSocketDir, dirname);

                Func <Process>    spawner   = () => Spawner.SpawnOndemandChild(shimSocket);
                UnixDirectoryInfo info      = directoryInfo;
                Action            spawnShim = () => Spawner.SpawnShim(configurationManager, shimSocket, info.FullName, backSocket);
                Spawner.RunAs(user, configurationManager.WebGroup, spawnShim) ();

                var child = new ChildInfo {
                    Spawner = spawner, OnDemandSock = backSocket, Name = directoryInfo.FullName
                };
                children.Add(child);

                PrepareAutomaticChild(configurationManager, frontSocket, child, 500);
            }
        }