透明思考


Transparent Thoughts


svlogd- runit's service logging daemon

After installrunit, you’ll get /usr/bin/svlogd in yoursystem, which is runit’s service logging daemon. Although there’s amanual, it took me a while to figure ourhow to use it …

(BTW, runit package in Ubuntu Feisty official repository isbroken…)

svlogd accepts input from itsSTDINand write it to log files. For example you can do following:

ls / | svlogd -v ./log

There will be a “log/current” file, which includes the output of “ls /”.

Tolog a runit’s service,you need create a “log” subdirectory within the service directory,thenrun svlogd in the subdirectory. Given I have a “mongrel_3002”service, I’ll create following stuff:

/var/service/mongrel_3002/log/var/service/mongrel_3002/log/run

Put following script in “log/run”, and make it executable:

#!/bin/shexec svlogd -tt /path/to/log # /path/to/log must be writable

Mongrel(in non-daemon mode, i.e. without “-d” option) makes it morecomplicated: it outputs log to log file of itself (such as”#{RAILS_ROOT}/log/production.log”), or outputs log toSTDERRif thelog file is not writable. In order to collect Mongrel’s log withsvlogd, I first make “production.log” not writable, then redirectSTDERRtoSTDOUTin Mongrel starting script:

gigix@gigix-laptop:~$ cat /var/service/mongrel_3002/run#!/bin/sh/usr/bin/mongrel_rails -c /path/to/rails/app -C /path/to/mongrel/config 2&1

Dirty, but it works …