public override StartServiceResult StartService(IntPtr ignored)
 {
     firewallService.Open(config.MonitoringServicePort, Resources.MonitoringWinService_ServiceName);
     return(base.StartService(ignored));
 }
Esempio n. 2
0
        public WebServerAdministrationBinding InstallWebApp(string localDirectory, string applicationInstanceName)
        {
            WebServerAdministrationBinding rv = null;

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsAppPoolExist(applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string       cmd  = String.Format("add apppool /name:{0}", applicationInstanceName);
                        AppCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated",
                            applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd             = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                                                        applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }
                    }

                    rv = new WebServerAdministrationBinding {
                        Host = localIPAddress.ToString(), Port = applicationPort
                    };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(rv);
        }
Esempio n. 3
0
 public override StartServiceResult StartService(IntPtr ignored, string[] args)
 {
     firewallService.Open(config.FilesServicePort, Resources.FilesWinService_ServiceName);
     return(base.StartService(ignored, args));
 }
Esempio n. 4
0
        public WebServerAdministrationBinding InstallWebApp(
            string localDirectory, string applicationInstanceName, ushort managedRuntimeVersion)
        {
            WebServerAdministrationBinding rv = null;

            if (managedRuntimeVersion != 2 && managedRuntimeVersion != 4)
            {
                throw new ArgumentException(
                          String.Format(Resources.WebServerAdministrationProvider_InvalidManagedRuntimeVersion_Fmt, managedRuntimeVersion), "managedRuntimeVersion");
            }

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsAppPoolExist(applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string        cmd  = String.Format("add apppool /name:{0}", applicationInstanceName);
                        ExecCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v{1}.0 /managedPipelineMode:Integrated /processModel.loadUserProfile:true",
                            applicationInstanceName, managedRuntimeVersion);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd             = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                                                        applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set config {0} /section:system.webServer/httpLogging /dontLog:True", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }
                    }

                    rv = new WebServerAdministrationBinding {
                        Host = localIPAddress.ToString(), Port = applicationPort
                    };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(rv);
        }