#!/usr/bin/perl # There is some kind of bug in owncloud/mirall. It repeatedly opens /dev/urandom but never closes it. # Eventually this leads to an inability to function but not a crash so the program just stops working. # This script is designed to be run from cron to check how bad the problem is and restart owncloud before it has a chance to stop working. $ENV{DISPLAY}=":0"; $PID=`pidof owncloud` or exit; # pidof returns a list if there is more than one. # lsof wants comma separated not spaces. # If there is more than one the first is usually a zombie. # Surprisingly, the zombie isn't the problem $PID =~ s/ /,/g; $CountOfStupidity=0; open (LSOF, "lsof -nPp $PID |"); while () { if ($_ =~ /^owncloud/) { if ($_ =~ /dev.urandom$/) { $CountOfStupidity++; } } } close (LSOF); # I could probably stretch this to 6000 but opening the same device node 4000 times is sufficiently stupid to justify euthanasia. # Newer versions keep proving me wrong. if ($CountOfStupidity > 990) { system ("killall owncloud"); sleep (1); system ("owncloud &"); }