Tuesday, September 17, 2013

Bash as occult text: starting a Unix daemon

So you've written your own Unix daemon, and now you need a start script to stick in /etc/init.d

As a socially responsible coder, you know your daemon needs to run under tightly policed user, like www or therebemonstershere.  So your init script will look something like this:

  su - therebemonstershere -c " { /usr/local/bin/mydaemon & } "

You'd also like to keep track of its pid, so you can kill your daemon later via /etc/init.d/mydaemon stop

  su - therebemonstershere -c " { /usr/local/bin/mydaemon & } ; echo \$! > /var/run/mydaemon.pid"

But this isn't enough: what about stdout and stderr?

  su - therebemonstershere -c " { /usr/local/bin/mydaemon > /var/log/mydaemon.log 2>&1 & } ; echo \$! > /var/run/mydaemon.pid"

Looking good!  But there's one more catch: when your terminal dies, your daemon will get a HUP signal and die too.   Probably in a week or so when you finally kill that xterm and forgot any of this happened.

  su - therebemonstershere -c " { nohup /usr/local/bin/mydaemon > /var/log/mydaemon.log 2>&1 & } ; echo \$! > /var/run/mydaemon.pid" 

Wednesday, February 13, 2013

Protip: disabling accidental text resizing in Firefox

Ubuntu, at least in its Pangolin incarnation, has this clever skeuomorphic touchpad behaviour: when you scroll with a glancing gesture, the scrolling continues for a bit after your fingers have left the touchpad, like flicking a playing card across a table.  It feels natural.

However, it often results in my Firefox fonts becoming randomly resized, as I frequently begin scrolling to the top of a page, then change my mind and highlight the URL bar via ctrl+L, and in that instant when the skeuomorphic scroll is happening and the ctrl key depressed, Firefox zooms.

The easy fix it to disable Firefox' ctrl+mousewheel zoom behaviour.