Skip to content

Commit

Permalink
Vastly improved exit handling.
Browse files Browse the repository at this point in the history
Some cleanups and little improvements with epiphany-browser and uzbl (though they still don't work well)
  • Loading branch information
schlomo committed Feb 13, 2015
1 parent a511d47 commit 25403d9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ And next to it another file with the HTML code, named `dashboard.html`:
</html>

Finally, adjust `KIOSK_BROWSER_START_PAGE` in `/etc/default/kiosk-browser` to point to this `dashboard.html` and you are done.

Hacking
=======

The kiosk-browser user session creates a temporary Home Directory under `/tmp`. To access the running kiosk-browser session use `kiosk-browser-control interactive`. In the shell you can use `cd` to go to the session Home Directory.
2 changes: 1 addition & 1 deletion src/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: kiosk-browser
Version: 47
Version: 48
Priority: optional
Section: web
Architecture: all
Expand Down
10 changes: 8 additions & 2 deletions src/usr/share/kiosk-browser/openbox-rc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ openbox configuration for kiosk-browser
xmlns:xi="http://www.w3.org/2001/XInclude">

<applications>
<application name="*xosview*">
<application name="*">
<decor>no</decor>
</application>

<application name="*xosview*">
<desktop>all</desktop>
<layer>above</layer>
<skip_pager>yes</skip_pager>
<skip_taskbar>yes</skip_taskbar>
</application>

<application class="Chromium">
<decor>no</decor>
<maximized>true</maximized>
</application>

<application name="uzbl*">
<fullscreen>yes</fullscreen>
</application>
</applications>

</openbox_config>
58 changes: 35 additions & 23 deletions src/usr/share/kiosk-browser/xsession.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/bin/bash
exec &> >(logger -t kiosk-browser)
exec &> >(logger -t "kiosk-browser[$$]" )

KILL_ON_EXIT=
HOME=$( mktemp -d -t kiosk-browser.HOME.XXXXXXXXXXXXX )
HOME=$( mktemp -d /tmp/kiosk-browser.HOME.XXXXXXXXXXXXX )
function exittrap {
kill -9 $KILL_ON_EXIT $(jobs -p)
sleep 2
rm -Rf $HOME
procs=( $KILL_ON_EXIT $(jobs -p))
kill -TERM ${procs[@]}
(
# wait in background for all procs to be gone before removing the old home directory
# reason is that nodm KILLs the session a short time after TERMinating it
sleep 5 &
wait $!
kill -KILL $KILL_ON_EXIT ${procs[@]} &>/dev/null
rm -Rf $HOME
) </dev/null &
}
trap exittrap EXIT # kill subprocesses on exit

trap exittrap 0 # kill subprocesses on exit


# window manager helps with fullscreen, window manager must support XINERAMA for multi-screen setups
openbox --debug --config-file /usr/share/kiosk-browser/openbox-rc.xml &

# show debug info for 60 seconds as overlay
{
Expand All @@ -27,7 +30,12 @@ openbox --debug --config-file /usr/share/kiosk-browser/openbox-rc.xml &
echo
echo "This message will self-destruct in 60 seconds"
} | osd_cat --pos bottom --align left --colour green --outline 2 --font 10x20 --lines 50 --delay 60 &
#wait $!

disown -a # forget about running osd_cat, it will terminate itself anyway

# window manager helps with fullscreen, window manager must support XINERAMA for multi-screen setups
openbox --debug --config-file /usr/share/kiosk-browser/openbox-rc.xml &


# cache xrandr configuration
XRANDR_OUTPUT="$(xrandr)"
Expand Down Expand Up @@ -57,6 +65,7 @@ if [[ ! "$KIOSK_BROWSER_START_PAGE" ]] ; then
KIOSK_BROWSER_START_PAGE=https://github.com/ImmobilienScout24/kiosk-browser
fi

KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL="${KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL:-313}"
if [[ ! "$KIOSK_BROWSER_WATCHDOG_TIMEOUT" ]] ; then
# default stale screen watchdog is 1h
KIOSK_BROWSER_WATCHDOG_TIMEOUT=3600
Expand All @@ -76,7 +85,9 @@ xrandr $(
xrandr_position="--right-of $port"
done
)
sleep 10 &

# wait a moment for displays to settle
sleep 5 &
wait $!

# xrandr configuration changed, update cache
Expand All @@ -90,11 +101,13 @@ xset s noblank
# start watchdog, reboot system if screen stops to change
if (( KIOSK_BROWSER_WATCHDOG_TIMEOUT > 0 )) ; then
(
trap 'kill $(jobs -p) ; sleep 1 ; kill $(jobs -p) &>/dev/null' TERM
exec &> >(logger -t "kiosk-browser[$$]-watchdog" )
: "Starting watchdog. Timeout is $KIOSK_BROWSER_WATCHDOG_TIMEOUT seconds, checking every $KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL seconds"
trap 'kill -TERM $(jobs -p)' TERM

LASTHASH=""
LASTCHANGED="$SECONDS"
while sleep "${KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL:-313}" & wait ; do
while sleep $KIOSK_BROWSER_WATCHDOG_CHECK_INTERVAL & wait $! ; do
HASH=$(nice import -display :0 -window root -monochrome jpg:- | nice identify -format '%#' -)
#declare -p HASH LASTHASH LASTCHANGED SECONDS
if [[ "$HASH" = "$LASTHASH" ]] ; then
Expand All @@ -119,23 +132,22 @@ if [[ "$KIOSK_BROWSER_VNC_VIEWER_DISPLAY" ]] && (( KIOSK_BROWSER_VNC_VIEWER_DISP
vncviewer -fullscreen -viewonly -listen "$KIOSK_BROWSER_VNC_VIEWER_DISPLAY" &
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

# 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

UZBL_CONFIG="set show_status=0
set geometry=maximized"

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/* ~/profile*
# if KIOSK_BROWSER_PORTS is set, assume that it specifies multiple screens connected.
for (( c=0 ; c<${#KIOSK_BROWSER_PORTS[@]} ; c++ )) ; do
port=$(xrandr_find_port "${KIOSK_BROWSER_PORTS[c]}")
Expand All @@ -153,7 +165,7 @@ while true; do
# Use PID to distinguish browsers
xdotool search --class epiphany-$c windowmove --sync $port_x 0 key F11
elif [[ "$KIOSK_BROWSER_PROGRAM" == "uzbl" ]] && type -p uzbl &>/dev/null ; then
uzbl -n uzbl-$c "$URL" &
uzbl -n uzbl-$c -c - "$URL" <<<"$UZBL_CONFIG" &
sleep 5 &
wait $!
xdotool search --class uzbl-$c windowmove --sync $port_x 0
Expand Down

0 comments on commit 25403d9

Please sign in to comment.