Author |
Message |
thornsoft
|
Posted: Thu Jan 18, 2007 5:26 pm |
|
Joined: Fri Nov 18, 2005 9:22 am
Posts: 777
Location:
spencerport, ny (USA)
|
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
Last edited by thornsoft on Fri Jan 19, 2007 10:25 am, edited 2 times in total.
|
|
Top |
|
![](images/spacer.gif) |
slowtolearn
|
Posted: Thu Jan 18, 2007 7:09 pm |
|
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location:
Farmington, MI USA
|
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? ![Very Happy :D](./images/smilies/icon_biggrin.gif)
|
|
Top |
|
![](images/spacer.gif) |
bigbro
|
Posted: Thu Jan 18, 2007 7:36 pm |
|
Joined: Sat Dec 24, 2005 11:33 am
Posts: 400
Location:
Kitsap Peninsula, Wa., United States
|
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!
_________________ KnoppMyth R5.5
MBE: AMD64 3400+, K8N Neo4 Plat., 1Gig, Asus Extreme N6200, 320G pata, 2x320Gsata, 750Gsata, PVR-150 Retail w/Blaster
SBE: AMD XP2000, GA 7ZMMH, 1 Gig, XFX 256M 6200, 20 Gig, PVR-150 Retail w/Blaster
SBE: AMD Dur1800, 512M, PVR500
|
|
Top |
|
![](images/spacer.gif) |
thornsoft
|
Posted: Thu Jan 18, 2007 8:54 pm |
|
Joined: Fri Nov 18, 2005 9:22 am
Posts: 777
Location:
spencerport, ny (USA)
|
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.
|
|
Top |
|
![](images/spacer.gif) |
bigbro
|
Posted: Thu Jan 18, 2007 11:42 pm |
|
Joined: Sat Dec 24, 2005 11:33 am
Posts: 400
Location:
Kitsap Peninsula, Wa., United States
|
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....
Andy
_________________ KnoppMyth R5.5
MBE: AMD64 3400+, K8N Neo4 Plat., 1Gig, Asus Extreme N6200, 320G pata, 2x320Gsata, 750Gsata, PVR-150 Retail w/Blaster
SBE: AMD XP2000, GA 7ZMMH, 1 Gig, XFX 256M 6200, 20 Gig, PVR-150 Retail w/Blaster
SBE: AMD Dur1800, 512M, PVR500
|
|
Top |
|
![](images/spacer.gif) |
thornsoft
|
Posted: Fri Jan 19, 2007 6:43 am |
|
Joined: Fri Nov 18, 2005 9:22 am
Posts: 777
Location:
spencerport, ny (USA)
|
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?
|
|
Top |
|
![](images/spacer.gif) |
randomhtpcguy
|
Posted: Fri Jan 19, 2007 8:31 am |
|
Joined: Mon Nov 07, 2005 10:09 am
Posts: 153
|
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
|
|
Top |
|
![](images/spacer.gif) |
bigbro
|
Posted: Fri Jan 19, 2007 8:39 am |
|
Joined: Sat Dec 24, 2005 11:33 am
Posts: 400
Location:
Kitsap Peninsula, Wa., United States
|
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!
|
|
Top |
|
![](images/spacer.gif) |
thornsoft
|
Posted: Fri Jan 19, 2007 9:00 am |
|
Joined: Fri Nov 18, 2005 9:22 am
Posts: 777
Location:
spencerport, ny (USA)
|
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.
|
|
Top |
|
![](images/spacer.gif) |
connollyr12
|
Posted: Fri Jan 19, 2007 9:50 am |
|
Joined: Tue Jun 21, 2005 6:09 pm
Posts: 57
|
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.
|
|
Top |
|
![](images/spacer.gif) |
randomhtpcguy
|
Posted: Fri Jan 19, 2007 9:55 am |
|
Joined: Mon Nov 07, 2005 10:09 am
Posts: 153
|
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
|
|
Top |
|
![](images/spacer.gif) |
connollyr12
|
Posted: Fri Jan 19, 2007 9:57 am |
|
Joined: Tue Jun 21, 2005 6:09 pm
Posts: 57
|
Thanks for the quick reply ![Laughing :lol:](./images/smilies/icon_lol.gif)
|
|
Top |
|
![](images/spacer.gif) |
thornsoft
|
Posted: Fri Jan 19, 2007 10:21 am |
|
Joined: Fri Nov 18, 2005 9:22 am
Posts: 777
Location:
spencerport, ny (USA)
|
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
|
|
Top |
|
![](images/spacer.gif) |
randomhtpcguy
|
Posted: Tue Jan 23, 2007 6:50 pm |
|
Joined: Mon Nov 07, 2005 10:09 am
Posts: 153
|
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.
|
|
Top |
|
![](images/spacer.gif) |
neutron68
|
Posted: Sun Jan 28, 2007 11:06 am |
|
Joined: Tue Mar 28, 2006 8:26 pm
Posts: 804
Location:
Minneapolis, MN
|
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?
_________________ KnoppMyth R5.5, Asus A8N-VM CSM (nvidia 6150 onboard video), AMD Athlon 64 dual-core 4200+, two 1GB sticks DDR 400, HD-3000 HDTV card, PVR-150 card, Iguanaworks RS-232 IR receiver/transmitter, Pioneer DVR-110 DVD burner
|
|
Top |
|
![](images/spacer.gif) |