Friday, December 31, 2010

volume keys in lxde

gmixer is just not working for me correctly under the Fedora LXDE spins on my Asus EEE laptop. So I hacked together a solution using some suggestions I found across the 'net.

add to the "keyboard" section in ~/.config/openbox/lxde-rc.xml

<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<command>/home/user/bin/vol.sh down</command>
</action>
</keybind>
<keybind key="XF86AudioRaiseVolume">
<action name="Execute">
<command>/home/user/bin/vol.sh up</command>
</action>
</keybind>
<keybind key="XF86AudioMute">
<action name="Execute">
<command>/home/user/bin/vol.sh mute</command>
</action>
</keybind>


/home/user/bin/vol.sh

#!/bin/bash

function dispvolpercentage() {
zenity --progress --text="Volume" --percentage="$1" --no-cancel --timeout=1
}

function getvolume() {
amixer get Master | grep -o -E "[0-9]+%" | head -1 | cut -d '%' -f 1
}

case "$1" in
up)
VAL="`getvolume`"
VAL=$(($VAL+5))
amixer set Master ${VAL}%
dispvolpercentage $VAL
;;
down)
VAL="`getvolume`"
VAL=$(($VAL-5))
amixer set Master ${VAL}%
dispvolpercentage $VAL
;;
mute)
amixer set Master toggle
;;
esac


References
* http://wiki.lxde.org/en/LXDE:Questions#How_do_I_make_my_keyboard_volume_buttons_work.3F
* https://bbs.archlinux.org/viewtopic.php?id=69589&p=1 - I wrote my script based on this one but just using zenity (doesn't look very nice, but works)

Saturday, December 4, 2010

openwrt crashes due to OOM killer

I have an openvpn tunnel running between two OpenWRT-powered routers. One of them is running Kamikaze 7.09 and crashes all the time when transferring lots of data at once. It was getting really annoying (for me and them) having to call the site and have it manually rebooted. I finally discovered that it appears to be dying because it runs out of memory and the OOM killer terminates all the important processes. It'd be nice if the OOM killer would just reboot the thing, but the kernel in Kamikaze 7.09 for this router doesn't support that (I think newer ones do). So I wrote the following watchdog script and installed it in root's crontab to run every 4 minutes. So far, the router hasn't crashed permanently. When memory gets low, it just reboots! Hopefully no more calls to this site...


#!/bin/sh

F="`free | grep Mem | cut -c 37-45`"
if [[ $F -lt 500 ]]; then
logger "Memory Low ($F) - rebooting..."
sleep 5
/sbin/reboot
fi

Thursday, December 2, 2010

I'm a victim of this NetworkManager bug where if it can't reach the dhcp server after some longer amount of time, it gives up. I have a server that is difficult for me to reboot that has gone down because NetworkManager just gives up if something happens to the DHCP server. So, I wrote this watchdog script and put it in my crontab to run every 5 minutes.


#!/bin/bash

if pidof dhclient > /dev/null; then
logger "dhclient is alive"
else
logger "dhclient is dead, restart NetworkManager"
/etc/init.d/NetworkManager restart
fi