[systemd-devel] nsapwned container terminal background color
zbyszek at in.waw.pl
Mon Mar 20 04:11:34 UTC 2017
On Sun, Mar 19, 2017 at 09:30:05PM +0000, Zbigniew Jędrzejewski-Szmek wrote:
> On Sun, Mar 19, 2017 at 04:37:53PM +0000, arnaud gaboury wrote:
> > I am trying with no success to have one background terminal color for the
> > host and another one for the container.
> > Some settings:
> > - on host:
> > window manager : i3
> > terminal : urxvt-256
> > -on container:
> > no X, it is a server.
> > Until now, I have tried to write a wrapper script to urxvt on host. This
> > script is to test value of $HOST or $TERM, then fire urxvt with background
> > color as option. This does not work.
> > I have to figure out that when i log my container, I am first on an urxvt
> > terminal which become, once I am logged as user on container, a xterm.
> > I am totally lost where to write instruction as the terminal color
> > background: on host or container? and what app shall be tested to set the
> > environment and decide the bg color (agetty?) ?
> Are you starting the container manually using systemd-nspawn in a terminal
> emulator window? If yes, then the following works (tested with gnome-terminal,
> but I think urxvt supports the same sequences):
> ExecStart=/usr/bin/printf '\033]11;darkgreen\007'
> ExecStop=/usr/bin/printf '\033]11;black\007'
> (It would be nicer to undo the setting and return to whatever the old
> background was, but I don't know how to do this.)
I figured it out, although it's a bit ugly ;)
==> /etc/systemd/system/bgcolor.service <==
Description=Set terminal background
ExecStart=/usr/local/bin/bgcolor.sh start /run/bgcolor.txt teal
ExecStop=/usr/local/bin/bgcolor.sh stop /run/bgcolor.txt
==> /usr/local/bin/bgcolor.sh <==
field=11 # background
if [ "$1" == "start" ]; then
stty raw -echo min 0
# OSC Ps ;Pt ST
IFS=';' read -t1 -r -d '\' answer
echo "$answer" | sed 's/^.*\;//;s/[^rgb:0-9a-f/]//g' >"$file"
elif [ "$1" == "stop" ]; then
This will set the background to teal during early boot, storing the
original color in the specified file, and reset it back during
shutdown. It seems to interfere with the systemd console output
(newlines get messed up), and sometimes the restoration does not
work. I suspect that both issues are caused by interference of
systemd printing to the console concurrently with the script. Most
likely putting a verify&retry loop around the query for original
color would fix the second issue.
More information about the systemd-devel