Re: How to setup a local s6-rc database and plug it into the supervision tree
Reply #15 –
Pretty much. Like runit, s6 services are intended to be one service = one process; therefore, an additional s6-svscan longrun and s6-rc oneshot, importing the USER2 variable, would be needed.
adminsv isn't completely out of question yet. Simplifying s6-rc-user's up to:
#!/bin/execlineb -P
envfile /etc/s6/config/user-services.conf
importas -uD "username" USER USER
s6-setuidgid ${USER} s6-rc-init -c /home/${USER}/.local/share/s6/rc/compiled -l /tmp/${USER}/s6-rc /tmp/${USER}/service
and leaving each users' s6-svscan/s6-rc on the default bundle is fine, since s6-rc-init by itself doesn't bring up any services.
I'd add .bash_profile might not be the best place since (1) it's run every time a terminal is open (2) s6-rc -up change default will close all non-default services due to the -p option (3) the logout question is still left unanswered.
The ideal place for what you're suggesting would be a PAM module, which is, in fact, able to be handle login and logout. There's a niche Linux distro called Chimaera Linux using the PAM module idea as we speak (but for dinit, and no easy way to use s6 with it).and First-login and last-logout hooks on elogind would be nicer, though.
Hey, can't we try that with a modified pam_rundir? Calling "bonus section" script on login and s6-svscanctl -t /tmp/$USER/service on logout? /run/user/$UID/{service,s6-rc} instead of /tmp/$USER/{service,s6-rc looks interesting, even.
The bonus section is definitely easier. However, plugging in the root tree gives you supervision (already mentioned), you get to learn about how important environment variables are, and a predictable environment, independent of your .bashrc and co, for your services.
I save my user logs on $HOME/.var/log folder created by Flatpak, because... why not. I created both a s6-svscan-capezotte-log service on adminsv (to ~/.var/log/uncaught-logs), and individual logger services on ~/.local/share/s6/sv (on ~/.var/log/dbus, ~/.var/log/gpg-agent, etc.). This is by no means an official recommendation by Skarnet or dudemanguy, that's what seemed logical to me.
Just the first approach is enough, since it prevents user logs from being sent to the root-only /run/uncaught-logs folder. The second makes a nice bonus, but isn't full without the first.