예제 #1
0
 private void OverrideEnvPort(ProcessSpec processSpec)
 {
     if (processSpec.Environment.ContainsKey("PORT"))
     {
         var hostport = container.GetProperty("ContainerPort:" + processSpec.Environment["PORT"]);
         processSpec.Environment["PORT"] = hostport;
     }
     if (processSpec.Arguments != null)
     {
         // TODO: Remove this. This case is for Healthcheck ; when nsync sends port as env variable we can remove this. (https://github.com/cloudfoundry-incubator/nsync/pull/1)
         var portArg = Array.Find(processSpec.Arguments, s => s.StartsWith("-port="));
         if (portArg != null)
         {
             var containerPort = portArg.Split(new Char[] {'='})[1];
             var hostport = container.GetProperty("ContainerPort:" + containerPort);
             processSpec.Environment["PORT"] = hostport;
         }
         // TODO: Remove this. This case is for the ssh daemon
         var addressArgIdx = Array.FindIndex(processSpec.Arguments, s => s.StartsWith("-address="));
         if (addressArgIdx != -1)
         {
             var containerAddr = processSpec.Arguments[addressArgIdx].Split(new Char[] { '=' })[1];
             var containerHostAndPort = containerAddr.Split(new Char[] { ':' });
             var containerPort = containerHostAndPort[1];
             var hostport = container.GetProperty("ContainerPort:" + containerPort);
             processSpec.Arguments[addressArgIdx] = "-address=" + containerHostAndPort[0] + ":" + hostport;
         }
     }
 }
예제 #2
0
 private static void CopyProcessSpecEnvVariables(ProcessSpec processSpec, string[] envStrings)
 {
     if (envStrings == null) { return; }
     foreach (var kv in envStrings)
     {
         string[] arr = kv.Split(new Char[] { '=' }, 2);
         processSpec.Environment[arr[0]] = arr[1];
     }
 }
예제 #3
0
 private ProcessSpec NewProcessSpec(Models.ApiProcessSpec apiProcessSpec)
 {
     var processSpec = new ProcessSpec
     {
         DisablePathMapping = false,
         Privileged = false,
         WorkingDirectory = container.Directory.UserPath,
         ExecutablePath = apiProcessSpec.Path,
         Environment = new Dictionary<string, string>
             {
                 { "USERPROFILE", container.Directory.UserPath },
                 { "ARGJSON", JsonConvert.SerializeObject(apiProcessSpec.Args) }
             },
         Arguments = apiProcessSpec.Args
     };
     return processSpec;
 }
 public void WriteTarStreamToPath(Stream stream, IContainer container, string filePath)
 {
     var tmpFilePath = container.Directory.MapBinPath(Path.GetRandomFileName());
     Directory.CreateDirectory(filePath);
     using (var tmpFile = File.Create(tmpFilePath))
     {
         stream.CopyTo(tmpFile);
     }
     var pSpec = new ProcessSpec()
     {
         ExecutablePath = TarArchiverPath("tar.exe"),
         Arguments = new []{"xf", tmpFilePath, "-C", filePath},
     };
     var process = container.Run(pSpec, null);
     var exitCode = process.WaitForExit();
     if (exitCode != 0)
         throw new Exception("Failed to extract stream");
     File.Delete(tmpFilePath);
 }
예제 #5
0
            public Run()
            {
                Spec = new ProcessSpec
                {
                    ExecutablePath = "/.iishost/iishost.exe",
                    Arguments      = new[] { "-p", "3000", "-r", @"/www" },
                };

                var containerUserPath = @"C:\Containers\handle\user\";

                ExpectedRunSpec = new ProcessRunSpec
                {
                    ExecutablePath   = @"C:\Containers\handle\user\.iishost\iishost.exe",
                    Arguments        = Spec.Arguments,
                    WorkingDirectory = containerUserPath,
                };

                Directory.MapUserPath("/.iishost/iishost.exe").Returns(ExpectedRunSpec.ExecutablePath);
                Directory.MapUserPath("/").Returns(containerUserPath);
            }
예제 #6
0
        public IContainerProcess Run(ProcessSpec spec, IProcessIO io)
        {
            lock (_ioLock)
            {
                ThrowIfNotActive();

                var runner = spec.Privileged
                    ? processRunner
                    : constrainedProcessRunner;

                var executablePath = !spec.DisablePathMapping
                    ? directory.MapUserPath(spec.ExecutablePath)
                    : spec.ExecutablePath;

                var specEnvironment    = spec.Environment ?? new Dictionary <string, string>();
                var processEnvironment = this.defaultEnvironment.Merge(specEnvironment);

                Action <string> stdOut = io == null || io.StandardOutput == null
                    ? (Action <string>)null
                    : data => io.StandardOutput.Write(data);

                Action <string> stdErr = io == null || io.StandardError == null
                    ? (Action <string>)null
                    : data => io.StandardError.Write(data);

                var runSpec = new ProcessRunSpec
                {
                    ExecutablePath   = executablePath,
                    Arguments        = spec.Arguments,
                    Environment      = processEnvironment,
                    WorkingDirectory = directory.MapUserPath(spec.WorkingDirectory ?? DefaultWorkingDirectory),
                    OutputCallback   = stdOut,
                    ErrorCallback    = stdErr,
                };

                var process = runner.Run(runSpec);

                return(new ContainerProcess(process));
            }
        }
예제 #7
0
 private void OverrideEnvPort(ProcessSpec processSpec, ContainerInfo info)
 {
     if (processSpec.Environment.ContainsKey("PORT"))
     {
         var hostport = container.GetProperty("ContainerPort:" + processSpec.Environment["PORT"]);
         processSpec.Environment["PORT"] = hostport;
     }
     else if (processSpec.Arguments != null)
     {
         // TODO: Remove this. This case is for Healthcheck ; when nsync sends port as env variable we can remove this. (https://github.com/cloudfoundry-incubator/nsync/pull/1)
         var portArg = Array.Find(processSpec.Arguments, s => s.StartsWith("-port="));
         if (portArg != null)
         {
             var containerPort = portArg.Split(new Char[] {'='})[1];
             var hostport = container.GetProperty("ContainerPort:" + containerPort);
             processSpec.Environment["PORT"] = hostport;
         }
     }
 }
예제 #8
0
 private IContainerProcess Run(IWebSocketEventSender websocket, ProcessSpec processSpec)
 {
     try
     {
         var processIO = new ProcessIO(websocket);
         var process = container.Run(processSpec, processIO);
         websocket.SendEvent("pid", process.Id.ToString());
         return process;
     }
     catch (Exception e)
     {
         websocket.SendEvent("error", e.Message);
         websocket.Close(System.Net.WebSockets.WebSocketCloseStatus.InternalServerError, e.Message);
         return null;
     }
 }
예제 #9
0
        public IContainerProcess Run(ProcessSpec spec, IProcessIO io)
        {
            lock (_ioLock)
            {
                ThrowIfNotActive();

                var runner = spec.Privileged
                    ? processRunner
                    : constrainedProcessRunner;

                var executablePath = !spec.DisablePathMapping
                    ? directory.MapUserPath(spec.ExecutablePath)
                    : spec.ExecutablePath;

                var specEnvironment = spec.Environment ?? new Dictionary<string, string>();
                var processEnvironment = this.defaultEnvironment.Merge(specEnvironment);

                Action<string> stdOut = io == null || io.StandardOutput == null
                    ? (Action<string>) null
                    : data => io.StandardOutput.Write(data);

                Action<string> stdErr = io == null || io.StandardError == null
                    ? (Action<string>) null
                    : data => io.StandardError.Write(data);

                var runSpec = new ProcessRunSpec
                {
                    ExecutablePath = executablePath,
                    Arguments = spec.Arguments,
                    Environment = processEnvironment,
                    WorkingDirectory = directory.MapUserPath(spec.WorkingDirectory ?? DefaultWorkingDirectory),
                    OutputCallback = stdOut,
                    ErrorCallback = stdErr,
                };

                var process = runner.Run(runSpec);

                return new ContainerProcess(process);
            }
        }
예제 #10
0
            public Run()
            {
                Spec = new ProcessSpec
                {
                    ExecutablePath = "/.iishost/iishost.exe",
                    Arguments = new[] { "-p", "3000", "-r", @"/www" },
                };

                var containerUserPath = @"C:\Containers\handle\user\";
                ExpectedRunSpec = new ProcessRunSpec
                {
                    ExecutablePath = @"C:\Containers\handle\user\.iishost\iishost.exe",
                    Arguments = Spec.Arguments,
                    WorkingDirectory = containerUserPath,
                };

                Directory.MapUserPath("/.iishost/iishost.exe").Returns(ExpectedRunSpec.ExecutablePath);
                Directory.MapUserPath("/").Returns(containerUserPath);
            }