Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

12 August 2010

Stop hard disk heavy processes from slowing down the entire machine on Ubuntu

So this is the deal:
We have a machine with many users and some of them are occasionally running hdd-intensive applications. This is an expected activity of the users, BUT it practically prevents other users from doing anything with the machine until the processes with the intensive hdd activities terminate.

This is why I added a "daemon" that runs in the background and checks for any hdd-intensive processes.
If any processes of this type are found, using "ionice", their I/O priority is reduced to "C 3" (idle):
from "man ionice"
"""
Idle. A program running with idle io priority will only get disk time when no other program has asked for disk io for a defined grace period. The impact of idle io processes on normal system activity should be zero. This scheduling class does not take a priority argument.
"""

The tools used here should be already there in Ubuntu. If they are not (or you just want to make sure that they are installed) you can run:
sudo apt-get install iotop util-linux grep mawk findutils

An entire "daemon" consists of adding the following line to "/etc/rc.local", just before "exit 0"

iotop -b -o -d 15 | grep "%" | grep "M/s" | awk '{print $1}' | xargs ionice -c 3 -p
Or you could run almost the same line as an ordinary user and "sudo":
iotop -b -o -d 15 | grep "%" | grep "M/s" | awk '{print $1}' | xargs sudo ionice -c 3 -p
The machine (and its users) are much happier now. :)

Hope this helps somebody else as well.

13 June 2010

Hamachi VPN Watchdog (KeepAlive) for Linux (Ubuntu 9.10 and likely 9.04, 10.04, etc.)

UPDATE: there is a new version at http://computarz.blogspot.com/2010/06/updated-hamachi-keep-alive-script.html

I just finished writing a script for keep LogMeIn Hamachi online.

You can get a script for installing and configuring hamachi at: http://www.webupd8.org/2010/05/script-to-install-hamachi-with-gui-in.html
#!/bin/bash

if [ `ip r | grep default -c` -lt 1 ]; then
  # No internet gateway, exiting!
  exit 1
fi

hamachi_online=`hamachi list | egrep '\* [0-9]' | awk '{print $2}'`

me_online=0
for IP in $hamachi_online; do
  ping -c 1 $IP >/dev/null
  if [ $? -eq 0 ]; then me_online=1; break; fi
done

if [ $me_online -eq 0 ]; then
  echo "hamachi is offline - restarting"
  if [ `pgrep -c tuncfg` -eq 0 ]; then sudo /sbin/tuncfg; fi
  hamachi stop >/dev/null
  sleep 1
  for ham_pid in `pgrep -f hamachi -l | grep -v hamachi_watchdog.sh | awk '{print $1}'`; do
      kill -9 ham_pid
  done
  hamachi start
  CNT=1;
  echo -n "Logging in... " ;
  while [ `hamachi login | grep -c failed` -eq 1 -a $CNT -lt 100 ]; do 
      echo -n "$CNT "; 
      let CNT=$CNT+1; 
      sleep 2; 
  done;
  echo
  hamachi get-nicks
#else
  #echo "hamachi is online"
fi
I configured cron to run this script every 5 minutes, by running in terminal:
crontab -e

and then adding this line:
# m h  dom mon dow   command
*/5 * * * * $HOME/bin/hamachi_watchdog.sh