Wednesday, May 13, 2009

F@H as a daemon

I wanted Folding@Home to start up automatically every time the computer is rebooted. Using /etc/rc.local did not work: F@H would start and then get killed when rc.local finished. Fortunately fahwiki.net has an entry on how to start F@H from the init scripts. Based on that I created this script, /etc/init.d/folding1:
#!/bin/sh
#
# $Id: folding.init.d,v 1.2 2008/02/27 13:20:31 est Exp $
### BEGIN INIT INFO
# Provides: folding1
# Required-Start: $local_fs,$network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0
# Short-Description: Start folding@home client
### END INIT INFO

#Adapted from dhcp3-server init file

PATH=/sbin:/bin:/usr/sbin:/usr/bin

test -f $DAEMON || exit 0

. /lib/lsb/init-functions

#Configure these variables to suit your needs

MYUSER='myname' #Run as this user (Change this!)
WORKING='/home/myname/folding1/' #Process Working Directory (This is where the FAH client is stored)
NAME='fah6' #Process Name (This is the Folding @ Home executable name)
FOLDING_OPTS='-forceasm -smp 4'

#No need to edit below this line

DESC='Folding @ Home Client' #Process Description (Brief line to describe FAH)
DAEMON="$WORKING$NAME" #Full Path to the Daemon
MYPID="/var/run/$NAME.1.pid" #PID file

# single arg is -v for messages, -q for none
check_status()
{
if [ ! -r "$MYPID" ]; then
test "$1" != -v || echo "$NAME is not running."
return 3
fi
if read pid < "$MYPID" && ps -p "$pid" > /dev/null 2>&1; then
test "$1" != -v || echo "$NAME is running."
return 0
else
test "$1" != -v || echo "$NAME is not running but $MYPID exists."
return 1
fi
}

case "$1" in
start)

log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon -b -m --start --chdir "$WORKING" --chuid "$MYUSER" --quiet --pidfile $MYPID \
--exec "$DAEMON" -- $FOLDING_OPTS; then
log_end_msg 0
else
log_end_msg 1
exit 1
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --pidfile $MYPID
log_end_msg $?
rm -f "$MYPID"
;;
restart | force-reload)
test_config
$0 stop
sleep 2
$0 start
if [ "$?" != "0" ]; then
exit 1
fi
;;
status)
echo -n "Status of $DESC: "
check_status -v
exit "$?"
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
esac

exit 0
Then run "update-rc.d folding1 defaults".

The script is named "folding1" because I actually run multiple folding clients on the same box. It still showed ~15% idle when running the first client with -smp 4 despite having only three cores, so why not? So I created similar scripts, folding2 and folding3, then made the necessary changes to indicate the different directories, and to delete the smp option.

Wednesday, February 11, 2009

Hooray, /etc/resolv.conf fixed!

A few things have been bothering me about my Linux install recently, so I spent about an hour fixing them this morning.

First, when I mistype a domain name or tried to visit a work web site while disconnected from the intranet, up popped the infamous Rogers search page. I'd put up with it long enough, and finally did what I should have done long ago: modify my router with static DNS, using these addresses
  • 4.2.2.1
  • 4.2.2.2
  • 4.2.2.3
Now I just get a good old fashioned "address not found" page load error. To whoever pays for the upkeep and maintenance of this service, Thank you, Thank you, Thank you.

Second, now that I've upgraded to Ubuntu Intrepid, vpnc did not seem to work as well as it did with Hardy. I think the dots are connected like this:
  • My router is configured to use DHCP to get an IP address from Rogers.
  • DHCP tells my router to use domain phub.net.cable.rogers.com
  • Network Manager uses /sbin/dhclient-script to add "domain phub.net.cable.rogers.com" and "search phub.net.cable.rogers.com" to /etc/resolv.conf when it gets an IP address from my router.
  • When I connect to work with vpnc, the domain line is replaced, but the search line is not
  • Consequently, "ping foo" fails, while "ping foo.work.com" works
After a bit of searching, the thing to do is this: apt-get install resolvconf. That installs a package that, if your VPN gateway sends some DNS server data, will fix up /etc/resolv.conf. So now when I'm connected to work, rogers is no longer searched.

Monday, January 12, 2009

xrandr 1.2

Added this to xorg.conf:
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"

SubSection "Display"
Depth 24
Modes "1600x1200" "1400x1050" "1280x1024" "1024x768"
Virtual 3000 1200
EndSubSection
EndSection

Restarted X

Ran this as joe-user:
xrandr --output LVDS --auto --output VGA-0 --auto --mode 1280x1024 --right-of LVDS
and voila, dual display.

Friday, September 26, 2008

Firefox and Java plugin

What is it with Firefox and Java, why can't the plugin be installed without having to use the terminal? I'm running Kubuntu 8.04 (Hardy Heron), and I still need to set up a symlink to the plugin:

/usr/lib/firefox-3.0.3/plugins/libjavaplugin_oji.so -> /someplace/libjavaplugin_oji.so

This morning I tried to add the Java plugin on my daughter's (admittedly out-of-date) Ubuntu setup, and although the Firefox Plugin installer said it went well, it didn't actually do anything. For someone who's trying to just keep his / her children busy while they should really be working, this is not helpful.

Wishlist: one-click install of the Java plugin on any Linux browser.