Ejemplo n.º 1
0
        private Installer InitInstaller(ResinService resinService)
        {
            TransactedInstaller txInst = new TransactedInstaller();

            txInst.Context = new InstallContext(null, new String[] { });
            txInst.Context.Parameters["assemblypath"] = resinService.Exe;

            ServiceProcessInstaller spInst = new ServiceProcessInstaller();

            if (resinService.User != null)
            {
                spInst.Username = resinService.User;
                spInst.Password = resinService.Password;
                spInst.Account  = ServiceAccount.User;
            }
            else
            {
                spInst.Account = ServiceAccount.LocalSystem;
            }

            txInst.Installers.Add(spInst);

            ServiceInstaller srvInst = new ServiceInstaller();

            srvInst.ServiceName = resinService.Name;
            srvInst.DisplayName = resinService.Name;
            srvInst.Description = "Service: " + Version.FULL_VERSION;
            srvInst.StartType   = ServiceStartMode.Automatic;

            txInst.Installers.Add(srvInst);

            return(txInst);
        }
Ejemplo n.º 2
0
        public void InstallService(ResinService resinService, bool isNew)
        {
            if (isNew)
            {
                Installer installer    = InitInstaller(resinService);
                Hashtable installState = new Hashtable();
                installer.Install(installState);
                StoreState(installState, resinService.Name);
            }

            RegistryKey system            = Registry.LocalMachine.OpenSubKey("System");
            RegistryKey currentControlSet = system.OpenSubKey("CurrentControlSet");
            RegistryKey servicesKey       = currentControlSet.OpenSubKey("Services");
            RegistryKey serviceKey        = servicesKey.OpenSubKey(resinService.Name, true);
            String      imagePath         = (String)serviceKey.GetValue("ImagePath");

            if (imagePath.Contains(".exe\""))
            {
                imagePath = imagePath.Substring(0, imagePath.IndexOf(".exe\"") + 5);
            }
            else if (imagePath.Contains(".exe"))
            {
                imagePath = imagePath.Substring(0, imagePath.IndexOf(".exe\"") + 4);
            }

            StringBuilder builder = new StringBuilder(imagePath);

            builder.Append(' ').Append(resinService.GetServiceArgs());

            serviceKey.SetValue("ImagePath", builder.ToString());
        }
Ejemplo n.º 3
0
        public void UninstallService(ResinService resinService)
        {
            Hashtable state = LoadState(resinService.Name);

            Installer installer = InitInstaller(resinService);

            installer.Uninstall(state);
        }
Ejemplo n.º 4
0
 public void AddResinService(ResinService service)
 {
     _resinServices.Add(service);
 }
Ejemplo n.º 5
0
 public bool HasResinService(ResinService service)
 {
     return(_resinServices.Contains(service));
 }
Ejemplo n.º 6
0
        public void FindResinServices()
        {
            RegistryKey services = Registry.LocalMachine.OpenSubKey(Setup.REG_SERVICES);

            if (services == null)
            {
                return;
            }

            foreach (String name in services.GetSubKeyNames())
            {
                RegistryKey key = services.OpenSubKey(name);

                if (key == null)
                {
                    continue;
                }

                try
                {
                    Object imagePathObj = key.GetValue("ImagePath");

                    if (imagePathObj == null || "".Equals(imagePathObj))
                    {
                        continue;
                    }

                    String imagePath = (String)imagePathObj;

                    String lowerCaseImagePath = imagePath.ToLower();

                    if ((imagePath.IndexOf("resin.exe") > 0 ||
                         imagePath.IndexOf("httpd.exe") > 0) &&
                        imagePath.IndexOf("-service") > 0)
                    {
                        ResinArgs resinArgs = new ResinArgs(imagePath);

                        ResinService resin = null;
                        if (resinArgs.ResinHome != null)
                        {
                            resin      = new ResinService();
                            resin.Home = resinArgs.ResinHome;
                        }
                        else if (resinArgs.Exe != null)
                        {
                            String exe  = resinArgs.Exe;
                            String home = exe.Substring(0, exe.Length - 10);
                            if (Util.IsResinHome(home))
                            {
                                resin      = new ResinService();
                                resin.Home = home;
                            }
                        }

                        if (resin == null)
                        {
                            continue;
                        }

                        resin.Exe = resinArgs.Exe;

                        resin.Name                 = name;
                        resin.Server               = resinArgs.Server;
                        resin.DynamicServer        = resinArgs.DynamicServer;
                        resin.ElasticServer        = resinArgs.ElasticServer;
                        resin.Cluster              = resinArgs.Cluster;
                        resin.Root                 = resinArgs.ResinRoot;
                        resin.Conf                 = resinArgs.Conf;
                        resin.Log                  = resinArgs.Log;
                        resin.User                 = "******";
                        resin.JavaHome             = resinArgs.JavaHome;
                        resin.ElasticServerAddress = resinArgs.ElasticServerAddress;
                        resin.ElasticServerPort    = resinArgs.ElasticServerPort;

                        if (resinArgs.JmxPort != null && !"".Equals(resinArgs.JmxPort))
                        {
                            resin.JmxPort = int.Parse(resinArgs.JmxPort);
                        }

                        if (resinArgs.DebugPort != null && !"".Equals(resinArgs.DebugPort))
                        {
                            resin.DebugPort = int.Parse(resinArgs.DebugPort);
                        }

                        if (resinArgs.WatchDogPort != null && !"".Equals(resinArgs.WatchDogPort))
                        {
                            resin.WatchdogPort = int.Parse(resinArgs.WatchDogPort);
                        }

                        resin.IsPreview = resinArgs.IsPreview;

                        resin.ExtraParams = resinArgs.ResinArguments;

                        AddResinService(resin);
                    }
                }
                catch (Exception e)
                {
                    LogStartupError(e.Message, e);
                }
                finally
                {
                    key.Close();
                }
            }

            services.Close();
        }