Auto launching Chrome on dedicated Zoneminder display

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
linuxsense
Posts: 374
Joined: Wed Nov 07, 2007 1:59 am
Location: Huntington Beach, California
Contact:

Auto launching Chrome on dedicated Zoneminder display

Post by linuxsense »

I figured I would share this in case someone else wants to do the same. I have been moving away from my old analog cams that I was running through a quad so I could display them on a LCD in my office so I needed a way to display my remaining analog cams as well as my IP cams. I tried using VLC and a few other methods but settled on using a custom montage page with the Chrome browser. It works very well but had a couple issues. Main one is from time to time one or all of the feeds would stall. Since looking at a 30 minute old stalled image does not do me any good I setup a cron job to kill chrome and relaunch it every two hours. The trick here is launching it into full screen and avoiding the 'restore previous tabs' prompt. Not a very tough task but finding documentation on the various command line options was. I found a lot of outdated and incomplete info. Ultimately I settled on two scripts. One to launch chrome when Unity starts (I have auto logon enabled for the account that runs on the server) and one to kill and re-launch Chrome on a schedule via cron. Here are the scripts...

Launch on Unity startup:

Code: Select all

#!/bin/bash
sleep 30
export DISPLAY=:0
/usr/bin/google-chrome-beta --disable-restore-background-contents http://zm/zm/montage.html >> /dev/null 2>&1 &
sleep 7
/usr/bin/xdotool key F11
Pretty simple and self explanatory but I'll explain anyway. The 30 second sleep is to make sure zoneminder is up and running before Chrome launches. The command to launch Chrome tells it to not nag about restoring the prior session. The next trick is to put Chrome into full screen. You can use the '--kiosk' option but if you do Chrome will be locked in that mode, you cant move it or minimize it. I couldnt find an option to put it into full screen so I have a small delay to make sure Chrome is ready then I send a 'F11' to it using xdotool. Works great. I have this script run via the startup programs utility but you could do it a few other ways.

For the relaunch script:

Code: Select all

#!/bin/bash
# This kills chrome and launches it to ensure ZM feeds are active.

# Kill off existing chome processes
if [[ -n `pidof chrome` ]];then
	kill -2 `pidof chrome`
fi
if [[ -n `pidof google-chrome-beta` ]];then
        kill -2 `pidof google-chrome-beta`
fi
# Set display so this works from cron
export DISPLAY=:0
# Launch chrome with option to disable 'restore' complaint
/usr/bin/google-chrome-beta --disable-restore-background-contents http://zm/zm/montage.html >> /dev/null 2>&1 &
# Pause to let Chrome launch
sleep 7
# Send the key to put Chrome into full screen mode. The --kiosk option could be used but it stays locked in that mode.
/usr/bin/xdotool key F11
# EOF
Pretty much the same as the other with some logic to kill all the chrome processes. You might need to tweak it to match whatever version of chrome you are running. I also use this one in combo with a job that restarts zoneminder each AM just to make sure one of my flaky cams feed stays active.

Enjoy.
Post Reply