Sunday, January 18, 2009

init script for fancontrol

Developed and tested on ubuntu 8.04.1; may work on other ubuntus, debian and other debian-based systems using lsb-base (>= 3.0-6).

Recommended to create the following script as /etc/init.d/fancontrol with owner and group root, permissions rwxr-xr-x. It can be installed as root using:

update-rc.d fancontrol defaults 99 01

If you want to see boot and shutdown messages from this script, set VERBOSE=yes in /etc/default/rcS. The default setting is VERBOSE=no.

#! /bin/sh

# fancontrol startup script

# fancontrol is part of the lm-sensors package

# Developed and tested using fancontrol 0.66 on ubuntu 8.04.1; may work
# on other ubuntus, debian and other debian-based systems using
# lsb-base (>= 3.0-6)

# INIT INFO for insserv and YaST
### BEGIN INIT INFO
# Provides: fancontrol
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: fancontrol
# Description: fan control
### END INIT INFO

# Change History
# 20jan09 Charles
# * Creation on ubuntu 8.04.1 with lm-sensors 1:3.0.0-4ubuntu2,
# using skeleton 1.8 as a pro-forma with minimal functional change

# PATH is not set because no reason to change what init provides
DESC="fan controller"
NAME=fancontrol
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS=
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
# fancontrol does not background itself so start-stop-daemon's -b option used
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon -b --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon -b --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac

Sunday, December 14, 2008

Integrating Vuze (formerly Azureus) with Gnome desktop

Here are a few techniques for integrating Vuze (formerly Azureus) with the Gnome desktop. It worked for Vuze 4.0.0.2 and 4.0.0.4 on Gnome on ubuntu 8.04.1.

To populate Applications->Internet with a Vuze entry
System, Preferences, Main Menu, Internet (in left pane), New Item
Name: Vuze
Command: /opt/vuze/vuze (or wherever you put it)
Comment: (whatever you like)

To give this entry the Vuze icon
Edit ~/.local/share/applications/alacarte-made.desktop, changing the Icon= line:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Icon[en_IN]=gnome-panel-launcher
Name[en_IN]=Vuze
Exec=/opt/vuze/vuze
Name=Vuze
Icon=/opt/vuze/vuze.png


The first line is empty, that's how the file is created by Gnome; it may or may not be important.

The icon change is not effective immediately. It is effective after ubuntu restart, probably after log off and on. To test the change: Preferences->Main Menu->Internet.

To create a launcher on the desktop (with the Vuze icon)
Applications->Internet and right click on Vuze then choose "Add this launcher to desktop".

To create a MIME type association (so clicking on a .torrent file opens Vuze)
Create ~/.mailcap:

###############################################################################
#
# MIME types and programs that process those types
#
# Users can add their own rules if they wish by creating a ".mailcap"
# file in their home directory. Entries included there will take
# precedence over /etc/mailcap
#
# The man page for update-mime(8) describes the fields
#
###############################################################################

application/x-bittorrent; /opt/vuze/vuze '%s'; description="BitTorrent client"; test=test -n "$DISPLAY"

I'm only guessing that Vuze is X-aware; if not the test= section is useless but doesn't do any harm. If you want to make this MIME type association for all users, modify /etc/mailcap instead.

To configure Firefox (3.0.3) to feed .torrent files to Vuze
Edit, Preferences, Applications
Content type: Bit torrent seed file
Use other
Browse to /opt/vuze/vuze (wherever you put it)

To start Vuze when starting a desktop session
This requires System->Control Centre which is not available by default. It can be configured by System->Preferences->Main Menu->System and selecting Control Centre.

System->Control Centre->(Personal) Sessions->Startup Programs->Add
Name: Vuze
Command: /opt/vuze/vuze (wherever you put it)
Comment: Starts Vuze BitTorrent client

Thursday, February 28, 2008