After install runit, you’ll get /usr/bin/svlogd in your system, which is runit’s service logging daemon. Although there’s a manual, it took me a while to figure our how to use it …

(BTW, runit package in Ubuntu Feisty official repository is broken ...)

svlogd accepts input from its STDIN and 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 /”.

To log a runit’s service, you need create a “log” subdirectory within the service directory, then run 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/sh
exec svlogd -tt /path/to/log # /path/to/log must be writable

Mongrel (in non-daemon mode, i.e. without “-d” option) makes it more complicated: it outputs log to log file of itself (such as ”#{RAILS_ROOT}/log/production.log”), or outputs log to STDERR if the log file is not writable. In order to collect Mongrel’s log with svlogd, I first make “production.log” not writable, then redirect STDERR to STDOUT in 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 …

blog comments powered by Disqus