RSS

Monthly Archives: December 2005

Adding services to Linux startup

Linux operation is controlled by its runlevels. There are 6 different levels defined in /etc/inittab file:

# 0 – halt (Do NOT set initdefault to this)
# 1 – Single user mode
# 2 – Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 – Full multiuser mode
# 4 – unused
# 5 – X11
# 6 – reboot (Do NOT set initdefault to this)
id:3:initdefault:

The above line determines the default runlevel. Each runlevel has its own directory in /etc/rc.d/

Level 3 is /etc/rc.d/rc3.d/
To add an auto-start service, we have to create a start/stop/restart script in /etc/rc.d/init.d/ and then link to it from different runlevel directories. In my case, I linked the lighttpd script from rc3.d, rc0.d and rc6.d. I don’t care about runlevel 1, 2, 4 and 5, as they’ll never be used on a production web server.

Below is the lighttpd script which should be located in /etc/rc.d/init.d:

#!/bin/sh
#
# Startup script for the Lighttpd Web Server
#
# chkconfig: – 85 15
# description: Lighttpd is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: lighttpd
# pidfile: /var/run/lighttpd.pid
# config: /usr/local/sbin/lighttpd.conf

#LIGHTTPD_CONF=/usr/local/sbin/lighttpd.conf
LIGHTTPD_CONF=/www/conf/lighttpd.conf
PIDFILE=/www/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

 
4 Comments

Posted by on December 17, 2005 in Lighttpd, Linux

 

Firefox multi-open

I switched over to Firefox couple months ago or so. I just noticed the “Open in tabs” option, in Bookmarks menu. When you click it, it opens a new tab and loads each of the links at once. If you have 10 bookmarks in the group, it will open 10 new windows. This saves a loooot of time.

 
2 Comments

Posted by on December 10, 2005 in Browsers

 

lighttpd configuration files for multiple rails apps

lighttpd 1.4.8 supports multiple rails aps via ‘strip-request-uri’. Lighty guys wrote about it here.

‘strip-request-uri’ strips URI’s from returning html, which is great if you’re proxying your application through another server. In my case I run apache as a primary server. All my Ruby on rails applications are on lighttpd running on the same server, but higher port, 8888.

One of the domains on the primary server, metak.com, runs my ajaxed dictionary application. For usability purposes I want this domain to operate in “/”, but my true location on lighty server is “/lat/recnik/”. ‘strip-request-uri’ does exactly what’s needed to fix this. Not just that it allows you to have multiple apps, but it gets rid of this “/lat/recnik/” path from resulting html.

Another way of getting multiple apps to work was brought up in the comments of lighty’s post. It works by adding code in rails environment.rb file:
ActionController::AbstractRequest.relative_url_root = “/lat/recnik”

This sure works, but the resulting html includes absolute uri’s “/lat/recnik/….”, so when you access it through the proxy it points to “/lat/recnik” directory which doesn’t exist on the primary server.

This method sure works better if you’re running lighty as a primary server 🙂
Finally, here’s my config file:

# lighttpd configuration file
#
# use a it as base for lighttpd 1.0.0 and above
#
# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $

############ Options you really have to take care of ####################

## modules to load
server.modules              = ("mod_rewrite", "mod_alias", "mod_access", "mod_status", "mod_fastcgi", "mod_accesslog" )

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root        = "/www/site/"

## where to send error-messages to
server.errorlog             = "/www/log/error.log"

# files to check for if .../ is requested
index-file.names            = ( "index.html", "index.htm", "default.htm" )

# mimetype mapping
mimetype.assign             = (
".pdf"          =>      "application/pdf",
[.... lots of boring lines here. Copy them from your original config file! ]
".tar.bz2"      =>      "application/x-bzip-compressed-tar"
)

## be nice and keep it at lighttpd
server.tag                 = "lighttpd | SerbianCafe"

#### accesslog module
accesslog.filename          = "/www/log/access.log"

## deny access the file-extensions
url.access-deny             = ( "~", ".inc" )

$HTTP["url"] =~ ".pdf$" {
server.range-requests = "disable"
}

# which extensions should not be handle via static-file transfer
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

######### Options that are good to be but not neccesary to be changed #######
## bind to port (default: 80)
# Use high ports unless you want to run the web server as root
server.port                = 8888

## bind to localhost (default: all interfaces)
#server.bind                = "serbiancafe.com"

## to help the rc.scripts
server.pid-file            = "/www/run/lighttpd.pid"

#### status module
status.status-url          = "/server-status"

$HTTP["url"] =~ "^/lat/recnik/" {
server.document-root = "/www/site/lat/recnik/public/"
alias.url = ( "/lat/recnik/" => "/www/site/lat/recnik/public/" )
server.error-handler-404 = "/lat/recnik/dispatch.fcgi"
fastcgi.server = ( "/lat/recnik/dispatch.fcgi" =>
(( "socket" => "/www/tmp/recnik.socket" ,
"bin-path" =>  "/www/site/lat/recnik/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" ),
"strip-request-uri" => "/lat/recnik"
)))
}

$HTTP["url"] =~ "^/typo/" {
server.document-root = "/www/railsapps/typo/public/"
alias.url = ( "/typo/" => "/www/railsapps/typo/public/" )
server.error-handler-404 = "/typo/dispatch.fcgi"
fastcgi.server = ( "/typo/dispatch.fcgi" =>
(( "socket" => "/www/tmp/typo.socket" ,
"bin-path" =>  "/www/railsapps/typo/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" ),
"strip-request-uri" => "/typo"
)))
}

### only root can use these options
#
# chroot() to directory (default: no chroot() )
#server.chroot              = "/"

## change uid to  (default: don't care)
server.username            = "wwwrun"

## change uid to  (default: don't care)
server.groupname           = "wwwrun"

#### compress module
#compress.cache-dir         = "/tmp/lighttpd/cache/compress/"
#compress.filetype          = ("text/plain", "text/html")
 
5 Comments

Posted by on December 5, 2005 in Lighttpd, Ruby/Rails

 

Make apache/plesk proxy to lighttpd

I found out that you can use apache as a proxy to another server. ProxyPass does all of the magic. Since I plan to use lighttpd with rails apps running on another port, I created a fresh vhost.conf in the ~user/conf directory which is where Plesk keeps its config files. I added this line:

ProxyPass / http://anothersite.com:port/path/to/your/application/

Now, Plesk doesn’t include vhost.conf files by default, so you have to know about it.

/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=yoursite.com

Restart the server:

/etc/rc.d/init.d/httpd restart

Enjoy!

 
1 Comment

Posted by on December 5, 2005 in Lighttpd, Linux

 
 
%d bloggers like this: