Пример #1
0
        public UnitConfiguration ToSystemdConfiguration()
        {
            var unit = new UnitSection {
                Description = Description ?? (Name + " Service")
            };

            string env = Environment != null
                ? string.Join(" ", Environment.Variables.Select(pair => pair.Key + "=" + pair.Value))
                : null;

            string execStart = Start.FileName.StartsWith("/")
                ? Start.ToString()
                : WorkingDirectory + "/" + Start.ToString();

            var service = new ServiceSection {
                WorkingDirectory = WorkingDirectory,
                ExecStart        = execStart,
                Environment      = env,
                User             = User.ToString(),
                SyslogIdentifier = Name
            };

            if (RestartPolicy != null)
            {
                switch (RestartPolicy.Condition)
                {
                case RestartCondition.Always: service.Restart = RestartOptions.Always;     break;

                case RestartCondition.OnFailure: service.Restart = RestartOptions.OnFailure;  break;

                case RestartCondition.OnAbormal: service.Restart = RestartOptions.OnAbnormal; break;
                }

                if (RestartPolicy.Delay != null)
                {
                    service.RestartSec = (int)RestartPolicy.Delay.Value.TotalSeconds;
                }
            }

            return(new UnitConfiguration {
                Unit = unit,
                Service = service,
                Install = new InstallSection {
                    WantedBy = "multi-user.target"
                }
            });
        }
Пример #2
0
 private void AddNewUnitToRoom(UnitSection unitSection)
 {
     ListOfUnitsInRoom.Add(unitSection.ID, unitSection);
     ActiveIDs.Add(unitSection.ID);
 }