Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed 

LightTPD subdomain rewrite, Backpack/Basecamp style.

Rewrites test.example.com/example/path/ to example.com/test/example/path/

This example show the values being passed to FCGI for use by Django.


$HTTP["host"] =~ "([^.]+)\.example\.com" {
  server.document-root = "/users/home/username/domains/example.com/web/public"
  server.errorlog = "/users/home/username/var/log/lighttpd.example_com.error.log" 
  accesslog.filename = "/users/home/username/var/log/lighttpd.example_com.access.log" 

  fastcgi.server = (
    "/main.fcgi" => (
      "main" => (
        "socket" => "/users/home/username/tmp/django/example_com.socket"
      )
    )
  )

  url.rewrite-once = ( "^(/.*)$" => "/main.fcgi/%1/$1" )
  server.error-handler-404 = "/main.fcgi" 
}

How TextDrive does both PHP and Rails FCGI in one thing-a-ma-bob

fastcgi.server = (
".fcgi" =>
                    ( "localhost" =>
                        (
                            "socket" => "/tmp/textdrive-new.socket",
                            "bin-path" => "/users/home/website/web/public/dispatch.fcgi",
                            "bin-environment" => ( "RAILS_ENV" => "production" )
                        )
                    ),
".php" =>
                    ( "localhost" =>
                        (
                            "socket" => "/tmp/textdrive-php5-fcgi.socket",
                            "bin-path" => "/usr/local/www/cgi-bin/php5-fcgi",
                            "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",   
                            "PHP_FCGI_MAX_REQUESTS" => "5000"
                                                 )
                        )       
                    )
)

yet another lighttpd restart script

#!/bin/sh

USERNAME=username
LIGHTTPD_CONF=/home/$USERNAME/service/lighttpd.conf
PIDFILE=/home/$USERNAME/service/logs/lighttpd.pid
HTTPD=/home/$USERNAME/lighttpd/sbin/lighttpd

PID=0
if [ -e $PIDFILE ]; then
    PID=`cat $PIDFILE`
    if [ "x" == "x$PID" ]; then
        PID=0
    fi
fi

case "$1" in
    start)
        if [ 0 -ne $PID ]; then
            running=`ps --pid $PID | grep $PID`
            if [ $running ]; then
                echo "lighttpd is already running"
                exit 1
            fi
            rm $PIDFILE
            PID=0
        fi
        $HTTPD -f $LIGHTTPD_CONF
        ;;
    stop)
        if [ 0 -eq $PID ]; then
            echo "lighttpd was not running"
            exit 1
        fi
        kill $PID
        tries=""
        while [ -e $PIDFILE ]; do
            if [ "x$tries" == "x.........." ]; then
                break
            fi
            sleep 2
            tries=".$tries"
        done
        if [ -e $PIDFILE ]; then
            echo "lighttpd did not go gentle into that good night, murdering"
            kill -9 $PID
            rm $PIDFILE
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    reload)
        if [ 0 -eq $PID ]; then
            echo "lighttpd was not running"
        fi
        kill -HUP $PID
        ;;
    *)
        echo "Usage: "`basename $0`" (start|stop|restart|reload)"
        exit 1
        ;;
esac

Updated lighttpd control script to kill FCGIs

#!/bin/sh

LIGHTTPD_CONF=/home/USERNAME/etc/lighttpd.conf
PIDFILE=/home/USERNAME/var/run/lighttpd.pid

case "$1" in
    start)
      # Starts the lighttpd deamon
      echo "Starting Lighttpd"
      /usr/local/sbin/lighttpd -f $LIGHTTPD_CONF
    
  ;;
    stop)
      # stops the daemon bt cat'ing the pidfile
      echo "Stopping Lighttpd"
      kill -9 `cat $PIDFILE`
      # kills the dispatch.fcgis
      ps axww | grep dispatch | egrep -v 'grep' | awk '{ print $1 }' | xargs kill -9 
  ;;
    restart)
        ## Stop the service regardless of whether it was
        ## running or not, start it again.
        echo "Restarting Lighttpd"
        $0 stop
        $0 start
  ;;
    reload)
      # reloads the config file by sending HUP
      echo "Reloading config"
      kill -HUP `cat $PIDFILE`
  ;;
    *)
            echo "Usage: lighttpdctl (start|stop|restart|reload)"
            exit 1
        ;;
esac

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed