Personal.X-Istence.com

Bert JW Regeer (畢傑龍)

Ubuntu multiple loopback interfaces

So today I was playing around with this crap named Ubuntu and I could not figure out why my extra loopback interfaces I added to /etc/network/interfaces would not show up after restarting networking with /etc/init.d/networking restart. The reason for that is that it excludes all loopback interfaces.

auto lo
iface lo inet loopback
auto lo:0
iface lo:0 inet static
address 127.0.0.2
netmask 255.0.0.0

Then use the function "ifup" to restart all the networking stuff. ifup -a. You are not set, check with ifconfig.

My Lesbian Love

Imagine you are back in high school. You are sitting in your English class. It is silent reading time. You carefully take a sip of your cup of coffee. You put your book down and stare out the window at the gym class that comes running by. You wonder if you have to do any running for gym today as well, or if your teacher is nicer. You think of your girlfriend and wonder how bored she is currently in French. You pick your book up again, and start reading just as your teacher looks up to see if everyone is still reading. You take a quick peek at the clock, only 10 minutes left to go! You take out your Palm V and add a note to yourself about picking up another book by this author. You take a look down at the floor where your backpack is sitting and you make a quick mental note to clean it out sometime and wash it.

The bell rings, and you jump up. You are not in school anymore, you are at home, and the bell is the front door. You get up out of bed wondering what time it is, and wander down stairs without getting the question answered as it seems the power is off. You yawn as you open the door, and take a look at the guy standing there pulling the door bell. It is Fedex. They are delivering the stuff you ordered online only two days ago. Just as you are starting to take the package apart the power comes back online, causing all the devices in the house to start flashing 12:00. With a sigh you take a look at your watch that was sitting on the kitchen table, 17:35, you make a mental note not to sleep all day again. After all the devices are reset you take a look at the mess on the kitchen table. Motherboard, hard drives, memory, everything all scattered over the place. You find the other box Fedex has also delivered, you assume it contains the new computer case. You look at the box and notice that it has been kicked around by Fedex, once again. Your parents are not going to be home for a while, so you decide to call up your girlfriend Melissa. Your heart skips a beat at the excitement of having her around to help you out. She picks up the phone and you say "Hey, just got my stuff from Fedex, want to come drop by and give me a hand?" Her reply is quick, "Sure, I'll give you a hand in more than one way", she giggles at the sexual connotation. you get back to unpacking. After all the components are laid bare on the table your girlfriend shows up, she rings the door bell and you let her in. Without even saying a word she walks over to you, and gives you a big kiss, she then walks over to the table. You follow her. As she is about to say something, you reach into your pocket and pull out what she was going to ask about. You hand them to her, and let her more feminine hands take care of the case for you. You look over the parts scattered all over the table, in the mean time she slowly one by one takes the screws out of the case, which seems to have survived the travel from Newegg in New Jersey to Arizona without any troubles, even-though the packaging it came in was for all other intents and purposes destroyed.

The rig is complete, you and your girlfriend completed a task normally done in a few hours within 45 minutes. The big question you have is, does it boot up? You walk up stairs back to your room to grab the spare LCD monitor you have sitting around. You also grab a monitor and the FreeBSD install CD. You think to yourself, a server should not be run on anything else. You head back downstairs, and find that Melissa has already found an extra power outlet in your kitchen. You hand over the keyboard and the CD, and plug in the power to the computer and the LCD. You then plug it into the onboard video card. You hit the power button ....

Fast forward a few years, you are sitting in University and you have an awesome teacher named Ellen. She has just given you an assignment that involves writing in the second person, and you can't think of anything. Your mind wanders as she starts to give more instructions, and something about a free writing exercise. You wander a few years back and wonder where it went wrong with Melissa. Was it the fact that your mom walked in on you two in bed? Was it the fact that you are a lesbian? Maybe it was the distance that was generated between the two of you when your mom did not let you go out on Friday night anymore. Made you go to Church classes, and tried to make you like guys. You start thinking about how society is screwed up, and how it is wrong that society does not accept people that are not like them. You think you are going to write this second person essay on just that topic. You take out a pen and start jotting down ideas, unbeknownst to you, you are following the class. Your teacher Ellen has just told everyone to make a spider web of what they want their essay to be on, and how they want it modelled. You start having more questions than answers. It is 20 past the hour, class is over. That concludes all the classes you have for today and as you make your way towards the exit you notice a girl you remember from your Linux/UNIX class sitting in the corner playing some new game. As you walk over you ask yourself if you are really falling for her. She has beautiful green eyes, not unlike your own. However hers have a tint of blue in them as well. You get more and more confused as you walk over to where she is sitting.

As you walk over to her, you start to get more scared. You start asking yourself questions like, how should I approach her. You feel insecure, and worst of all, you have no-one to fall back on yet. No-one to talk to about your feelings. Right before you get to her, you panic, you turn around and walk away. Away from the feelings of insecurity, away from someone you are falling in love with. You know you are falling in love, the butterflies, they are all signs. The cold sweats, the dreams. You want to be with her, you can't foster the courage to walk up to her and talk to her. You don't seem to have power over your legs as your body walks away while your brain and heart want to go back. You know you want to be with her, everything about her makes you complete. Her eyes, her body, the way she moves, the way she talks and smiles. You know Jennyfer would make you a complete human being, and happy again. You just don't have the power, you are afraid of failure.

That night as you are lying in bed, thinking of Jennyfer you wonder how to approach the problem. You ponder on it for a long time before finally falling asleep. You dream about being with Jennyfer again. Holding her hand, kissing her lips, hugging her, taking showers with her, sleeping with her. It seems like the dream never ends, but at 07:30 your alarm clock goes off, and wakes you up. You hit it, and it stops making the god-awful noise. You get out of bed, and head into the bathroom, you turn on the shower, and head into the kitchen. You grab some corn flakes and some milk. Following your daily ritual you take the milk and put it in the bowl, after which you let it sit there and walk back to the bathroom. By this time your shower is nice and warm and provides a soothing stream of water. You wash your hair, and shave. You get out of the shower, still naked you walk back into the kitchen, grab the bowl, the corn flakes and you poor them in. You start eating as you walk back to the bed room. Here you quickly throw on some clothes, put on some eye liner, and grab your purse and head out the door. You take care to lock the door, and run to the bus.

As you are on the bus it hits you. You are going to go back to your high school days and do what you did best. Write little notes. The ones you used to write about the teacher when they had their socks on backwards, or when you tried to get Melissa's attention to go out to lunch after school was over. You start thinking about how you could approach the situation. As you write the note you start thinking of how to get it to Jennyfer. The note you write is simple. In it you ask her if she wants to come out to dinner tonight. You see her in the computer lab when you walk in. Different location, yet she still seems like she is sitting alone in a corner. Her beauty shining like the ray's of the sun as it rises. As you walk by, you nonchalantly put the note down on the table and walk on. You have two classes to go before you might get a reply. You are hoping so desperately to get a reply. You sit through your two classes with anxiety wondering if Jennyfer will take you up on your offer, or if she will shoot you down. As you walk into your Linux/UNIX class you notice that at the stop you normally sit at, there is a note half hidden underneath the keyboard. You take it out and read it. All it says is "Who is asking?". Your heart drops as you fear that she thinks you are helping out some guy. You scribble on a note "Me", and hand it to her with a slightly trembling hand. The smile she gives you though gives you hope. At the end of class as you are exiting you feel a slight tap on your shoulder. You turn around and there is Jennyfer. She smiles and gives you the most reassuring nod, and then says "Yes, I do want to go out to dinner with you!"

Book signing with Internet Legend Maddox

So Maddox was here in Tempe, AZ for a book signing (The Alphabet of Manliness, if you have not bought a copy yet you should right now!) at the borders on Mill Ave, which meant I headed over there with another friend of mine here from UAT. Maddox is an asshole! Seriously.

He was one of the coolest people I have ever met. I got my book signed, and he said "Manly handshake" in mine. My handshake is a strong grip (just like his), and two very small pumps, quick and subtle. I off course got a picture with me and him, but since it was taken on my Phone, the image quality is shit, and because of the lighting, it tried to expose it too long and it caused it to be moved. :-(, but at least it is a picture with the man, the myth and the legend!

Me and Maddox

I will take some pictures of the signing he did in the book, and post those online soon as well.

FastCGI quick and dirty

In this quick and dirty guide for FreeBSD I will assume you have already compiled and installed PHP5 with fcgi mode enabled, which can be checked by running:

/usr/local/bin/php-cgi --version

I will also assume you have installed mod_fastcgi from www/mod_fastcgi in the ports.

Create the fast cgi ipc temp dir, make sure you place this somewhere it will keep existing:

cd /var/tmp
mkdir -p /var/tmp/fcgi-ipc/dynamic
chmod -R 0777 /var/tmp/fcgi-ipc

Let's create the directory where we are going to place our PHP wrapper, this config is for server wide using the same FastCGI PHP config. This is on purpose, since it will allow server wide PHP usage. If you want you could then split it up into virtualhosts if one required a standalone php running for that.

mkdir /usr/local/www/fastcgi-bin/
chmod 755 /usr/local/www/fastcgi-bin/</pre>

Next up we create the very simple wrapper

cat << EOF > /usr/local/www/fastcgi-bin/php5.fcgi
#!/bin/sh
# To use your own php.ini, comment the next line and uncomment the following one
#PHPRC="/usr/local/etc"
export PHPRC
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
exec /usr/local/bin/php-cgi
EOF

Set PHP_FCGI_CHILDREN to whatever value you want, that is how many processes it will use. I suggest the standard which is 8, if you make it more, you use more ram, you make it less Apache will have to wait if all of the PHP processes are in use.

Next up, make it executable:

chmod +x /usr/local/www/fastcgi-bin/php5.fcgi

Last but not least, edit httpd.conf and make sure to add a comment in front of the mod_php5 line, and uncomment the mod_fastcgi line. Then add this to the end of your Apache config:

<IfModule mod_fastcgi.c>
    FastCgiIpcDir /var/tmp/fcgi-ipc/
    FastCgiConfig  -pass-header HTTP_AUTHORIZATION

    AddHandler  fastcgi-script              .fcgi .fcg .fpl

    Action      application/x-httpd-php5    /fastcgi-bin/php5.fcgi
    AddType     application/x-httpd-php5    .php .php5
</IfModule>

ScriptAlias /fastcgi-bin/ "/usr/local/www/fastcgi-bin/"
<Location /fastcgi-bin/>
    Options ExecCGI
    SetHandler fastcgi-script
    Order allow,deny
    Allow from all
</Location>

That's it. Restart apache and watch as the first time you access a PHP script FastCGI will spawn several of them, and they start serving requests. Load usage may seem higher, that is because unlike Apache the standalone running PHP's handle the jobs as they come in with whatever one is first, Apache will try to put as much work in one of it's preforked modules. As the PHP processes come and go through FastCGI the memory usage will go up and down. Mine has an average of about 300 MB, which is very good compared to the 800 MB Apache with mod_php would rack up.

Backup Script

I was working one some backup scripts and I decided I might as well generalise almost all of it (I am sorry about the hard coded paths) so almost anyone can come grab it and use it on their servers. The shell script is pretty self explanatory and I am not very good at documenting code, so the script source itself is your best bet as to why I did something some way. This script is in production use on several servers I administrate, I hope someone can use it as well.

Documentation on how to use it:

New backup script which will mount a /backup, then use rsync to copy files from /usr/home to /backup/yyyy-mm-dd. After it is done, it will remove the oldest backup, 14 days ago. All paths are hardcoded.

If a file .exclude is in a users homedir, it is looked at, and is used to exclude certain directories or files from the rsync. For example:

in /usr/home/xistence/.exclude

public_html/iso

No trailing slash, this will cause the folder /usr/home/xistence/public_html/iso to not be backed up. This might be for various reasons, but for this example it is because backing up GB sized files should not be something that is done, only because it takes ages and wastes valuable space.

Thing to keep in mind is, if you want to backup a 40 GB HD, with 22 GB used, to keep even a 3 day backup of that would require 3 * 22 GB, or 66 GB of available space on the backup drive. It is therefore in ones best interest to exclude very large files, and back them up in a different method since they are most likely not going to change much across revisions.

This script should be set to cron every 30 minutes, as rsync will do one full backup when the day changes, and then from there on do incremental backups.

Maybe removing the --delete option might help with customers that delete files and expect them to still be in the backup for that day, this way however if a file is removed it will still exist in the backup until it is deleted after 14 days.

#!/usr/local/bin/bash

# This file REQUIRES bash, and can not be run under /bin/sh!

###
 # Copyright 2006 Bert JW Regeer. All rights  reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
 #    notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
 #    notice, this list of conditions and the following disclaimer in the
 #    documentation and/or other materials provided with the distribution.
 #
 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
 # The views and conclusions contained in the software and  documentation are
 # those of the authors and should not be  interpreted as representing official
 # policies, either expressed  or implied, of bsdPanel project.
 #
###

for HOMEDIR in `/usr/bin/find /usr/home -type d -maxdepth 1 | grep -v '^.$'`; do
    if [ -f $HOMEDIR/.exclude ]; then
        echo "Exclude found for $HOMEDIR"
        while read line; do
            if [ "${line:0:1}" != "/" ]; then
                # They are missing a full path, we will be nice and add it
                TMPLINE="$HOMEDIR/$line"
                line=$TMPLINE
            fi
            echo "  Excluding $line"
            echo $line &gt;&gt; /tmp/exclude.$$
        done &lt; $HOMEDIR/.exclude
    fi
done

mount | grep /backup

if [ $? -ne 0 ]; then
    /sbin/mount /backup
    if [ $? -ne 0 ]; then
        logger -s -p user.err -t backup "Backup drive could not be mounted! Bailing!"
        /sbin/umount -f /backup
        exit 1
    fi
fi

BACKUPDIR="/backup/`date "+%Y-%m-%d"`"
OLDDIR="/backup/`date -v-14d "+%Y-%m-%d"`"

if [ ! -d $BACKUPDIR ]; then
    mkdir $BACKUPDIR
fi

if [ $? -ne 0 ]; then
    logger -s -p user.err -t backup "Could not create backup folder $BACKUPDIR. Bailing!"
    /sbin/umount -f /backup
    exit 1
fi

# We got this far, now we have to run rsync. Rsync is very verbose on purpose

/usr/local/bin/rsync -av --relative --delete /usr/home/ $BACKUPDIR --exclude-from=/tmp/exclude.$$

if [ $? -ne 0 ]; then
    logger -s -p user.err -t backup "rsync failed. Do not trust backup ($BACKUPDIR)"
    /sbin/umount /backup
    exit 1
fi

echo "Backup complete! Deleting oldest backup (14 days ago)"

if [ -d $OLDDIR ]; then
    rm -rf $OLDDIR
fi

/sbin/umount /backup
/bin/rm -f /tmp/exclude.$$

logger -s -p user.notice -t backup "Backup complete at $BACKUPDIR."</pre>