Thruk in Lighttpd
This post is really outdated ;)
Thruk is a great piece of software from Sven Nierlein providing a replacement for the old nagios CGIs. If you don’t know about it, just go to the homepage.
I prefer to use lighttpd rather than apache, so i tried to find some docs but nothing very useful.
I found some useful ones on Catalyst wiki. So, let’s applying it to our case.
My server runs Debian GNU/Linux 6.0. It will works on other UN*X using perl/thruk/lightty but some support scripts need rewriting (ie. lightty conffiles in Debian are in a specfic tree, etc…)
From Catalyst wiki
Lightty Config
Enable fastgi support w/ command lighttpd-enable-mod fastcgi
Create a /etc/lighttpd/conf-enabled/90-thruk.conf
config file w/ the following
$HTTP["host"] =~ "^thruk.dahwa.fr" {
fastcgi.server = (
"" => ( # the extension is emty because we want to match on any extension
"myserver1" => (
"host" => "127.0.0.1",
"port" => 55901,
"check-local" => "disable"
)
)
)
}
For those who prefer to use it throught a simple directory instead of a virtualhost, another lighttpd config follows :
$HTTP["url"] =~ "^/thruk/" {
fastcgi.server = (
"" => ( # the extension is emty because we want to match on any extension
"myserver1" => (
"host" => "127.0.0.1",
"port" => 55901,
"check-local" => "disable"
)
)
)
}
reload lightty, you should have a 503 Error on http://thruk.dahwa.fr/ (or http:///thruk/ depending on the choosen configuration)
now, let’s test the fastcgi interface using this in Thruk home
script/thruk_fastcgi.pl --listen 127.0.0.1:55901 --keeperr
Refresh your URL, you should see the thruk interface running.
to have you fastcgi daemon active, you should have a init.d script like the following
#!/bin/bash
# APP_NAME is the Catalyst-normalized name of your app (lowercased, s/::/_/g)
# i.e. the portion before "_create.pl" in scripts/*_create.pl
APP_NAME=thruk
APP_PATH=/opt/Thruk
FCGI_TCP_CONNECTION=127.0.0.1:55901
PID_PATH=/tmp/$APP_NAME.pid
case $1 in
start)
echo -n "Starting $APP_NAME (${APP_NAME}_fastcgi.pl)..."
cd $APP_PATH
script/${APP_NAME}_fastcgi.pl --listen $FCGI_TCP_CONNECTION --pidfile $PID_PATH --keeperr 2>>$APP_PATH/log/error.log &
if [ -r $PID_PATH ]; then
echo " $APP_NAME already running"
exit 0
fi
# Wait for the app to start
TIMEOUT=10; while [ ! -r $PID_PATH ]; do
echo -n '.'; sleep 1; TIMEOUT=$((TIMEOUT - 1))
if [ $TIMEOUT = 0 ]; then
echo " ERROR: TIMED OUT"; exit 0
fi
done
echo " started."
;;
stop)
echo -n "Stopping $APP_NAME: "
if [ -r $PID_PATH ]; then
PID=`cat $PID_PATH`
echo -n "killing $PID... "; kill $PID
echo -n "OK. Waiting for the FastCGI server to release the port..."
TIMEOUT=60
while netstat -tnl | grep -q $FCGI_TCP_CONNECTION; do
echo -n "."; sleep 1; TIMEOUT=$((TIMEOUT - 1))
if [ $TIMEOUT = 0 ]; then
echo " ERROR: TIMED OUT"; exit 0
fi
done
echo " OK."
else
echo "$APP_NAME not running."
fi
;;
restart|force-reload)
$0 stop
echo -n "A necessary sleep... "; sleep 2; echo "done."
$0 start
;;
*)
echo "Usage: $0 { stop | start | restart }"
exit 1
;;
esac
Note that the original script from Catalyst wiki have a bug on line 42
(duplicate then statement)
Don’t forget to update the APP_PATH var.
don’t forget to mkdir APP_PATH/log/
I’ve put this script on script/thruk_initd.sh
and linked it to /etc/init.d/thruk
use update-rc.d thruk defaults 80 20
to autostart it on boot, and enjoy you Thunk w/ Lighttpd ;)
PS : Yes, ii know ;) insserv: warning: script 'thruk' missing LSB tags and overrides