LinHES Forums
http://forums.linhes.org/

My mythbackend babysitting script - babysit_backend.sh
http://forums.linhes.org/viewtopic.php?f=3&t=13613
Page 1 of 4

Author:  thornsoft [ Thu Jan 18, 2007 5:26 pm ]
Post subject:  My mythbackend babysitting script - babysit_backend.sh

Link: http://www.thornsoft.com/Misc/babysit_backend.sh
Since upgrading to R5E50, which I love, I've had problems with the backend not being up when it's supposed to be. I understand that this issue is being worked on. In the meantime, I wrote a script that can be run from crontab to re-start the backend if it's down.
If it sees the backend running with a non-defunct process ID, it just exits.
If it doesn't see the backend, and none of the following conditions apply, it'll re-start it.
Exceptions:
mythfrontend is down (you're probably doing some other maintenance)
mythbackup is running
mythrestore is running

You can easily extend it to add exceptions too.


Installation:
From a directory such as /tmp, as root:
Code:
wget http://www.thornsoft.com/Misc/babysit_backend.sh
cp babysit_backend.sh /usr/local/bin
chmod +x /usr/local/bin/babysit_backend.sh


run: babysit_backend.sh
It should exit with no messages, if the backend is running. Otherwise it'll restart it.
Suggested usage - add this line to crontab:
Code:
* * * * * /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1


Note: See the note by "bigbro", if your contab lists a user. Mine doesn't, and I don't know how common this is.

This runs the job every minute. It'll handle re-starts after reboot (just wait a minute, and it'll come up) and also those pesky random crashes that always seem to happen right before the wife's show is supposed to record.

Please leave feedback, suggestions, fixes here.

Also see my "mythcommflag babysitting script", which ensures low cpu usage by commflag:
http://mysettopbox.tv/phpBB2/viewtopic.php?t=13614

Author:  slowtolearn [ Thu Jan 18, 2007 7:09 pm ]
Post subject:  Re: My mythbackend babysitting script - babysit_backend.sh

Hi thornsoft,
You'll want to remove the Home: portion from the wget line.

thornsoft wrote:
...and also those pesky random crashes that always seem to happen right before the wife's show is supposed to record.

Ain't that always the way? :D

Author:  bigbro [ Thu Jan 18, 2007 7:36 pm ]
Post subject: 

I tested this all files seemed in right places and it works in R5C7.
Should really help the WAF when I don't miss a particular show like has happened the last two Wednesday's in a row.
Still trying to determine why the MBE suddenly disappeared.

Anyway, I noticed when it runs and exits with no error I get no indication in the babysit-backend.log I assume that is normal.

Can you post a sample of what I might see if it had to restart the backend?

Thanks!

Author:  thornsoft [ Thu Jan 18, 2007 8:54 pm ]
Post subject: 

bigbro wrote:
Anyway, I noticed when it runs and exits with no error I get no indication in the babysit-backend.log I assume that is normal.

Yeah, I had logging in there, and it was just in the way so I yanked it.

Quote:
Can you post a sample of what I might see if it had to restart the backend?


Something like this:
Code:
Myth Backend Babysitter Run At Thu Jan 18 14:10:01 EST 2007
babysit_mythbackend Needs to re-start Myth Backend at Thu Jan 18 14:10:01 EST 2007.
Restarting MythTV server: mythbackendNo /usr/bin/mythbackend found running; none killed.
.
.
Sleeping....
Myth Backend restarted as process 3180.


You can test it easily. Just press Alt+2 to kill the backend, and wait a minute. You'll get output.

slowtolearn - thanks for the heads up on the typo. I fixed it.

Author:  bigbro [ Thu Jan 18, 2007 11:42 pm ]
Post subject: 

Thanks for the input and what it should look like.

As soon as I got a break in the "Schedule" I stopped my backend.
It didn't work. I went in and Checked my cron.log
Here is what I saw>
Quote:
Jan 18 17:30:01 mythtv /usr/sbin/cron[4546]: (*system*) RELOAD (/etc/crontab)
Jan 18 17:30:01 mythtv cron[4546]: Error: bad username; while reading /etc/crontab


So I made a change that I would suggest to your Crontab line.

Changed this:
Code:
* * * * * /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1


To this:
Code:
* * * * *  root /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1


Now I see it running in my Cron.log and it does not present that error at first run.
Quote:
Jan 18 21:34:01 mythtv /usr/sbin/cron[4546]: (*system*) RELOAD (/etc/crontab)
Jan 18 21:34:01 mythtv /USR/SBIN/CRON[12958]: (root) CMD (/usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1)
Jan 18 21:35:01 mythtv /USR/SBIN/CRON[13042]: (root) CMD (/usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1)


Thanks for the Great script should raise the WAF for sure.... :D

Andy

Author:  thornsoft [ Fri Jan 19, 2007 6:43 am ]
Post subject: 

Interesting... What user were you when you inserted into crontab? I was root when I did mine. Maybe the "root" directive in the crontab entry is only needed if you add as another user such as mythtv?

Author:  randomhtpcguy [ Fri Jan 19, 2007 8:31 am ]
Post subject: 

thanks for the idea and script.

I installed it on my slave backend whose backend recorder seems to go offline periodically.

I thought running it every minute might be overkill if there is any significant resources used to run it. Any thoughts? My machine barely eeks out hd now.

Previously, i had been thinking about looking for a script that would run from the master backend to periodically check that all slave backends are online and if not start them. i hadn't really looked into it yet though. I guess this works better. Thanks

Author:  bigbro [ Fri Jan 19, 2007 8:39 am ]
Post subject: 

Thornsoft wrote:
Quote:
What user were you when you inserted into crontab?


I was root when I installed this. I did notice when I went in to fix it, my Crontab lists the user name as one of the parameters that is what I guessed I needed to fix to make this work for me.

Anyway it works and that is a good thing....

Thanks!

Author:  thornsoft [ Fri Jan 19, 2007 9:00 am ]
Post subject: 

randomhtpcguy wrote:
I thought running it every minute might be overkill if there is any significant resources used to run it. Any thoughts? My machine barely eeks out hd now.

It takes hardly any time to run, and doesn't launch anything bigger than "ps" unless the process is down. I don't think it would even have an impact if it ran every second.

Author:  connollyr12 [ Fri Jan 19, 2007 9:50 am ]
Post subject:  Crontab

Could anyone point me in the direction of how to add this script to Crontab I have run it and it definetly fixed the problem I had with my backend going down.

Author:  randomhtpcguy [ Fri Jan 19, 2007 9:55 am ]
Post subject: 

follow the instructions at the top.

to add lines to crontab

login as root and type:

Code:
crontab -e


add the line from above

then exit and yes to save

that's it

Author:  connollyr12 [ Fri Jan 19, 2007 9:57 am ]
Post subject:  Crontab

Thanks for the quick reply :lol:

Author:  thornsoft [ Fri Jan 19, 2007 10:21 am ]
Post subject: 

Here's my favorite crontab tip:
Use a crontab.txt file, it's just safer. Here's how.
As root:

Go to the root home directory:
Code:
cd /root

Dump the existing crontab into crontab.txt
Code:
crontab -l > crontab.txt

Edit the file, I use vi.
Code:
vi crontab.txt

Now load the crontab.txt back into crontab.
Code:
crontab crontab.txt


Now verify the changes by listing the crontab:
Code:
crontab -l


Benefits: You have a backup if something goes wrong, and you can use any editor. To me, it just feels safer. And you can include it in the backup list, so it gets backed up. See TJC's backup notes.

--
Chris

Author:  randomhtpcguy [ Tue Jan 23, 2007 6:50 pm ]
Post subject: 

For some reason, this doesn't work for me on my slave backend.

I think it is because the myth-backend needs to be restarted while the database and mythtv-backend on the master is running.

If i reboot the master including the master myth-backend, i have to restart the slave myth-backend for the frontends to recognize the recorders on the slave backend as available for recording.

After a master reboot, the slave myth-backend stays online but the frontends for some reason think the slave backend capture card is unavailable.

pretty confusing.

Author:  neutron68 [ Sun Jan 28, 2007 11:06 am ]
Post subject:  crontab sanity check

I just looked in the /etc/crontab file and it looks different than I used to see in releases R5C7 and R5D1 - the /usr/local/bin/mythrename.pl script isn't being called anymore, for example.

By the way, the suggested crontab commands don't work in R5E50.
Code:
# cd /root
# crontab -l
and nothing was listed.
Code:
# cd /root
# crontab -e
and a text editor with an empty window appeared.
So, it would appear that these old crontab commands don't work in R5E50.

So, my belief is that /etc/crontab is the correct place to insert the line?
Code:
* * * * * /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1

If so, my current /etc/crontab file looks like this:
Code:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* * * * *  /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1
#

Look correct?

Page 1 of 4 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/