Add s6 support

Co-authored-by: userbook <userbook@devuan>
Co-authored-by: TerminalJunki <158248817+TerminalJunki@users.noreply.github.com>
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2024-07-27 15:00:07 +02:00
parent ce90f91bbf
commit 0cead672da
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F
4 changed files with 55 additions and 4 deletions

View File

@ -106,6 +106,11 @@ pub fn build(b: *std.Build) !void {
const installrunit_step = b.step("installrunit", "Install the Ly runit service"); const installrunit_step = b.step("installrunit", "Install the Ly runit service");
installrunit_step.makeFn = ServiceInstaller(.Runit).make; installrunit_step.makeFn = ServiceInstaller(.Runit).make;
installrunit_step.dependOn(installexe_step); installrunit_step.dependOn(installexe_step);
installopenrc_step.dependOn(installexe_step);
const installs6_step = b.step("installs6", "Install the Ly s6 service");
installs6_step.makeFn = ServiceInstaller(.S6).make;
installs6_step.dependOn(installexe_step);
const uninstallall_step = b.step("uninstallall", "Uninstall Ly and all services"); const uninstallall_step = b.step("uninstallall", "Uninstall Ly and all services");
uninstallall_step.makeFn = uninstallall; uninstallall_step.makeFn = uninstallall;
@ -123,12 +128,21 @@ const InitSystem = enum {
Systemd, Systemd,
Openrc, Openrc,
Runit, Runit,
S6,
}; };
pub fn ServiceInstaller(comptime init_system: InitSystem) type { pub fn ServiceInstaller(comptime init_system: InitSystem) type {
return struct { return struct {
pub fn make(step: *std.Build.Step, _: ProgressNode) !void { pub fn make(step: *std.Build.Step, _: ProgressNode) !void {
const allocator = step.owner.allocator; const allocator = step.owner.allocator;
switch (init_system) { switch (init_system) {
.Systemd => {
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/usr/lib/systemd/system" });
std.fs.cwd().makePath(service_path) catch {};
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
defer service_dir.close();
try std.fs.cwd().copyFile("res/ly.service", service_dir, "ly.service", .{ .override_mode = 0o644 });
},
.Openrc => { .Openrc => {
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/init.d" }); const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/init.d" });
std.fs.cwd().makePath(service_path) catch {}; std.fs.cwd().makePath(service_path) catch {};
@ -147,13 +161,22 @@ pub fn ServiceInstaller(comptime init_system: InitSystem) type {
try std.fs.cwd().copyFile("res/ly-runit-service/finish", service_dir, "finish", .{ .override_mode = 0o755 }); try std.fs.cwd().copyFile("res/ly-runit-service/finish", service_dir, "finish", .{ .override_mode = 0o755 });
try std.fs.cwd().copyFile("res/ly-runit-service/run", service_dir, "run", .{ .override_mode = 0o755 }); try std.fs.cwd().copyFile("res/ly-runit-service/run", service_dir, "run", .{ .override_mode = 0o755 });
}, },
.Systemd => { .S6 => {
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/usr/lib/systemd/system" }); const admin_service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/adminsv/default/contents.d" });
std.fs.cwd().makePath(admin_service_path) catch {};
var admin_service_dir = std.fs.cwd().openDir(admin_service_path, .{}) catch unreachable;
defer admin_service_dir.close();
const file = try admin_service_dir.createFile("ly-srv", .{});
file.close();
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/sv/ly-srv" });
std.fs.cwd().makePath(service_path) catch {}; std.fs.cwd().makePath(service_path) catch {};
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable; var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
defer service_dir.close(); defer service_dir.close();
try std.fs.cwd().copyFile("res/ly.service", service_dir, "ly.service", .{ .override_mode = 0o644 }); try std.fs.cwd().copyFile("res/ly-s6/run", service_dir, "run", .{ .override_mode = 0o755 });
try std.fs.cwd().copyFile("res/ly-s6/type", service_dir, "type", .{});
}, },
} }
} }
@ -258,6 +281,16 @@ pub fn uninstallall(step: *std.Build.Step, _: ProgressNode) !void {
std.fs.cwd().deleteTree(runit_service_path) catch { std.fs.cwd().deleteTree(runit_service_path) catch {
std.debug.print("warn: runit service not found.\n", .{}); std.debug.print("warn: runit service not found.\n", .{});
}; };
const s6_service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/sv/ly-srv" });
std.fs.cwd().deleteTree(s6_service_path) catch {
std.debug.print("warn: s6 service not found.\n", .{});
};
const s6_admin_service_file = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/adminsv/default/contents.d/ly-srv" });
std.fs.cwd().deleteFile(s6_admin_service_file) catch {
std.debug.print("warn: s6 admin service not found.\n", .{});
};
} }
fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion) ![]const u8 { fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion) ![]const u8 {

View File

@ -148,6 +148,21 @@ you should disable the agetty-tty2 service like this:
# rm /var/service/agetty-tty2 # rm /var/service/agetty-tty2
``` ```
### s6
```
# zig build installs6
```
Then, edit `/etc/s6/config/ttyX.conf` and set `SPAWN="no"`, where X is the TTY ID (e.g. `2`).
Finally, enable the service:
```
# s6-service add default ly-srv
# s6-db-reload
# s6-rc -u change ly-srv
```
### Updating ### Updating
You can also install Ly without copying the system service and the configuration file. That's You can also install Ly without copying the system service and the configuration file. That's
called *updating*. To update, simply run: called *updating*. To update, simply run:

2
res/ly-s6/run Normal file
View File

@ -0,0 +1,2 @@
#!/bin/execlineb -P
exec agetty -L -8 -n -l /usr/bin/ly tty2 115200

1
res/ly-s6/type Normal file
View File

@ -0,0 +1 @@
longrun