[mythtv-users] finish current job and shutdown?

Dan Wilga mythtv-users2 at dwilga-linux1.amherst.edu
Wed Nov 16 14:09:43 UTC 2011

On 11/14/11 6:05 PM, Thomas Boehm wrote:
> Dirk Aust wrote:
>> I have a small script that has been configured to be called when the backend want's to shut down, it
>> simply tests among other things whether a "mythtranscode" process is running and then denies the
>> shutdown. The backend tries again after it's normal timeout, so when the transcode processis not
>> running any more, the backend goes down.
> Thanks Dirk, I know about the "Pre-shutdown-check command" and have a
> similar script running. It works fine.
> But I want to do something different. I want to shutdown after the
> currently active job finishes and resume all other pending jobs at the
> next boot.
Here's a slightly different idea: replace the normal mythtranscode with 
a wrapper that runs mythtranscode as normal, but then checks for the 
existence of a file. If that exists and there are no other 
mythtranscodes running, reboot. Something along these lines (untested):

mythtranscode-real $*
if [ -e /tmp/want-shutdown]; then
   # We can't just quit if another transcode is running, because the 
backend might start a new one,
   # so wait for all transcodes to finish. It won't matter if multiple 
copies of this script get to this stage.
   while [ `pidof mythtranscode-real` ]; do
     sleep 10
   # Clear flag
   rm /tmp/want-shutdown
   # You might need to add sudo here
   shutdown -h now

(Of course, instead of renaming the real mythtranscode to 
mythtranscode-real, you could make the above script a user job and have 
it call mythtranscode directly. Change the "pidof", too.)

All you then have to do is "touch /tmp/want-shutdown" and it will happen 
the next time all transcodes finish. You could do something like this:

if [ `pidof mythtranscode` ]; then
   touch /tmp/want-shutdown
   # Might need sudo here
   shutdown -h now

It would also be a good idea to "rm /tmp/want-shutdown" somewhere before 
starting mythbackend, just in case it's already there.

Dan Wilga                                                        "Ook."

More information about the mythtv-users mailing list