on Aug 5th, 2008sudo: port: command not found

On MacOSX, if you have installed macports with the package installer, you may encounter the sudo: port: command not found problem.

Macports binaries are installed in /opt/local/bin, so you just need to add this path to your PATH environment variable. Example with your user, add to your $HOME/.profile :

export PATH=$PATH:/opt/local/bin

You can source your profile file to update your environment:

$ source .profile

You are now able to use the port command:

$ sudo port -v selfupdate

on Aug 4th, 2008How to know the maximum RAM supported by your server?

The dmidecode command gives you all informations available about your memory.

With the special parameter “-t 16″, you can see the maximum (physical) memory that your server can have:

$ dmidecode -t 16
# dmidecode 2.8
SMBIOS 2.4 present.

Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 8

Here we can see that your server can handle up to 32Gb

Check empty memory slots

To know which slots are used or not use the “-t 17″ flag.

dmidecode -t 17 | grep Size
        Size: 2048 MB
        Size: 2048 MB
        Size: No Module Installed
        Size: No Module Installed
        Size: No Module Installed
        Size: No Module Installed
        Size: No Module Installed
        Size: No Module Installed

Links

on Jul 30th, 2008Follow your debian server updates by email with apticron

apticron is a shell script that send you an email report when new packages are available on your debian server.

Install apticron

As root, do:

apt-get install apticron

apticron configuration via /etc/apticron/apticron.conf

To receive reports on your email change the EMAIL variable in the configuration file. By default, reports are sent to the root user.

EMAIL="root" -> EMAIL="you@domain.com"

Reports received

Now apticron will send you reports like this:

apticron report [Sat, 26 Jul 2008 06:45:47 +0200]
==============================================
apticron has detected that some packages need upgrading on:

        localhost.localdomain

        [ 127.0.0.1 XXX.XXX.XXX.XXX ]

The following packages are currently pending an upgrade:

        lighttpd 1.4.13-4etch10

========================================================================

Package Details:

Reading changelogs...

--- Changes for lighttpd ---

lighttpd (1.4.13-4etch10) stable-security; urgency=low

  [ Pierre Habouzit ]

  * Non-maintainer upload.

  * Fix [CVE-2008-1531] patches mess, and add a missing hunk of the patch.

 -- Thijs Kinkhorst thijs debian org  Tue, 22 Jul 2008 12:19:10 +0200

========================================================================

You can perform the upgrade by issuing the command:

        aptitude dist-upgrade

as root on localhost.localdomain

It is recommended that you simulate the upgrade first to confirm that the actions that
would be taken are reasonable. The upgrade may be simulated by issuing the command:

        aptitude -s -y dist-upgrade

--
apticron

Apticron files

For more informations, you can have a look to those files:

/etc/cron.daily/apticron
/usr/sbin/apticron

on Jul 22nd, 2008Maintenance mode (HTTP 503) with lighttpd and PHP

When you put your website in maintenance mode, it’s a good idea to return a HTTP 503 error code to the client.

This code indicates that “the server is currently unable to handle the request due to a temporary overloading or maintenance of the server”.

The 503 code is used to avoid crawlers or caching proxy use the maintenance page as the new valid content for the request. You certainly don’t want Google save this content in his search index as the content of your website :)

To achieve this we will use a rewrite rule in lighttpd to redirect all requests to a single PHP script which will return a 503 error code and print an informative message.

Lighttpd configuration

url.rewrite = ( "" => "/maintenance.php" )

This configuration will redirect any request to maintenance.php script.

If you need to serve an image in your maintenance page, you have to add another rule to the rewrite process like that :

url.rewrite = ( "upgrading.png" => "$0",
                "" => "/maintenance.php" )

Let some users see the website

It might be usefull to let admins or developers access the website during the maintenance.
For that, you can disable the maintenance rewrite rule for certain IP addresses :

 $HTTP["remoteip"] != “192.168.1.42″ {
               url.rewrite = ( "upgrading.png" => "$0",
                      "" => "/maintenance.php" )
}

PHP code example

<?php
header("HTTP/1.1 503 Service Unavailable");
?>
We're currently upgrading our servers...

Links

on Jul 17th, 2008Rotate Nginx log files under FreeBSD

To rotate your nginx log files, you can use the log file handler provided by FreeBSD: newsyslog.

Configuring /etc/newsyslog.conf

/var/log/nginx-access.log               644  7     1024 *     JC /var/run/nginx.pid
/var/log/nginx-error.log                644  7     1024 *     JC /var/run/nginx.pid

Before log rotation:

-rw-r--r--  1 root  wheel    104278002 Jul 16 11:35 nginx-access.log
-rw-r--r--  1 root  wheel      1509531 Jul 16 11:17 nginx-error.log

After log rotation:

-rw-r--r--  1 root  wheel        967 Jul 16 12:42 nginx-access.log
-rw-r--r--  1 root  wheel    5310443 Jul 16 12:41 nginx-access.log.0.bz2
-rw-r--r--  1 root  wheel         77 Jul 16 12:41 nginx-error.log
-rw-r--r--  1 root  wheel      37552 Jul 16 12:41 nginx-error.log.0.bz2

Links

on Jun 30th, 2008Permanent redirect (301) with lighttpd

If you want to redirect visitors that access your website without the ‘www’, you can use mod_redirect with the following syntax:

$HTTP[”host”] =~ “^lescampeurs\.org” {
    url.redirect = (
        ”^/(.*)$” => “http://www.lescampeurs.org/$1″
    )
}

Links:

on Jun 7th, 2008A new article about Google data centers

On the other hand, Dean seemingly thinks clusters of 1,800 servers are pretty routine, if not exactly ho-hum.

… that would mean Google has more than 200,000 servers, …

Co-founder Larry Page encourages a “healthy disrespect for the impossible” at Google

Dean described three core elements of Google’s software: GFS, the Google File System, BigTable, and the MapReduce algorithm.

Read it at CNET

on Jun 4th, 2008Rotate Apache logs with Cronolog

Cronolog is log rotation program which gives you a lot of options to template the log destination files. The common use is to split logs by year / month / day.

Here is how to configure Apache to send log entries to cronolog :

CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%m-%d_domain.com_access.log" combined

This will create a log file named 2008-06-02_domain.com_access.log for today.

Cronolog reads log entries from standard input and writes them to the output file specified by your template.

More examples

  • Rotate by month :
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%m_domain.com_access.log" combined
  • Rotate by week number :
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%W_domain.com_access.log" combined
  • Rotate hourly
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%H_domain.com_access.log" combined

Links

on May 28th, 2008Deny access to .svn directories with Apache2 / lighttpd

If you’re using SVN to control your web application, your certainly need to deny access to .svn sub-directories.

With Apache2

    <DirectoryMatch "^/.*/\.svn/">
            Order allow,deny
            Deny from all
    </DirectoryMatch>

With lighttpd

    $HTTP["url"] =~ "/\.svn/" {
        url.access-deny = ( "" )
    }

on May 23rd, 2008Retrieve file from svn

Sometimes you need to retrieve a single file from SVN without doing a checkout on the repository.

SVN provides the svn cat to output the content of a file. You can redirect the output to get the file as :

svn cat https://svn.mydomain.com/project/folder/file.ext > file.ext

You can also use a simple shell script to do the work :

$ cat svnget
#!/bin/sh

if [ -z "$1" ]; then
        echo
        echo "Usage : $0 <SVN-URL>"
        echo
        exit
fi

fn=`basename $1`
svn cat $1 > $fn