Monthly Archives: November 2014

inotify – A lazy man´s git system

Sharing my inotify script that takes care of backing up puppet configuration when changes are done. Works well if you don´t know how or have the need or diciplin to use git. Can of course be used for something other than puppet configs 😉

Search for other versions of a file with something like:

find /etc/puppet-backups -wholename "*/etc/puppet/modules/banner/templates/motd.erb"

With the found matches you can also do a “diff” and compare the different versions.

Also suggest creating the directory /etc/puppet-backups/thisyear/thismonth/today/initial/etc/puppet and copying your modules and environments directory there, this way you will have a base backup and a base to use when diffing.

# inotifywait: Start/Stop inotifywait
# chkconfig: - 80 20
# description: inotifywait waits for changes to files using inotify.
# processname: inotifywait
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
start() {
   echo -n $"Starting inotifywait: "
   (while true; do
    # For some reason, VIM creates a file called 4913 which messes things up for inotify
    dirfile=$(inotifywait -r -e create,modify --exclude '(.*\.sw[pox].*|4913)' --format '%w %f' /etc/puppet/modules /etc/puppet/environments)
    dir=$(echo $dirfile | awk '{ print $1 }')
    file=$(echo $dirfile | awk '{ print $2 }')
    year=$(date +%Y)
    month=$(date +%m)
    day=$(date +%d)
    time=$(date +%H%M%S)
    mkdir -p $backupbase
    mkdir -p $backupdir
    echo "${year}-${month}-${day} ${time} - Backing up new file version of file ${dir}${file} to directory $backupdir" >>$LOGFILE
    cp ${dir}${file} ${backupdir}/ 1>>$LOGFILE 2>&1
   done) &
   [ $RETVAL -eq 0 ] && touch $LOCK
   return $RETVAL
stop() {
   echo -n $"Stopping inotifywait: "
   killproc inotifywait
   [ $RETVAL -eq 0 ] && rm -f $LOCK
   return $RETVAL
case "$1" in
      status inotifywait
      echo $"Usage: $0 {start|stop|status|restart}"
      exit 1
exit $?

rar2fs on FreeNAS 9.2 embeded

This is a quick guide on how I configured rar2fs on my FreeNAS- and shared a rar2fs directory using Samba. My disk is mounted on /mnt/vol1.
Did some tests on my “a few years old hardware” and I got average file transfer speeds around 50 MB/s using cifs.



I found that fusefs-kmod and fusefs-libs packages comes with the FreeNAS embeded install – nice. The module is however not loaded by default.

This can be verified with this command:
>kldstat | grep fuse
27 1 0xffffffff81aaa000 aa63 fuse.ko
That row will not be returned by default.

Load the module with command “kldload fuse.ko”.

To be able to add the rar2fs binary to /usr/local/bin/ and the unrar library to /usr/local/lib/  you need to use unionfs.
First create a directory on your data disk which you can use to mount to /usr/local
>mkdir -p /mnt/vol1/opt/usr_local
Now mount the drive with command:
>mount_unionfs /mnt/vol1/opt/usr_local /usr/local

Note: If you also like to install ports using pkg_add , you also need create directory /mnt/vol1/opt/var and do a mount_unionfs /mnt/vol1/opt/var /var .

Now create a directory somewhere to put the source for unrar, fuse and rar2fs.
>mkdir -p /mnt/vol1/opt/build

Download the needed files.
>cd /mnt/vol1/opt/build
See: (In my case 2.9.3)
See: (in my case 1.20.0)

Extract fuse.
>tar zxvf fuse-2.9.3.tar.gz

Compile libunrar.
>tar zxvf unrarsrc-5.2.1.tar.gz ; cd unrar
For some reason I needed to edit the makefile and make the below changes, otherwise I got some errors, not sure if it is due to differences between linux and freebsd. (Using gmake may also work but its not included in freenas embeded)

Change row 98:

Comment out these 2 rows around row number 134.

Compile and copy the unrar library.
>make lib -f makefile
If I remember correctly, I got some make error regarding missing lgcc , I solved it by creating a temporary mount like “mount_unionfs /mnt/vol1/opt/usr/lib /usr/lib” and then a “ln -s /usr/lib/ /lib/libgcc-something”. Only needed when building libunrar.

>cp /usr/local/lib/

Now you can compile rar2fs.
>tar zxvf rar2fs-1.20.0.tar.gz ; cd rar2fs
> ./configure –with-fuse=/mnt/vol1/opt/build/fuse-2.9.3/include –with-fuse-lib=/usr/local/lib –with-unrar=/mnt/vol1/opt/build/unrar –with-unrar-lib=/usr/local/lib


>cp rar2fs /usr/local/bin/

Try if its working (don´t forget to do a kldload fuse.ko first):

>/usr/local/bin/rar2fs /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_myrars
rar2fs[90982]: mounted /mnt/vol1/rar2fs_myrars

If its not working, you can add “-o debug” to run it in debug mode.

If it is working, unmount your rarfs with “umount /mnt/vol1/rar2fs_myrars”.

Now create a startup script to run at freenas start. I added it to /mnt/vol1/opt/ , dont forget to chmod 755
I´ve added seek-length=1 option to rar2fs for performance reasons.
The allow_other option is needed for non-root access to the file system. If you want to browse it with samba, you need this option.

echo "Loading module fuse.ko ..."
/sbin/kldload fuse.ko
echo "Mounting unionfs filesystem /mnt/vol1/opt/usr_local => /usr/local ..."
/sbin/mount_unionfs /mnt/vol1/opt/usr_local /usr/local
# Uncomment below if you want this as well.
#echo "Mounting unionfs filesystem /mnt/vol1/opt/var => /var ..."
#/sbin/mount_unionfs /mnt/vol1/opt/var /var
echo "Starting rar2fs ..."
/usr/local/bin/rar2fs --seek-length=1 -o allow_other /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_myrars

Create a init script in FreeNAS. Go to System / Add Init/Shutdown scripts.

Type: Script
Path: /mnt/vol1/opt/
Pre init

Reboot your freenas box.
You can check the console output and you should see the script output like “Starting rar2fs …” etc. (Make note of any error messages)
If your rar2fs mounts well, share it using CIFS if you like.
Note: Sharing using NFS is not working according to some forum threads, something about NFS interacts with the filesystem differently.
You can also add the rar2fs filesystem as storage to a freenas jail, like Plex 🙂

UPDATE: Someone told me that gcc isnt a part of FreeNAS 9.3 , I haven´t confirmed it myself though. Its possible to just add a compiled rar2fs executable and unrar library to a 9.3 install so I made it available in the tar archive below.
If you use these you could get by with just copying rar2fs/unrar-lib to your data disk and perhaps setting LD_LIBRARY_PATH to the correct directory before running rar2fs.

THE QUICK WAY (verified it myself on a clean 9.2 and 9.3 installation):
mkdir /mnt/vol1/opt
# Download the file below
tar xvf rar2fs-freenas9-x86_64.tar
setenv LD_LIBRARY_PATH /mnt/vol1/opt ; /sbin/kldload fuse.ko ; /mnt/vol1/opt/rar2fs –seek-length=1 -o allow_other /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_mountpoint


Merlin Bigscreen – OP5 Monitor Unhandled Problems on big screen TV

A fork of Morten Bekkelunds nagios-dashboard based on the OP5 Monitor API.
There is also another fork that uses livestatus that you may want to check out as well:

Note that in my fork, the html/css and fonts/colors may have changed a lot from the original due to lots of non developers playing around 🙂



Installation instructions:

  • Extract the tar ball in the /var/www/html directory of your OP5 Monitor server.
  • You can put the files on the another server as well as long as it can reach the op5 monitor server using https – if you do, don´t forget to update the op5server variable at the top of the config.php file.
  • Make sure your user has API access permission.
  • Go to yourserver/bigscreen in your browser.
  • If you use Active Directory authentication you need to edit the login.php file and update the authtype select box and add your domain there.

The following filtering options are available for passing using the querystring by adding it to end of the url in your web browser, example: http://yourserver/bigscreen/?warnings=false&unknowns=false&nosla=false
The “nosla” option is used to filter out hosts or services which have a custom variable “_SLA” set to the value “none”.
You may also use autologin as a start page in a web browser by using url: http://yourserver/bigscreen/login.php?redir=index.php&autologin=true&username=youruser&password=yourpassword

You can get the files on github:
Or below.