From 412994775bd37542d135a972968439e48ee4b44f Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Fri, 17 Oct 2025 23:10:52 +0200 Subject: [PATCH] Add SysVinit service (closes #224) Signed-off-by: AnErrupTion --- build.zig | 11 +++++++++ readme.md | 10 ++++++++ res/ly-sysvinit | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 res/ly-sysvinit diff --git a/build.zig b/build.zig index b2864d5..1373f00 100644 --- a/build.zig +++ b/build.zig @@ -8,6 +8,7 @@ const InitSystem = enum { runit, s6, dinit, + sysvinit, }; const min_zig_string = "0.15.0"; @@ -308,6 +309,15 @@ fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void { const patched_service = try patchFile(allocator, "res/ly-dinit", patch_map); try installText(patched_service, service_dir, service_path, "ly", .{}); }, + .sysvinit => { + const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/init.d" }); + std.fs.cwd().makePath(service_path) catch {}; + var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable; + defer service_dir.close(); + + const patched_service = try patchFile(allocator, "res/ly-sysvinit", patch_map); + try installText(patched_service, service_dir, service_path, "ly", .{}); + }, } } @@ -339,6 +349,7 @@ pub fn Uninstaller(uninstall_config: bool) type { try deleteFile(allocator, config_directory, "/s6/adminsv/default/contents.d/ly-srv", "s6 admin service not found"); }, .dinit => try deleteFile(allocator, config_directory, "/dinit.d/ly", "dinit service not found"), + .sysvinit => try deleteFile(allocator, config_directory, "/init.d/ly", "sysvinit service not found"), } } }; diff --git a/readme.md b/readme.md index 4690b02..1919f91 100644 --- a/readme.md +++ b/readme.md @@ -159,6 +159,16 @@ To disable TTY 2, edit `/etc/s6/config/tty2.conf` and set `SPAWN="no"`. To disable TTY 2, go to `/etc/dinit.d/config/console.conf` and modify `ACTIVE_CONSOLES`. +### sysvinit + +``` +# zig build installexe -Dinit_system=sysvinit +# update-rc.d lightdm disable +# update-rc.d ly defaults +``` + +To disable TTY 2, go to `/etc/inittab` and comment out the line containing `tty2`. + ### Updating You can also install Ly without overrding the current configuration file. This diff --git a/res/ly-sysvinit b/res/ly-sysvinit new file mode 100755 index 0000000..f24dfd4 --- /dev/null +++ b/res/ly-sysvinit @@ -0,0 +1,65 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ly +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Ly display manager +# Description: Starts and stops the Ly display manager +### END INIT INFO +# +# Author: AnErrupTion +# + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DAEMON=/usr/bin/ly +TTY=/dev/tty$DEFAULT_TTY +PIDFILE=/var/run/ly.pid +NAME=ly +DESC="Ly display manager" + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Starting $DESC on $TTY..." + if [ -f "$PIDFILE" ]; then + log_progress_msg "$DESC is already running" + log_end_msg 0 + return 0 + fi + + # Ensure TTY exists + [ -c "$TTY" ] || { + log_failure_msg "$TTY does not exist" + return 1 + } + + start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE \ + --chdir / --exec /bin/sh -- -c "exec setsid sh -c 'exec <$TTY >$TTY 2>&1 $DAEMON'" + log_end_msg $? + ;; + stop) + log_daemon_msg "Stopping $DESC..." + start-stop-daemon --stop --pidfile $PIDFILE --retry 5 + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f "$PIDFILE" + log_end_msg $RETVAL + ;; + restart) + echo "Restarting $DESC..." + $0 stop + sleep 1 + $0 start + ;; + status) + status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0