Monday, April 15, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 529  / 3 Years ago, wed, july 28, 2021, 2:11:58

I use Gnome Do as a launcher for most things. I have it set to run on login and for most of the time it sits in the background waiting for me to mash a keyboard shortcut. About once a week, it falls over. I mash my shortcut and nothing happens. I have to re-launch it.



It's not amazingly annoying but I would like to know if there are any good ways to make sure desktop applications keep running forever. If they die, they get re-launched (perhaps with a crash timeout so if it crashes on load, it doesn't keep trying to run it over and over and over again).



I know some applications do this. On Gnome2, if gnome-panel isn't running, the system forces it to load. Is there a simple way of tapping into this logic (of course, without breaking Gnome).



I don't want this question to be too specific to Gnome Do or even Gnome because I have more than one application for a solution (I run Boxee on an OpenBox desktop on our media centre) and I'm sure other people all have their own issues they'd like to fix through something like this.


More From » gui

 Answers
7

Another not so elegant solution:



#!/bin/bash

threshold=2
program="$1"

while true; do
start=$(date +%s)
"$program"
ret_val=$?
stop=$(date +%s)
if [[ ret_val -eq 0 ]]; then
# normal exit, quit
exit 0
else
# abnormal exit, check runtime. if < threshold quit
runtime=$((stop - start))
if [[ runtime -lt $threshold ]]; then
echo "crash on start"
exit 1
fi
fi
done


This will restart, if the program (first argument) exits with a return code != 0 and ran at least threshold seconds.



I tried to create an Upstart job using the respawn and respawn limit options, but that somehow failed.


[#44787] Wednesday, July 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
otatorm

Total Points: 218
Total Questions: 113
Total Answers: 124

Location: British Indian Ocean Territory
Member since Tue, Feb 22, 2022
2 Years ago
otatorm questions
;