supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: Rio Liu <rio.liu@r26.me>
To: Supervision <supervision@list.skarnet.org>
Subject: Re: s6 xinit replacement?
Date: Tue, 17 May 2022 04:10:19 +0000	[thread overview]
Message-ID: <Yhc8_zshLRSrqL6cCfe-4wpatPuHulqPHfexWzCL382rWhrXQ_1gUwggTE0E30Bc9qh1b3d1eBZ8XHx02Ih2x2y6EB7ZfKt8wm1-Q-ORqLY=@r26.me> (raw)
In-Reply-To: <CADQ2Nw9eUToXLs2_aknP28JUnVYUfDCBcrYDmq-MeKZjs7ccaQ@mail.gmail.com>

This thread has inspired me to move my desktop setup under s6 this weekend. Here's what I got:

General flow: boot to tty1 -> login -> bash starts bashrc -> bashrc sets DISPLAY and TTY env vars then exec into s6-svscan -> s6-svscan starts xserver, window manager, and other desktop services.

Reading Samuel's reply, I find the easiest way to get around the controlling terminal issue is to give Xorg capability: `setcap cap_sys_tty_config=+eip /usr/lib/Xorg`. (Considering Chromium has cap_sys_admin, letting Xorg control ttys doesn't seem that bad). Setting the owner of tty doesn't quite work in my case because of the login shell is attached to tty1 already.

In my bashrc, I have some logic to check whether X should be started. Eventually, it runs this code:

exec execlineb /dev/stdin << EOF
s6-setsid -q
piperw 4 3
background {
  fdclose 3 fdmove 0 4
  foreground { redirfd -w 1 /dev/null cat }
  foreground { s6-rc-init -l "$S6/live" -c "$S6/compiled" "$S6/service" }
  s6-rc -l "$S6/live" -up change "$1"
}

fdclose 4
s6-svscan -d 3 "$S6/service"
EOF

And I have $HOME/.service/xserver-srv/run that replaces startx/sx:

#!/usr/bin/execlineb -P
fdmove -c 2 1

importas DISPLAY DISPLAY
importas TTY TTY

if { test -r /dev/dri/card0 }
if { test -n "${DISPLAY}" }

backtick -E cookie { xxd -l 16 -ps /dev/urandom }
foreground { xauth add "${DISPLAY}" MIT-MAGIC-COOKIE-1 "${cookie}" }

Xorg "${DISPLAY}" -displayfd 3 "vt${TTY}"

With a finish file:

#!/usr/bin/execlineb -P
if { test -n "$DISPLAY" }
xauth remove "$DISPLAY"

The window manager, pulseaudio server, and a few other services are started together as well, using s6-rc to depend on xserver.

This is what I ended up with:

s6-supervise agetty-tty1
 \_ login -- rio
     \_ s6-svscan -d 3 /tmp/rio/s6/1/service
         \_ s6-supervise xss-lock
         |   \_ xss-lock -- s6-svc -1 /run/service/locker
         \_ s6-supervise xserver-srv
         |   \_ /usr/lib/Xorg :1 -displayfd 3 vt1
         \_ s6-supervise xserver-log
         |   \_ s6-log -- n4 T /tmp/rio/s6/1/log/xserver
         \_ s6-supervise xbanish
         |   \_ xbanish -i mod1 -i mod4 -i control
         \_ s6-supervise syndaemon
         |   \_ syndaemon -tki 0.2
         \_ s6-supervise pulseaudio-srv
         |   \_ pulseaudio --exit-idle-time=-1 --daemonize=no
         |       \_ /usr/lib/pulse/gsettings-helper
         \_ s6-supervise pulseaudio-log
         |   \_ s6-log -- -system_bus_socket T /tmp/rio/s6/1/log/pulseaudio
         \_ s6-supervise gcin
         |   \_ gcin
         \_ s6-supervise awesome
         |   \_ awesome --no-argb
         \_ s6-supervise s6rc-fdholder
         |   \_ s6-fdholderd -1 -i data/rules
         \_ s6-supervise s6rc-oneshot-runner

Now there are probably issues here and there, as I just got it running. Suggestions welcome.

Rio

  reply	other threads:[~2022-05-17  4:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11  3:36 dallinjdahl
2022-05-14  3:47 ` Guillermo
2022-05-14 23:45   ` dallinjdahl
2022-05-15  1:52     ` Laurent Bercot
2022-05-15 15:02       ` Guillermo
2022-05-17  4:10         ` Rio Liu [this message]
2022-05-15  2:44   ` Samuel Holland
2022-05-22 15:07     ` Guillermo
2022-05-22 16:33       ` Samuel Holland
2022-05-23 10:05       ` yianiris
2022-05-23 23:40         ` Guillermo
2022-05-27  2:04         ` Steve Litt
2022-05-28  4:07     ` Dallin Dahl
2022-05-28 17:15     ` Dallin Dahl
2022-05-28 19:43       ` Samuel Holland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='Yhc8_zshLRSrqL6cCfe-4wpatPuHulqPHfexWzCL382rWhrXQ_1gUwggTE0E30Bc9qh1b3d1eBZ8XHx02Ih2x2y6EB7ZfKt8wm1-Q-ORqLY=@r26.me' \
    --to=rio.liu@r26.me \
    --cc=supervision@list.skarnet.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).