Call us Toll-Free:
1-800-218-1525
Email us
This weekend we converted all SPI mutlihomed hosting email mailboxes from the mbox format to maildir.

What is the difference between mbox and maildir?

Mbox is the traditional way of storing mail messages in the Unix world. In this format, a regular text file which serves as the mail user's mailbox file is created.

Pros: Format is universally supported, Appending a new mail into the mailbox file is fast, Searching text inside a single mailbox file is fast.

Cons: Has file locking problems, Has problems when used with network file systems, Format is prone to corruption.

Maildir is a new way of storing mail messages. In this format, a directory usually named Maildir is created for each mail user. Under this directory are three more directories named new, cur and tmp.

Pros: Locating, retrieving and deleting a specific mail is fast, Minimal to no file locking needed, Immune to mailbox corruption (assuming the hardware will not fail).

Cons: Some filesystems may not efficiently handle a large number of small files, Searching text, which requires all mail files to be opened is slow.

Why we chose Maildir

We've decided to upgrade to Maildir because its more reliable (entire mailbox never fully corrupts) and thanks to no locking it is noticeably much faster to access your mail over Maildir.

Ongoing mbox file locking issues were driving us nuts.

SPI is using the Dovecot mail server on all machines. Dovecot is one of the highest performing IMAP servers. Luckily it supports both mbox and maildir, so all we had to do was: Convert old email messages from mbox to maildir.

Mb2md

Mb2md is a Perl script that takes one or more Mbox format mailbox files in a directory and convert them to Maildir format mailboxes.

Replace USERNAME below with the unix username whose mailbox you are converting

Step 1: Set environment variables for Mb2md

setenv MAIL /var/mail/USERNAME

Step 2: Convert the inbox folder and create Maildir folder

sudo -u USERNAME mb2md -m

Step 3: Convert other folders the user created

sudo -u USERNAME mb2md -s /home/USERNAME/mail/ -R

Step 4: Copy IMAP subscriptions

cp /home/USERNAME/mail/.subscriptions /home/USERNAME/Maildir/subscriptions

Step 5: Tell sendmail to deliver new mail to the user's /Maildir

cd /home/USERNAME
echo '"|IFS='"' '"' && exec /usr/local/bin/procmail -f || exit 75 #YOUR EMAIL NAME"' >> .forward
chmod 644 .forward
echo "DEFAULT="'$'"HOME/Maildir/" >> .procmailrc
chmod 644 .procmailrc
chown USERNAME:USERNAME .forward
chown USERNAME:USERNAME .procmailrc

Step 6: Delete old mbox files

rm /var/mail/USERNAME
rm -fdr /home/USERNAME/mail

Testing & Troubleshooting

To test, use sendmail to send a test message to your user:

sendmail USEREMAIL
subject: Test, please ignore

This is a test
.

If all works well, your email message will be delivered to the user's Maildir.

If you see the mail appended to /var/mail/USERNAME (do a tail -f /var/mail/USERNAME), this means sendmail is failing to invoke .procmailrc and deliver the email message to Maildir.

This is usually due to the /home or /home/USERNAME folders not having the correct file permissions.

Run this command to troubleshoot:

sendmail -v -Am -d11 USERNAME < /dev/null
In a recent post, we explained how to run FreeBSD on Windows using VirtualBox. Today we will show you how to achieve the same thing but using VMware Server. VirtualBox is a very nice application: it's fast, simple and lightweight; but VMware Server has some very interesting features to offer:

* It can run any number of virtual machines in the background. You don't need to keep any window opened and you can simply access your virtual machines using SSH if you wish.

* It supports any guest operating system, including 64-bit versions.

* All the administration is done via a great Web interface.

As VirtualBox, VMware Server is also 100% free. Another product that is competing VMware Server, and that is also free, is Microsoft VirtualServer. It has the same features but is harder to install, harder to use and is a lot more fragile. After months of testing, VMware Server proved to be the best on performance, stability and usability.

1. Download VMware Server

The first step is obviously to download VMware Server. Go there: http://www.vmware.com/products/server/ and click on the "Download" button on the left. You will need to register to download the software. Once you're registered and logged in, copy the "VMware Server 2 for Windows" serial number displayed in the "Licensing" section of the page and paste it somewhere - you will need it later. Then grab the "VMware Server 2" EXE image under the "Binaries" section. The file is around 500MB.

2. Install VMware Server

Installing VMware Server is very straightforward: basically, you simply run the setup file and hit next, next, next, next... without changing anything. There's no real options except which shortcuts you want to create.

At the end of the setup, you will be asked to enter your serial number. Because of the virtual network adapters VMware Server installs, you will also be required to reboot: you need to do it immediately if you want to go further in this tutorial.

3. Download FreeBSD

In this tutorial, we'll be installing FreeBSD 7.2 minimal. If you have a 64-bit CPU, download this one (amd64 release):

ftp://ftp.freebsd.org/pub/FreeBSD/re...md64-disc1.iso

If you have a 32-bit CPU, download this one (i386 release):

ftp://ftp.freebsd.org/pub/FreeBSD/re...i386-disc1.iso

The ISO file is around 600MB.

4. Create the FreeBSD Virtual Machine

Start the VMware Server Web Access using the Start Menu shortcut (called "Web Access") or use your favorite browser and go to this URL: http://127.0.0.1:8308/ui/

Log into the VMware Server Web Access using your Windows account.

The first thing to do is to add a Datastore to your VMware Server configuration. To do so, click on your machine name on the left panel and click on the "Add Datastore" link on the right panel. The Datastore is a folder where everything about virtual machines will get created and stored. Simply give it a name and specify the directory (example: name: VM, directory: d:\VM).

Click on the "Create Virtual Machine" on the right panel:

* Name the virtual machine "FreeBSD", select the Datastore you've just created and hit next.

* Choose "Other operating systems", choose "FreeBSD" (32 or 64-bit, depending on your CPU) in the combo box and hit next.

* Assign the amount of memory you want your virtual machine to have (usually the recommended amount is quite good, unless you need a high-performance virtual machine). If you have a multi-core CPU (or many CPU's), you can choose the number of CPU's you want your virtual machine to use. Hit next when you're satisfied with your settings.

* Select "Create a New Virtual Disk" and hit next.

* Choose the size you want your virtual disk to have and hit next.

* Select "Add a Network Adapter" and hit next.

* Leave the settings to "Bridged" and hit next.

* In the CD/DVD section, select "Use an ISO Image" and hit next.

* Move the FreeBSD 7.2 ISO image you've just downloaded somewhere under the directory you're using as your Datastore. Then select it and hit OK. Then hit next.

* Select "Don't Add a Floppy Drive"

* Select "Don't Add a USB Controller"

* Check "Power on your new virtual machine now" and Hit "Finish"

5. Installing FreeBSD

Now that your FreeBSD virtual machine is created, it's time to install FreeBSD! First of all, in the VMware Server Web Access, click on the FreeBSD virtual machine on the left panel. Then click on the "Console" tab on the right, and click anywhere in the black screen. A small console window will popup: that's your FreeBSD machine, just like if you were sitting in front of a computer running FreeBSD.

NOTE: the console window "steals the focus"; at any time, press CTRL+ALT to release focus from this window. And simply click into the console window to use it.

It should boot from the ISO image you've specified in the setup: it's now time to install FreeBSD:

* Choose "United States" and hit enter.

* Choose "Standard" and hit enter.

* In the Disk Geometry screen, hit "a", then "q".

* Choose "BootMgr" and hit enter.

* In the Partition screen, hit "a", then "q".

* In the "Choose Distributions" screen, select "Minimal" and hit space to check it. Then hit tab, then enter on the OK button.

* Choose CD/DVD and hit enter. The base system will install.

* Network:

Hit "yes" to configure network.
Choose the "em0" network interface.
Hit "yes" to configure using DHCP.
Enter an hostname and hit enter many times.
Choose "no" to use this machine as a gateway.
Hit "no" to enable inetd.
Hit "yes" to enable SSH.
Hit "no" to anonymous FTP.
Hit "no" to NFS server.
Hit "no" to NFS client.

* Last settings:

Hit "no" to customize console.
Hit "yes" to timezone and choose your timezone.
Hit "no" to PS/2.
Hit "no" to package collection.
Hit "no" to create a user.
Set the "root" password.
Hit "no" to visit the options menu.

At the main menu, hit tab to go to the "Exit Install" option, hit enter and then hit "yes". Close the console. In the VMware Server Web Access, select the FreeBSD Virtual Machine on the left panel and hit the red "stop" sign at the top. Then hit the green "play" sign and return in the console. Your FreeBSD system should boot normally.

6. Mounting a shared folder using Samba

It's very convenient to be able to easily and quickly share files between your Windows and FreeBSD machine.

First of all, share a folder on your Windows machine (ex: share). It can be any folder, just share it normally. Then choose a mount point for that folder on your FreeBSD (ex: /mnt/share). We're now going to configure your FreeBSD machine so the shared folder will be automatically mounted at boot time.

Here's the sample informations (replace with yours):

Windows machine: win
Windows IP addr: 192.168.0.100
Windows share: share
Windows user: administrator
Windows password: mypass
FreeBSD mount point: /mnt/share (do not forget to create the directory!)

In /etc/nsmb.conf, add:
NOTE: the caps are important

[WIN]
addr=192.168.0.100

[WIN:ADMINISTRATOR]
password=mypass

Then in /etc/fstab, add:

//administrator@win/share /mnt/share smbfs rw 0 0

NOTE: before rebooting FreeBSD to test, I recommend testing the mounting manually with a command like this:

mkdir -p /mnt/tmp
mount_smbfs //administrator@win/share /mnt/tmp

Finally, reboot your FreeBSD machine and then go check in your mount point (like /mnt/share) if it works! Try creating folders from FreeBSD and from Windows and verify if it's working correctly. If it's not, the problem is probably on the authentication side.

7. Starting the virtual machine automatically

One other great VMware Server feature is the ability to start virtual machines automatically when you boot Windows.

To configure this, in the VMware Server Web Access, click on your Windows machine name on the left panel, and then click on "Edit Virtual Machine Startup/Shutdown Settings". Select your FreeBSD virtual machine and click "Move Up" to put it in the "Any Order" category.

Conclusion

You now have a FreeBSD virtual machine, acting just like if it was a real server sitting somewhere in your house! Virtual machines are great for development and testing. Please let me know if you have any problems getting this tutorial working!
Step 1 - Download and install VirtualBox

VirtualBox is a general-purpose full virtualizer for x86 hardware. It allows running any flavor Unix system on a Windows box.

You can download the latest version of VirtualBox for Windows Hosts here

Step 2 - Download FreeBSD 6

Download the single-file dvd iso here FreeBSD 6.4 download repository

Download 7-zip and extract the 6.4-RELEASE-i386-dvd1.iso.gz file to a folder on your machine

Step 3 - Create a new FreeBSD VirtualBox machine

Create a new VirtualBox machine, selecting BSD as the operating system and FreeBSD as the version.



Click Next to accept all defaults, but when you get to the 'Virtual Disk Location and Size' screen, change the disk size to 50GB.

Double-click the new machine to start it.

Step 4 - Install FreeBSD on new Virtual Machine

You will be greeted with a 'Welcome to the first run' wizard.

A 'Select Installation Media' screen will then popup. Pick the 'Image File' option, click the icon and locate the folder on your machine where you previously saved the FreeBSD iso file.



Click next a few times, keeping all default options.

FreeBSD install will boot in the VirtualBox

Select OK for United States
Select Standard Installation
Click A for 'Use Entire Disk', followed by Q
Click Enter for BootMgr
Click A for 'Auto Defaults', followed by Q
Select option 4 (Developer) and Yes to install ports
Select 1 for Install from CD

You will see a message saying All file information saved successfully. FreeBSD install will then begin running.

Step 5 - Configuration

Select YES to configure Ethernet network devices and pick your Ethernet card on the next screen

Select YES for DHCP

Select NO for network gateway and NO for iNetD

Select YES to enable SSH login

Select NO for FTP and NFS server/client

Select NO for all remaining questions

Pick a password for your root user

From the VirtualBox menu, select Devices - then Unmount CDRom

Enter X to exit install and reboot the FreeBSD virtual machine
If you're using MySQL InnoDB tables with these two lines in your /etc/my.cnf, for the most part, your database should gracefully handle unexpected shutdowns without data corruption:

innodb_flush_log_at_trx_commit=1
sync_binlog=1

I was working on such a database today, that experienced a power outage.

While all InnoDB data remained intact (I verified the checksum to ensure database is in sync), replication relay logs got corrupted.

Trying to SLAVE START failed with this nasty error message:

Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.

Here's how to recover from such an error -

Step 1: Identify the corrupted file

Issue a SHOW SLAVE STATUS followed by a SHOW MASTER STATUS and record the relay log filenames and positions.

In my case those were: mysql-bin.000313 position 1037717439 and mysql-bin.000249 position 326501604

Running mysqlbinlog to read the first block in each of these files, starting at the last position, immediately reveals the problematic file:

/usr/local/mysql/bin/mysqlbinlog -Hvv mysql-bin.000313 --start-position=1037717439 | more

ERROR: Error in Log_event::read_log_event(): 'Event too small', data_len: 0, event_type: 0
ERROR: Could not read entry at offset 326501604: Error in log format or read error.
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;

Notice the ERROR on the first line. This tells us we've found the corrupted replication file

Step 2 - Skip the bad block

This involves some trial and error, but what we want to do is use mysqlbinlog to manually parse MySQL replication log file to the end, bypassing the 'Event too small' bad block.

Once done, we have to update relay-log.info, so that MySQL doesn't try to process this file again.

Replaced this:

cat relay-log.info

./mysql-bin.000313
1037717439
mysql-bin.000249
113612

With:

./mysql-bin.000314
0
mysql-bin.000249
113612

(Telling MySQL to advance to the next file mysql-bin.000314)

Step 3 - Restart database

While this may be a bit of an overkill, I prefer restarting the entire database, before issuing a SLAVE START

mysqladmin shutdown
mysqld_safe &
Mercurial server can be setup in two modes:

* hg serve - a built in lightweight web server that is provided as part of the Mercurial package. hg serve can be used to quickly serve a single repository, but it's not a good choice for production systems.

hg serve doesn't support user authentication, multiple repositories and is limited to handling a single connection at a time.

* hgweb.cgi - a Python script that is faster, supports user authentication, multiple repositories, styles and web console.

As part of this post I'll walk you through setting up hgweb.cgi on an NGinx web server.

Step 1 - Install Python

cd /usr/ports/lang/python25
make all install

Step 2 - Install hgweb.cgi

Save this file under your web server main direcory.

hgweb.cgi:
#!/usr/bin/env python

import cgitb
from mercurial.hgweb.hgwebdir_mod import hgwebdir
from mercurial.hgweb.request import wsgiapplication
from flup.server.fcgi import WSGIServer

cgitb.enable()

def make_web_app():
return hgwebdir("/home/admin/htdocs/hgweb.config")

WSGIServer(wsgiapplication(make_web_app)).run()

Replace /home/admin/htdocs/ with your web server folder

Step 3 - Configure hgweb

Save this config file under your web server main directory.

hgweb.config:
[ui]
username = root
editor = vim

[hooks]
changegroup = hg update >&2

[web]
baseurl =/.
style= gitweb
push_ssl = false
allow_push = *

[paths]
Clients = /home/
SPI = /home/admin/htdocs/

Replace mydomain with your web server url

Create this global settings file under /etc/mercurial/hgrc:

[web]
style= gitweb

Step 4 - Install Spawn-fcgi

Before we can tell NGinx to handle the hgweb.cgi Python script, we have to install spawn-fcgi

Follow these steps:
wget "http://www.lighttpd.net/download/spawn-fcgi-1.6.2.tar.gz"
tar -xvf spawn-fcgi-1.6.2.tar.gz
cd spawn-fcgi-1.6.2
./configure
make all
make install

Start spawn-fcgi:
/usr/local/bin/spawn-fcgi -f /home/code/hgweb.cgi -a 127.0.0.1 -p 8081

Try running hgweb.cgi by issuing: python hgweb.cgi
If you get a message about missing flup, you'll have to download flup and install it:

wget "http://www.saddi.com/software/flup/dist/flup-1.0.1.tar.gz"
tar -xvf flup-1.0.1.tar.gz
cd flup-1.0.1
python setup.py install

--

Now create a new file under /usr/local/etc/rc.d/start-spawnfcgi.sh to start spawn-fcgi automatically after a reboot.

Save the same line above under /usr/local/etc/rc.d/start-spawnfcgi.sh

Step 5 - Configure NGinx

Add this to your nginx.conf, replacing mydomain.com with your web server domain name and 1.2.3.4 with the dedicated ip address:

server {
listen 1.2.3.4:80;
server_name mydomain.com;

server_name_in_redirect off;

auth_basic "Restricted";
auth_basic_user_file /home/hg/.htpasswd;

gzip on;

location / {

root /home/hg/;
index index.php index.html index.htm;

fastcgi_pass 127.0.0.1:8081;
fastcgi_param SCRIPT_FILENAME /home/hg/$fastcgi_script_name;
include /etc/nginx/fastcgi_top.conf;
fastcgi_param DOCUMENT_ROOT /home/hg/;
include /etc/nginx/fastcgi_bottom.conf;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}


}

Note that we are password protecting the repository by using an .htpasswd file. You can generate one using publicly available htpasswd generators like this one.

Tell NGinx to reload its configuration file:
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

If all goes well, you should be able to point your browser to mydomain.com and see a list of Mercurial repositories.

View 2 Comment(s)

Mercurial Version Control

Adrian Singer, September 2
Mercurial (also called HG) is a cross-platform, super-fast, distributed revision control system for software developers.

Unlike other version control tools such as CVS, SVN, Preforce etc., Mercurial is a distributed system, where every node can act as both a client and server.

We've tested a lot of competing revision control systems, before Mercurial won us over.

The advantages Mercurial brings to the table include:

* Allows users to work on a local copy of the files, even when not connected to a network

* Most operation are faster since no network is involved

* Allows private work, so you can use your revision control system even for early drafts you don't want to publish

* Avoids relying on a single physical machine. A server disk crash is a non-event with distributed revision control

* Allows participation in projects without requiring permissions from project authorities, instead of requiring "committer" status

Graphical User Interface

Mercurial comes with great desktop integration for Windows and Mac, using a tool called Tortoise. Once installed, it adds a right-click context-menu, allowing one-click commit, file diff, sync, directly from the file explorer.

Tortoise includes a green icon next to all files that are up-to-date and an orange icon next to files that have been updated and need to be uploaded.



How to install Mercurial

An all-in-one Mercurial+Tortoise installer is available here

Once installed, Mercurial will add a right-click context-menu, as shown in the image above.

Before you move forward, it is important that you setup a Username, so that all Commits you upload, include your name.

Right click and select 'Global Options' from HG menu. Then enter your full name under Username



Next - click on the 'Sync' tab and select Update as the 'after pull operation'



Connecting to a live repository

Create a new folder on your machine where you'd like to save all source files, right click and select 'Create Repository Here' from Mercurial's menu



This will create two files under the current directory:
.hg subfolder
.hgignore text file

To avoid any conflicts, go ahead and delete the .hgignore text file.

Now that the repository is created, we can download all files from the server. Right click again and select 'Synchronize' from the menu.

This popup window will open:



Enter the live repository url and click the 'Pull' button to download all source files from the live repository.

Note: You can repeat this process of synchronizing with the live server, whenever you'd like to download updates from the server.

The first time you synchornize, it's going to take a while. But subsequent pulls will be very quick.

Updating Files

Step 1: Open the local copy of the file in your favorite editor, make changes and hit Save.

Mercurial detects the change and automatically updates the file icon to orange.

Step 2: Once you're done making changes, right-click and select HG Commit.

Enter a comment describing the changes you've just implemented. For example:
"Project 384283 - Added opt-in form on instant pay increase"

Good comments are the basis of a solid version control system. Your comments help other developers understand the nature of your changes, as they download them to their local repositories.

Step 3: Unlike a centralized cvs, the 'Commit' operation is a local one. Once changes are committed to your local repository, Right click and select 'Synchronize'. Enter the live repository url and click the 'Push' button. This takes care of uploading your changes to the server.

Adding new files to the project

In order to add a new file, you have to take one additional step -

Highlight the new files, right click and select 'Add Files'



Then, follow the steps listed under "Updating Files", committing changes and synchronizing with the server.

View 3 Comment(s)
« Previous Posts » Next Posts



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions