Archived
0
0
Fork 0

add support for just specifying service name

This commit is contained in:
Daryl Ronningen 2022-11-16 22:45:25 -08:00
parent 71c50ded5c
commit f70ff1f358
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
3 changed files with 37 additions and 11 deletions

View file

@ -3,16 +3,26 @@ using StartGrpc;
namespace netsd.Handlers;
public static class Start
public class Start
{
public static async Task StartAsync()
public Start(string? ServiceFilePath = null, string? ServiceName = null)
{
var parseServiceFile = await ServiceParser.Parse("/lib/systemd/system/sddm.service");
Console.WriteLine($"ExecStart: {parseServiceFile.ExecStart}");
if (ServiceFilePath == null && ServiceName != null)
{
if (!Path.Exists($"/etc/netsd/services/{ServiceName}.service"))
{
// TODO: Add proper error messages (and most likely something like serilog for logging)
Environment.Exit(1);
return;
}
ServiceFilePath = Path.GetFullPath($"/etc/netsd/services/{ServiceName}.service");
}
using var channel = UDSConnector.CreateChannel();
var client = new StartRpc.StartRpcClient(channel);
var reply = client.StartService(new StartRequest{ Name = "Awoo" });
var reply = client.StartService(new StartRequest{ Path = ServiceFilePath });
Console.WriteLine(reply.Success);
}

View file

@ -2,17 +2,33 @@ using System.CommandLine;
using netsd.Handlers;
var initCommand = new Command("init", "Run and bring up all default services");
var startCommand = new Command("start", "Starts up a netsd service");
var startServiceName = new Argument<string>("file", "The name of the service you want to start");
var startServicePath = new Option<FileInfo>("--file", "The path to the service file");
startServiceName.SetDefaultValue("");
startServicePath.AddAlias("-f");
startCommand.AddArgument(startServiceName);
startCommand.AddOption(startServicePath);
var rootCommand = new RootCommand("Linux service manager written in C#");
rootCommand.AddCommand(initCommand);
rootCommand.AddCommand(startCommand);
initCommand.SetHandler(() =>
{
new Init();
});
initCommand.SetHandler(() => new Init());
startCommand.SetHandler(async () => await Start.StartAsync());
startCommand.SetHandler((file, name) =>
{
if (name.Length != 0)
{
new Start(ServiceName: name);
}
else
{
new Start(ServiceFilePath: file.FullName);
}
}, startServicePath, startServiceName);
return await rootCommand.InvokeAsync(args);

View file

@ -9,7 +9,7 @@ service StartRpc {
}
message StartRequest {
string name = 1;
string path = 1;
}
message StartReply {