I have a Windows-only daemon running on a linux box with wine and Xvfb. Due to this quite experimental setup, the daemon crashes periodically and i'd like to implement some kind of mechanism to automatically restart the daemon. Currently i have a systemd unit definition with the Restart=always
setting.
However, i have noticed that sometimes the daemon crashes, but doesn't exit it's process. This is the equivalent of displaying a dialog box with the question "The daemon is crashed, do you want to send an error report?". So, the process is still running, but the daemon has stopped working.
The only outside behaviour of this phenomenon which i can examine on my linux box are two new files, which appear at a certain location but with variable filenames (they're time dependent, and have a timestamp in their name). I think they are some kind of memory dump or stack traces which should originally be used for the error report sending.
So now i am looking for a solution for systemd to capture this solution, like
- On unit start, look at the crash dump target directory and make a snapshot of the directory contents
- Start the daemon
- Periodically look at the directory and if there are new files, which aren't in the snapshot, based on some regular expression, restart the daemon and refresh the snapshot.
I thought about a wrapper, written in bash or something, but there are two problems: First i would not know how to implement this behaviour, and second, this would make the use of systemd completely obsolete, since the script handles all the crash handling, and systemd would only execute the script.
I also thought about just periodically restarting the the daemon with systemd's given features, but this would be quite inefficient (given the fact that a windows daemon in a wine wrapper isn't inefficient in the first place), since it would restart the daemon sometimes when it's not necessary, or it would take some time after the daemon crash until the periodic restart kicks in.
What would be the best solution to solve this problem?
And just for the records: The daemon i am talking about is the Uploader for Google Photos. Google doesn't for some reason release it for Linux.