[systemd-devel] autostart processes based on tty
Mantas Mikulėnas
grawity at gmail.com
Mon May 16 05:04:58 UTC 2016
On Mon, May 16, 2016 at 5:09 AM, Emanuel Berg <embe8573 at student.uu.se>
wrote:
> I would like to start different processes in
> different ttys on boot, automatically and with
> autologin first, and then have them run as normal
> programs, with the I/O intact, including quitting
> and get the shell - i.e., just as you would if you
> did it all manually. (The autologin part of the
> above question I solved.)
>
> Up and until today, I've done this with zsh in
> .zprofile, and I include it here so you'll know
> exactly what I ask for:
>
> # ...
>
> local tty_number=${TTY#/dev/tty}
>
> case $tty_number in
> (1) lkeys # [1]
> make -C ~/.emacs.d/emacs-init
> emacs ;;
> (2|3) tmux-new-session-split ;;
> (5) echo "Waiting for Internet connection..."
> when-internet-set-time > /dev/null # ~/.zsh/web
> tmux ;;
> (6) start-x-if-not-running & ;;
> esac
>
> # ...
>
> I thought it'd be a good idea to do it with systemd!
>
~/.zprofile seems just fine for this task – it *is* the zsh "run things on
login" script after all. (And since these are your personal processes,
especially the X stuff, it's much better to have them running *inside* the
login session along with everything else.)
Trying to cram these into systemd .services would only overcomplicate
things.
>
> As a test, I tried to do it with top(1) in
> /dev/tty4, and I got this far
>
> [Unit]
> Description=top on tty4
>
> [Service]
> Type=simple
> ExecStart=/usr/bin/top
> StandardInput=tty
> StandardOutput=tty
> TTYPath=/dev/tty4
> Restart=always
>
> [Install]
> WantedBy=getty.target
>
> This results in a running process, but it doesn't
> seem to be associated with /dev/tty4 and there is no
> I/O there but the familiar shell.
>
I'm not sure of the exact conditions, but sometimes (depending on various
[Service] settings) TTYPath= uses exclusive access mode – only one service
at a time is allowed. If it didn't, then you'd have both top and getty
trying to display things *at once*, and trying to read from the keyboard at
once as well.
To make this work at all, you'd need Conflicts=getty at tty4.service and some
way to start the getty@ again once your custom service has exit. Or,
perhaps, Type=oneshot + Before=getty at tty4 + an infinite timeout. (Also
you'd of course need User=emanuel, some PAMName=, and so on – autostarting
top as root isn't the best idea.)
> PS. I would say this is a ".user" question but
> I couldn't find such a group!
>
For the time being, systemd-devel@ is multipurpose. It doesn't really
receive enough traffic to warrant separation, IMHO.
--
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160516/a52e6820/attachment.html>
More information about the systemd-devel
mailing list