public bool ReloadUnit(string name) { var transaction = UnitRegistry.GetUnit(name).GetReloadTransaction(); var result = transaction.Execute(); return(result.Type == Tasks.ResultType.Success); }
public void AddUnitByPath_UnitNotFound_True() { // Arrange UnitRegistry.UnitFiles.Clear(); UnitRegistry.Units.Clear(); // Act UnitRegistry.IndexUnitByPath($"{DirectoryName}/nonexistent-unit.service"); // Assert Assert.IsNull(UnitRegistry.GetUnit(TestUnitFilename)); }
public void AddUnitByPath_UnitFound_True() { // Arrange UnitRegistry.UnitFiles.Clear(); UnitRegistry.Units.Clear(); // Act UnitRegistry.IndexUnitByPath(TestUnitPath); // Assert Assert.IsNotNull(UnitRegistry.GetUnit(TestUnitFilename)); }
static void Main(string[] args) { Log.Info("SharpInit starting"); PlatformUtilities.RegisterImplementations(); PlatformUtilities.GetImplementation <IPlatformInitialization>().Initialize(); Log.Info("Platform initialization complete"); UnitRegistry.InitializeTypes(); UnitRegistry.ScanDefaultDirectories(); Log.Info($"Loaded {UnitRegistry.Units.Count} units"); UnitRegistry.UnitStateChange += StateChangeHandler; Log.Info("Registering IPC context..."); var context = new ServerIpcContext(); IpcFunctionRegistry.AddFunction(DynamicIpcFunction.FromContext(context)); Log.Info("Starting IPC listener..."); var ipc_listener = new IpcListener(); ipc_listener.StartListening(); Log.Info($"Listening on {ipc_listener.SocketEndPoint}"); if (UnitRegistry.GetUnit("default.target") != null) { Log.Info("Activating default.target..."); var result = UnitRegistry.CreateActivationTransaction("default.target").Execute(); if (result.Type == Tasks.ResultType.Success) { Log.Info("Successfully activated default.target."); } else { Log.Info($"Error while activating default.target: {result.Type}, {result.Message}"); } } Console.CancelKeyPress += (s, e) => { ipc_listener.StopListening(); }; Thread.Sleep(-1); }
public UnitInfo GetUnitInfo(string unit_name) { var unit = UnitRegistry.GetUnit(unit_name); var info = new UnitInfo(); info.Name = unit.UnitName; info.Path = unit.File.UnitPath; info.Description = unit.File.Description; info.State = Enum.Parse <Ipc.UnitState>(unit.CurrentState.ToString()); info.LastStateChangeTime = unit.LastStateChangeTime; info.ActivationTime = unit.ActivationTime; info.LoadTime = unit.LoadTime; return(info); }
public void PercentSpecifier_Checks() { // Arrange Environment.SetEnvironmentVariable("SHARPINIT_UNIT_PATH", DirectoryName); UnitRegistry.DefaultScanDirectories.Clear(); // Act UnitRegistry.ScanDefaultDirectories(); var unit_unspecified = UnitRegistry.GetUnit <ServiceUnit>(TestUnitFilename); var unit_specified = UnitRegistry.GetUnit <ServiceUnit>(TestUnitInstanceName); // Assert Assert.IsTrue(unit_unspecified.Descriptor.WorkingDirectory == "/" + StringEscaper.Unescape(unit_unspecified.Descriptor.DefaultInstance)); Assert.IsTrue(unit_specified.Descriptor.WorkingDirectory == "/" + StringEscaper.Unescape(UnitRegistry.GetUnitParameter(TestUnitInstanceName))); }
public override TaskResult Execute() { var failure_type = StopExecution ? ResultType.StopExecution : ResultType.Failure; var unit = UnitRegistry.GetUnit(TargetUnit); if (unit == null) { return(new TaskResult(this, failure_type, $"Unit {TargetUnit} is not loaded.")); } var state = unit.CurrentState; if (ComparisonState.HasFlag(state) || ComparisonState == UnitState.Any) { return(new TaskResult(this, ResultType.Success)); } return(new TaskResult(this, failure_type, $"Expected {TargetUnit} to be Active, it was instead {state}")); }
public UnitInfo GetUnitInfo(string unit_name) { var unit = UnitRegistry.GetUnit(unit_name); var info = new UnitInfo(); var unit_files = unit.Descriptor.Files.OfType <OnDiskUnitFile>(); info.Name = unit.UnitName; info.Path = unit_files.Any() ? string.Join(", ", unit_files.Select(file => file.Path)) : "(not available)"; info.Description = unit.Descriptor.Description; info.State = Enum.Parse <Ipc.UnitState>(unit.CurrentState.ToString()); info.LastStateChangeTime = unit.LastStateChangeTime; info.ActivationTime = unit.ActivationTime; info.LoadTime = unit.Descriptor.Created; return(info); }
public bool ReloadUnitFile(string unit) { UnitRegistry.GetUnit(unit).ReloadUnitFile(); return(true); }