Skip to content

Commit

Permalink
Improve session shutdown and switch to full-screen window manager
Browse files Browse the repository at this point in the history
* exit trap will now kill all subprocesses
* watchdog will kill its sleep process
* matchbox better suited to kiosk mode than metacity

Note: Add all window classes that should not be made full screen to matchbox call
  • Loading branch information
schlomo committed Nov 12, 2014
1 parent 5a522fa commit 8f0de7f
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 145 deletions.
4 changes: 2 additions & 2 deletions src/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: kiosk-browser
Version: 41
Version: 42
Priority: optional
Section: web
Architecture: all
Maintainer: Schlomo Schapiro <kiosk-browser@schlomo.schapiro.org>
Pre-Depends: nodm
Depends: chromium | chromium-browser, x11-xserver-utils, metacity, xdotool, x11-apps, sudo, imagemagick, debconf, xtightvncviewer, xosd-bin, xosview
Depends: chromium | chromium-browser, x11-xserver-utils, xdotool, x11-apps, sudo, imagemagick, debconf, xtightvncviewer, xosd-bin, xosview, matchbox-window-manager
Homepage: https://github.com/ImmobilienScout24/kiosk-browser
Description: Kiosk Browser
Setup system to work as a kiosk browser, showing only a full-screen browser.
Expand Down
9 changes: 7 additions & 2 deletions src/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ echo "/usr/sbin/nodm" >/etc/X11/default-display-manager
ln -sf nodm /usr/sbin/kiosk-browser

# disable X cursor
sed -i -e 's/NODM_X_OPTIONS=.*/NODM_X_OPTIONS="-nocursor -nolisten tcp"/' -e 's/NODM_ENABLED=.*/NODM_ENABLED=true/' -e 's/NODM_USER=.*/NODM_USER=kiosk-browser/' /etc/default/nodm
sed -i \
-e 's/NODM_X_OPTIONS=.*/NODM_X_OPTIONS="-nocursor -nolisten tcp"/' \
-e 's/NODM_ENABLED=.*/NODM_ENABLED=true/' \
-e 's/NODM_USER=.*/NODM_USER=kiosk-browser/' \
-e 's#NODM_XSESSION=.*#NODM_XSESSION=/usr/bin/kiosk-browser-xsession#' \
/etc/default/nodm

# allow kiosk user to only write in directories needed by chromium
mkdir -p /var/lib/kiosk-browser/{.cache,.config/chromium,.pki}
Expand All @@ -33,7 +38,7 @@ fi
if pgrep -u kiosk-browser >/dev/null ; then
service nodm stop || :
echo "Waiting for kiosk-browser processes to exit..."
sleep 20 # wait for chromium and other subprocesses to exit
sleep 5 # wait for chromium and other subprocesses to exit
fi

# always start nodm
Expand Down
149 changes: 149 additions & 0 deletions src/usr/bin/kiosk-browser-xsession
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/bin/bash
exec 2> >(logger -t kiosk-browser)

KILL_ON_EXIT=
function exittrap {
kill $KILL_ON_EXIT $(jobs -p)
}

trap exittrap 0 # kill subprocesses on exit


# windows manager helps with fullscreen
matchbox-window-manager -use_titlebar no -force_dialogs xosview -use_dialog_mode free &

# show debug info for 60 seconds as overlay
{
echo "Welcome to the Kiosk Browser (http://github.com/ImmobilienScout24/kiosk-browser)"
echo
echo "This is $(uname -n)"
ip a
ip route
cat /etc/resolv.conf
perl -e '$/ = undef; $d=<>; $d =~ m/.*(lease {.*?})$/s ; print $1' $(ps ax | grep dhclient | sed -ne "s/.* \(\/[^ ]\+\.lease[s]\?\).*/\1/p") <<<""
echo
echo "This message will self-destruct in 60 seconds"
} | osd_cat --pos bottom --align left --colour green --font 10x20 --lines 50 --delay 60 &

wait $!

# cache xrandr configuration
XRANDR_OUTPUT="$(xrandr)"
function xrandr_find_port {
# find connected port matching pattern
read port junk < <(grep connect <<<"$XRANDR_OUTPUT" | grep -i "$1") ; echo $port
}

function xrandr_find_other_ports {
# find ports NOT matching pattern
grep connect <<<"$XRANDR_OUTPUT" | cut -f 1 -d " " | grep -v $(xrandr_find_port "$1")
}

set -x
if test -r /etc/default/kiosk-browser ; then
source /etc/default/kiosk-browser
fi


if [[ ! "$KIOSK_BROWSER_PORTS" ]] ; then
# set . as a built-in default to use the first connected port that xrandr reports
KIOSK_BROWSER_PORTS=.
fi

if [[ ! "$KIOSK_BROWSER_START_PAGE" ]] ; then
# point to our github page as built-in default
KIOSK_BROWSER_START_PAGE=https://github.com/ImmobilienScout24/kiosk-browser
fi

if [[ ! "$KIOSK_BROWSER_WATCHDOG_TIMEOUT" ]] ; then
# default stale screen watchdog is 1h
KIOSK_BROWSER_WATCHDOG_TIMEOUT=3600
fi

if [[ ! "$KIOSK_BROWSER_VNC_VIEWER_DISPLAY" ]] ; then
# disable VNC viewer by default
KIOSK_BROWSER_VNC_VIEWER_DISPLAY=0
fi

# configure displays
xrandr $(
xrandr_position=
for (( c=0 ; c<${#KIOSK_BROWSER_PORTS[@]} ; c++ )) ; do
port=$(xrandr_find_port "${KIOSK_BROWSER_PORTS[c]}")
echo "--output $port ${KIOSK_BROWSER_XRANDR_EXTRA_OPTS[c]} $xrandr_position --auto"
xrandr_position="--right-of $port"
done
)
sleep 3

# xrandr configuration changed, update cache
XRANDR_OUTPUT="$(xrandr)"

# disable screen blanking
xset -dpms
xset s off
xset s noblank

# start watchdog, reboot system if screen stops to change
if (( KIOSK_BROWSER_WATCHDOG_TIMEOUT > 0 )) ; then
(
trap 'exittrap' TERM

LASTHASH=""
LASTCHANGED="$SECONDS"
while sleep "${KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL:-313}" & wait ; do
HASH=$(nice import -display :0 -window root -monochrome jpg:- | nice identify -format '%#' -)
#declare -p HASH LASTHASH LASTCHANGED SECONDS
if [[ "$HASH" = "$LASTHASH" ]] ; then
if (( SECONDS > LASTCHANGED + KIOSK_BROWSER_WATCHDOG_TIMEOUT )) ; then
sudo /sbin/reboot
break
fi
else
LASTHASH="$HASH"
LASTCHANGED="$SECONDS"
fi
done
) </dev/null 1>&2 &
fi

if [[ "$KIOSK_BROWSER_SHOW_SYSTEM_MONITOR" ]] ; then
xosview &
fi

# start vnc viewer if requested
if [[ "$KIOSK_BROWSER_VNC_VIEWER_DISPLAY" ]] && (( KIOSK_BROWSER_VNC_VIEWER_DISPLAY >= 0 )) ; then
vncviewer -fullscreen -viewonly -listen "$KIOSK_BROWSER_VNC_VIEWER_DISPLAY" &
fi

# Ubuntu has chromium-browser and Debian wheezy has chromium
CHROME=$(type -p chromium-browser 2>/dev/null)
if [[ -z "$CHROME" ]] ; then
CHROME=$(type -p chromium 2>/dev/null)
fi

# remember system jobs
KILL_ON_EXIT=$(jobs -p)
# the wait below should wait only for the browsers and not hang on the system jobs
disown -a

while true; do
# exit if no display given, use xwininfo to test for running X server
xwininfo -root &>/dev/null || exit 0
# wipe state data
rm -Rf ~/.config/chromium/* ~/.cache/* ~/.pki/*
# if KIOSK_BROWSER_PORTS is set, assume that it specifies multiple screens connected.
for (( c=0 ; c<${#KIOSK_BROWSER_PORTS[@]} ; c++ )) ; do
$CHROME --user-data-dir=$HOME/.config/chromium/$c "${KIOSK_BROWSER_OPTIONS[@]}" --disable-translate --no-first-run "${KIOSK_BROWSER_START_PAGE[c]:-$KIOSK_BROWSER_START_PAGE}" &
sleep 30
# move new window to the current screen. We identify the window by the --user-data-dir option which appears in the window class name :-)
port=$(xrandr_find_port "${KIOSK_BROWSER_PORTS[c]}")
port_x=$(sed -ne "/$port/s#[^+].*+\([0-9]\+\)+.*#\1#p" <<<"$XRANDR_OUTPUT")
xdotool search --classname chromium/$c windowmove --sync $port_x 0 key F11
done

wait # for the browsers to finish
sleep 15
done

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
141 changes: 0 additions & 141 deletions src/var/lib/kiosk-browser/.xsession

This file was deleted.

0 comments on commit 8f0de7f

Please sign in to comment.