I recently built a new file server and I based it on the well renowned FreeNAS by iXsystems. It’s been pretty solid over the past few weeks but today I ran into an issue. The web ui stopped responding. Actually it turned out that the django service had stopped. Well, that was the perfect opportunity to use CFEngine to make sure I never have the issue again.
wget http://www.cfengineers.net/files/packages/cfengine-community/3.7.0/cfengine-community-3.7.0_1-freebsd_9.x_amd64.tbz pkg_add cfengine-community-3.7.0_1-freebsd_9.x_amd64.tbz
I just wanted to experiment locally instead of bootstrapping to a policy server so I grabbed the masterfiles source tarball for 3.7.0 and installed the masterfiles policy framework.
tar zxvf cfengine-masterfiles-3.7.0-2.tar.gz cd cfengine-masterfiles-3.7.0/ ./configure make install
Since I am only going to have local policy for now I went ahead and linked inputs to masterfiles.
rm -rf /var/cfengine/inputs ln -s /var/cfengine/masterfiles /var/cfengine/inputs
And then I enabled cfengine.
cfengine3_enable="YES" >> /etc/rc.conf service cfengine3.sh start
I enabled autorun for convenience.
sed -i 's/.*services_autorun.*expression.*/ "services_autorun" expression => "any";/' /var/cfengine/masterfiles/controls/3.7/def.cf
And then I installed this policy into services/autorun.
wget https://gist.githubusercontent.com/nickanderson/a46fdf764da3370e2bce/raw/a9116f64f8cf6158738a82e136de676325ab0a0e/freenas.cf -O /var/cfengine/masterfiles/services/autorun/freenas.cf
Now any time django decides to die, CFEngine will come along and fix it up.
[root@freenas] ~# service django stop Stopping django. Waiting for PIDS: 17087. [root@freenas] ~# cf-agent -K [root@freenas] ~# service django status django is running as pid 17203. [root@freenas] ~# tail /var/log
Maybe I’ll do some Software Defined Storage :-p