Installing Cognifty

Now that we have a repeatable build process for our Web server stack, we need to turn it into a Web application stack by adding Cognifty to the mix.

Since we are going to be building an embedded virtual host control panel, we won’t need all the CMS stuff that comes with Cognifty. Therefore, our build process will rip all of the default modules out before installing. The problem this creates is that we no longer have an “install” module for Cognifty to make our initial database and setup our admin user.

Don’t fret, I’ve created a standalone module specifically for installing into this environment and for using a SQLite database.

niftyserver_modules.tar.gz

Place this into your “src/modules” folder so that you have “src/modules/install”. Don't worry about the "main" module right now. We'll go over that in the next step.

Installing Cognifty will be the most complex part of our build script up until now. We have to patch the core ini file to use a the pdo-sqlite driver for installation, plus we need to rewrite the nanoweb configuration files to reset the document root to our new Cognifty installation. To do this last step, I’ve written a custom shell script to call sed and replace the DocumentRoot line in nanoweb.conf. (Are you starting to see why we’ve gone through so much trouble to make this all repeatable with ant?)

<!-- cognifty r14 -->
<property name="cognifty-version" value="0014" />
<property name="cognifty-package" value="cognifty-0014.tar.gz" />

<target name="extract-cognifty"
    description="Extract the cognifty tar into the build directory">
    <!-- creates build/nanoweb_2.2.9 -->
    <untar src="${libs}/${cognifty-package}" dest="${build}/" overwrite="false" compression="gzip"/>
</target>

<target name="patch-cognifty"  depends="extract-cognifty"
    description="Change the default core.ini to work with ../../src/modules">

    <copy file="patches/02_cognifty_run-root_core.ini" tofile="build/cognifty-${cognifty-version}/boot/core.ini"/>
</target>

<target name="install-cognifty"  depends="patch-cognifty"
    description="Install cognifty into the run-root directory">
    <copy todir="${run-root}/niftyserver/" includeEmptyDirs="true">
      <fileset dir="build/cognifty-${cognifty-version}/" casesensitive="yes">
          <include name="**"/>
          <exclude name="cognifty/modules/**"/>
          <exclude name="cognifty/admin/**"/>
      </fileset>
    </copy>
    <!-- rewrite nanoweb's config file to use run-root/niftyserver as DocumentRoot -->
    <exec dir="${user.dir}" executable="sh">
      <arg value="./scripts/swap-documentroot.sh"/>
      <arg value="run-root/nanoweb/etc/nanoweb/nanoweb.conf"/>
      <arg value="${user.dir}/run-root/niftyserver"/>
    </exec>

I’m not going to explain each individual portion, this segment of XML follows the other examples closely. You can simply run the “install-cognifty” target with ant just as in the previous examples. The extra configuration files can be downloaded here:

swap-documentroot.sh 02_cognifty_run-root_core.ini

The 02_cognifty_run-root_core.ini goes into the "patches" folder, while the swap-documentroot.sh file goes into the "scripts" folder.

Now everything should be setup for Cognifty to read its modules from the “src/modules” directory. Start nanoweb with the commands:

$> cd run-root/nanoweb/
$> ./usr/sbin/nanoctl start

Point your browser to http://localhost:8443/ you should see the Cognifty installation screen.