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

My mythcommflag babysitting script - babysit_commflag.sh
http://forum.linhes.org/viewtopic.php?f=3&t=13614
Page 1 of 2

Author:  thornsoft [ Thu Jan 18, 2007 5:34 pm ]
Post subject:  My mythcommflag babysitting script - babysit_commflag.sh

Link: http://www.thornsoft.com/Misc/babysit_commflag.sh
Description: Utility to watch over mythcommflag and prevent it from hogging the CPU. This improves playback while commflag is running, so you don't have to restrict commflag to the wee hours of the morning.

Problem Solved: mythcommflag defaults to "nice" value 17. But that's not good enough. It needs to be 19 (lowest priority).

If you can't use commflagging without having to manually renice the priority to 19, this is for you.

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


Test run: babysit_commflag.sh
It should exit with no messages, if mythcommflag isn't found, or IS found, but already is at 19. Otherwise, it'll renice to 19 and output a message saying that it did so.

Suggested usage - add this line to crontab:
Code:
* * * * * /usr/local/bin/babysit_commflag.sh >>/var/log/mythtv/babysit_commflag.log 2>&1


This runs the job every minute. You may have brief episodes of choppy playback when one job ends and another starts, but the babysitter will catch it within a minute, and calm it down.

Please leave feedback, suggestions, fixes here.

Author:  randomhtpcguy [ Tue Jan 23, 2007 7:32 pm ]
Post subject: 

commflag was always messing up my recordings so i enabled it to only occur in the middle of the night when no one would be watching. That fixed the problem, but with the obvious disadvantage of having to watch shows a day late to auto skip commercials.

I suspect i can let commflag run at anytime now.

My only remaining concern is if the bandwidth between master and slave backends becomes a bottleneck, rather than cpu cylces, will this help?

Possible solution to intranet bandwidth issues is using a quality of service setup with dd-wrt (prioritizing packets with specific datatype) I could maybe prioritize packets leaving the master "/myth/tv" store (to the remote frontends), over packets entering the master "/myth/tv" store (from the remote backends). So that frontends get the data they need on time with out hiccups. (i don't have gigE)

Other possibility would be a bandwidth_babysit script that ramps down something if bandwidth is an issue. It might be good discussion for a new thread. However, I will drop the idea for now until i verify that bandwidth and not disk i/o or cpu is really the issue while watching multiple streams of hd. (at 10/100 speeds)

Anyway, thanks for your scripts. Seems like a very useful and clever way to improve everyday use of knoppmyth.

Author:  cesman [ Tue Jan 23, 2007 10:55 pm ]
Post subject: 

Nice. Added to next release.

Author:  Too Many Secrets [ Thu Feb 01, 2007 8:56 am ]
Post subject: 

This works great!

Author:  thornsoft [ Thu Feb 01, 2007 9:26 am ]
Post subject: 

cesman wrote:
Nice. Added to next release.

I'm Honored! Thanks.

Author:  turpie [ Fri Feb 02, 2007 12:12 am ]
Post subject:  Re: My mythcommflag babysitting script - babysit_commflag.sh

thornsoft wrote:
Suggested usage - add this line to crontab:
Code:
* * * * * /usr/local/bin/babysit_commflag.sh >>/var/log/mythtv/babysit_commflag.log 2>&1



NOTE: If you're putting it into the system crontab you need to include the user name in field six.
Code:
 * * * * * root /usr/local/bin/babysit_commflag.sh >>/var/log/mythtv/babysit_commflag.log 2>&1

[/quote]

Author:  datobin1 [ Sat Feb 03, 2007 3:05 pm ]
Post subject: 

Just wanted to let you know, I added this to my backend over a week ago and seems to be working fine.

Thanks for the script

Author:  the_manowar [ Sat Feb 03, 2007 5:35 pm ]
Post subject: 

Great work.

For safety's sake you should ensure that you rotate the logfile as well.

Add the following to /etc/logrotate.d/babysit_commflag (assuming you use the log file/path in the crontab entry):

Code:
/var/log/mythtv/babysit_commflag.log {
        daily
        rotate 7
        notifempty
        copytruncate
        compress
}

Author:  ffrr [ Sun Mar 04, 2007 5:45 am ]
Post subject:  Re: My mythcommflag babysitting script - babysit_commflag.sh

thornsoft wrote:
Link: [url]

Problem Solved: mythcommflag defaults to "nice" value 17. But that's not good enough. It needs to be 19 (lowest priority).

If you can't use commflagging without having to manually renice the priority to 19, this is for you.


Thanks for the solution. I just wanted to mention that it can be worse than "nice" 17 when it starts. I started a comm flag job manually from the recorded pprograms menu and found this in the log later
Code:
Sun Mar  4 20:38:02 EST 2007 : commflag pid [6461] at ni [0], renicing to 19.

[/code]

Author:  mihanson [ Sun Mar 04, 2007 10:21 am ]
Post subject: 

This script worked very well for me, too except... I have a non-standard installation and my root partition is not really big (3 GB), but I've never had a problem with it filling up until a few days ago. It seems that an entry is written to my syslog everytime this script runs because it is envoked by cron. I had the script running every minute from mythtv's crontab. I deleted my old, large log files as well as stopped the script from running in cron. That cleared up my partiton. I was looking at webmin trying to figure out if there was a way to exclude just this script from logging in my syslog, but nothing jumped out at me. Anyone have any ideas?

Author:  thornsoft [ Sun Mar 04, 2007 10:39 am ]
Post subject: 

mihanson wrote:
trying to figure out if there was a way to exclude just this script from logging in my syslog, but nothing jumped out at me. Anyone have any ideas?

Dang! I never knew that crap showed up there. Mine seems to be rotating off though. Still, my syslogs are fill of it.

Author:  mihanson [ Thu Mar 08, 2007 11:03 am ]
Post subject: 

To help with my issue of log size, I adjusted my crontab to run every 3 minutes instead of every minute. I also found and deleted a bunch of mysql .bin files that I did not need. My root partition is at about 75% full now and things seem much better.

Author:  cfoxga [ Fri Mar 16, 2007 10:02 pm ]
Post subject: 

I noticed that the script only worked for a single commflag process. I wanted to allow for multiple commflaging processes to run simultaneously, so I modified the script...

Code:
#!/bin/bash
# babysit_commflag.sh   v0.14 by Chris Thornton - chris@thornsoft.com
# Utility to renice commflag if it is running at higher than "nice" level 19.
# Home: http://www.thornsoft.com/Misc/babysit_commflag.sh
# Copyright 2007 Chris Thornton
# Free for any use.
# Installation:
#  cp babysit_commflag.sh /usr/local/bin
#  chmod +x /usr/local/bin/babysit_commflag.sh
# Usage: Add to crontab (crontab -e):
# * * * * * /usr/local/bin/babysit_commflag.sh >>/var/log/mythtv/babysit_commflag.log 2>&1

NOWDATE=$(date)
PROCCOMMFLAG=`ps -eo pid,ni,comm |grep "mythcommflag" | grep -v "<defunct>" \
    |grep -v grep | awk ' { print $1 } '`
#if commflag IS running, and NIce value <19...
for ARG in $PROCCOMMFLAG
do
    NICOMMFLAG=`ps -eo pid,ni,comm | grep "mythcommflag" | grep $ARG | \
        grep -v "<defunct>" | grep -v grep | awk ' { print $2 } '`
    if [ "${NICOMMFLAG}"  -ne "19" ]
    then
        renice 19 -p "${ARG}"
        echo "$NOWDATE : commflag pid [$ARG] at ni [$NICOMMFLAG], renicing to 19."
    fi
done

Author:  crushinator [ Sun May 20, 2007 5:01 pm ]
Post subject: 

cesman wrote:
Nice. Added to next release.


This babysitting script is great, thank you. I think it might have been overlooked in R5F1. I wonder if it can be added in next time, especially any and all changes regarding crontab, logrotate, multiple commflag jobs.

Author:  silentaccord [ Fri Jun 29, 2007 4:32 am ]
Post subject: 

I just stumbled across this thread and I was curious since I have been doing something similar. In my opinion, the script is overkill because the same thing can be accomplished without using a script at all. Just add this line to /etc/crontab:
Code:
* * * * * root renice 19 $(pidof mythcommflag)

Except for the logfile (which I don't even want), I think this does exactly what the script does and it works with multiple processes.

For those that don't want syslog filling up with this stuff, I believe the only option is to redirect all cron logging to /dev/null. To do this, edit /etc/syslog.conf. Add "cron," after the semicolon on the *.* line to exclude it from this catch-all rule. Then uncomment the cron.* line and change the logfile to /dev/null. The 2 lines should look like this when you're done:
Code:
*.*;cron,auth,authpriv.none     -/var/log/syslog
cron.*                          /dev/null

After saving the changes, restart syslogd:
Code:
/etc/init.d/sysklogd restart

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