Hi, so I've been fiddling for a while on and off to get this to work, and finally success.
I'm not great on linux so it's taken me a bit of googling to get this working.
Basically I have MC20 running in Ubuntu, with a couple of Windows computers running MC as clients, plus JRemote on an ipad.
Every now and then MC crashes on linux, and I have to manually restart it. Sometimes it's bothersome (when I'm at work and have to explain to the wife how to do it!) and I just want it to auto restart.
So I created the following script
log="/home/robert/scripts/checkmc20.log"
checkmc=`ls -ltr /var/crash/*mediacenter20* | wc -l`
if [ $checkmc -gt 0 ]
then
pkill apport
pkill mediacenter
now=$(date +%y%m%d%H%M)
cd /var/crash
for file in *mediacenter20*
do
mv "$file" "$file.$now"
done
mv *mediacenter20* /home/robert/Documents
sudo restart apport >> $log
echo "restarted mc20 $(date)" >> $log
##sudo -u root /usr/bin/mediacenter20 --revised per later post
/usr/bin/mediacenter20
fi
then set up cron using command "crontab -e"
*/5 * * * * export DISPLAY=:0 && sudo /home/robert/scripts/checkmc20
in other words, run "checkmc20" every 5 minutes. the "export" bit is needed to allow the script to launch an application with a gui window.
(see
http://www.jveweb.net/en/archives/2011/01/using-cronjobs-in-linux.html particularly the "launching a graphical program with cron" bit)
then, because the script contains "sudo" and i wanted it to run without needing a password, I added it to "sudoers"
see
http://luiseth.wordpress.com/2012/04/15/in-a-nutshell-add-permissions-with-configuration-files-in-etcsudoers-d/I created "checkmc20_sudo" in my home directory (apparently the file name must not contain a ~ or a .)
edit it and add something like the following
robert ALL=NOPASSWD: /home/robert/scripts/checkmc20
In other words, allow this script to run without a password prompt
then chmod the file to 440 and chown it with root:root
then sudo mv to /etc/sudoers.d directory
Now if MC20 crashes, within 5 minutes the script will run and discover the crash log file within /var/crash
it will kill apport and mediacenter
it will append the date and time to the crash log file name, then move it into the documents folder (so it is available if needed)
then apport will be restarted - this is the crash report app in ubuntu, and mediacenter20 will be restarted. (and some logging along the way)
so far it seems to work beautifully.
I guess the principle can be applied to other distros with relative ease.
The stumbling blocks for me were working out what the pop up crash window was - it's called "apport", so I could add "pkill apport" to the script
and adding the "export" bit into crontab took a bit of googling.
hope this helps someone.
regards, Robert