19 April 2012

Perforce on a freenas

Lately I installed an old pc with freenas 8.0.2 for backup purposes as well as a centralized depository for our home media, music and pictures.

At both Larian and Newfort we used perforce for source control. I also have worked in the past with svn, cvs, git and plastic scm. My scm of choice remains perforce, I feel most confident with that system.

Perforce is now free for 20 users and 20 work spaces which is a huge improvement over their former 2 users. So for my own projects at home, let's install perforce on the freenas. Mind you, I have almost no experience with linux/unix (I worked with some debian version at the KULeuven) so I made a lot of beginner mistakes.

  1. Make sure to activate the ssh service on the freenas, that way you can use putty to login on the freenas via the network instead having to be connected to the pc. You start in the C-shell, which is important since some commands that are available in csh are not in bash and vice versa. For example, setting environment variables in bash is done with 'export', while in csh it's done with 'setenv'.
  2. I have a disk of 122 GB where I created a ZFS volume on called p4disk.
  3. Then I setup the folders, get the p4 and p4d binaries and make them executable
    cd /mnt/p4disk/
    mkdir bin
    mkdir p4root
    cd bin
    wget http://www.perforce.com/downloads/perforce/r11.1/bin.freebsd70x86/p4d
    wget http://www.perforce.com/downloads/perforce/r11.1/bin.freebsd70x86/p4
    chmod +x p4 p4d
  4. On another drive I created a folder to store the journal. Since you need this to restore the server it should not be on the same drive as the server.
    cd /mnt/TERRA01
    mkdir p4
  5. Then we need to make sure the server is run when the freenas boots. It seems like there are a million ways to accomplish that (I hate that) and this is how I did it. If there is a better way please tell me :)
    mount -uw /
    cd /conf/base/etc/rc.d/
    nano perforce
    The first command is needed to make the drive writable, and then we need to add our service in the rc.d folder. But not in the /etc/rc.d/ folder since that one is always reset after a reboot. 'nano perforce' opens the nano editor to write our service script.
  6. Paste this:
    #!/bin/sh -e
    export P4ROOT=/mnt/p4disk/p4root
    export P4PORT=1666
    p4d -J /mnt/TERRA01/p4/journal &
  7. Save the file and continue:
    chmod +x perforce
    cd /conf/base/etc/
    nano rc.conf
  8. Go to the last line and add:
  9. Reboot and done!

If I read these steps again it seems simple enough. I had some weird issues though, all because I'm not that Linux-savvy. A difficult one was that my server was very slow. If I called 'p4 info' on my PC, it took 5 seconds to get a reply. After much googling I found out this was due to a reverse dns look up on the server that failed. Some perforce calls, 'p4 info' among others, perform a reverse dns look up and that slowed it down.

The solution offered by perforce was to include all clients in the hosts file, which is not much of a solution if you ask me. I eventually found out that the server, and all my PC's in the house too, received three ip-addresses of dns-servers from the router: the router itself and two from my ISP. However my router is not a dns server, so all reverse dns calls on my router failed, causing the delay. A firmware update for the router is not available, so unfortunately I had to set the dns ip's from my ISP by hand on the freenas. From then on, perforce ran smooth. Gonna buy myself a new router I think.

With the steps I describe the perforce server is run by the root user. Some other how-to's, like for example installing svn on a freenas, say I should've created a perforce group and user and let that user run the server. I didn't bother and have no idea whether or not that's a good thing. If not, tell me why :). The main reason why I skipped it was because the 'sudo' command wasn't available on the freenas and I could not find how to install it.

Now that all runs fine, I can start experimenting with everything I read in my Effective C# book. I was afraid that the book wouldn't be as good as I hoped, but it turns out to live up to expectations. I'll post something about what I've read later.

1 comment:

Styn said...

Wow! I was actually looking for this recently!
Now all I need is a guide te set up cruise control on a freenas :)