Пример #1
0
        public KillProcessStatus TryStopService(string serviceName)
        {
            var map     = ServiceMap.LoadSettings();
            var process = map.Items.FirstOrDefault(i => i.ServiceName == serviceName);

            if (process == null)
            {
                return(KillProcessStatus.TaskNotFound);
            }

            return(ServiceProcessManager.KillProcess(process.ServiceName, process.ServiceExecFileName));
        }
Пример #2
0
        public StartProcessStatus TryStartService(string serviceName)
        {
            var map     = ServiceMap.LoadSettings();
            var process = map.Items.FirstOrDefault(i => i.ServiceName == serviceName);

            if (process == null)
            {
                return(StartProcessStatus.NotFound);
            }

            return(ServiceProcessManager.StartProcess(process.ServiceName));
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Read from the expermental.json
            log4net.Config.XmlConfigurator.Configure();

            try
            {
                var assembly  = typeof(Program).Assembly;
                var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
                var id        = attribute.Value;
                using (new SingleAppMutexControl(id))
                {
                    CheckArguements(args);
                    var    apiHost = ConsulAgent.GetApiHost(_apiHostName).GetAwaiter().GetResult();
                    byte[] hashvalue;
                    byte[] newHash;

                    do
                    {
                        hashvalue = GenerateHash(apiHost.Value);
                        var apiServices = ConsulAgent.GetApiHostsServices(_apiHostName);

                        // download from the s3 location
                        foreach (var service in apiServices[_apiHostName])
                        {
                            var serviceProcessManager = new ServiceProcessManager();
                            var userdataFile          = ConsulAgent.GetUserDataJsonFile(service).GetAwaiter().GetResult();

                            if (!serviceProcessManager.RedeployService(userdataFile))
                            {
                                continue;
                            }

                            Logger.Debug("Starting zip download of -");
                            Logger.Debug($"Service Name: {service}");

                            var archiveFileName = ConsulAgent.GetServiceS3ZipFile(service).GetAwaiter().GetResult();
                            var version         = JObject.Parse(Encoding.UTF8.GetString(userdataFile, 0, userdataFile.Length))
                                                  .Value <string>("Version");

                            Logger.Debug($"Version: {version}");

                            var outfolder = _baseDirectory + $"{service}_{version}";
                            ServiceDownloader.ExtractZipFile(archiveFileName, null, outfolder);

                            ServiceDownloader.CreateUserDataFile(userdataFile, outfolder);
                            serviceProcessManager.StartProcess(service, outfolder, version);
                        }

                        apiHost = ConsulAgent.GetApiHost(_apiHostName).GetAwaiter().GetResult();
                        newHash = GenerateHash(apiHost.Value);
                    } while (Encoding.ASCII.GetString(hashvalue) != Encoding.ASCII.GetString(newHash));
                }
            }
            catch (TimeoutException timeoutException)
            {
                Logger.Error($"Timeout Exception. {timeoutException}");
            }
            catch (Exception ex)
            {
                Logger.Error($"Messaging: {ex}");
            }
        }