Posted on Leave a comment

Setting up MongoDB on Debian Wheezy 64Bit

MongoDB Logo

Here are the steps required for setting up MongoDB on Debian Wheezy. This is the manual guide since the official MongoDB packages provided by Debian are a little dusty. Don’t worry, the setup process is pretty straight forward. Let’s get started!

Import public key for package management tool apk

First you need to import the public key for your package management tool. In this case apk:

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.YX8vkOfNgq --trustdb-name /etc/apt//trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d//debian-archive-wheezy-stable.gpg --keyserver keyserver.ubuntu.com --recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Add MongoDB to package list

echo “deb http://repo.mongodb.org/apt/debian “$(lsb_release -sc)“/mongodb-org/3.0 main” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Note that this command requires lsb_release.  In case you haven’t installed it do so by issuing the following command:

sudo apt-get install lsb_release

Refresh local package list

In order to check for your new package entry reload your local package list:

apt-get update

...
Get:1 http://repo.mongodb.org wheezy/mongodb-org/3.0 Release.gpg [490 B]
Hit https://repo.varnish-cache.org wheezy/varnish-4.0 amd64 Packages
Get:2 http://repo.mongodb.org wheezy/mongodb-org/3.0 Release [2,017 B]
Get:3 http://repo.mongodb.org wheezy/mongodb-org/3.0/main amd64 Packages [4,113 B]
Fetched 6,620 B in 1s (3,471 B/s)
Reading package lists... Done

Install MongoDB

Now it’s time to actually install MongoDB – hurray! We are going to install the latest stable release. In case you want to install a specific release version simply specify the release number.

Install latest stable MongoDB

sudo apt-get install -y mongodb-org

Install specific MongoDB version

Replace VERSION-XYZ with your desired MongoDB version, e.g. 3.0.4-rc0:

sudo apt-get install -y mongodb-org=VERSION-XYZ mongodb-org-server=VERSION-XYZ mongodb-org-shell=VERSION-XYZ mongodb-org-mongos=VERSION-XYZ mongodb-org-tools=VERSION-XYZ

Check installation messages

Watch for the following installation messages to ensure that MongoDB was setup corectly:

Setting up mongodb-org-shell (3.0.3) ...
Setting up mongodb-org-server (3.0.3) ...
Adding system user `mongodb' (UID 111) ...
Adding new user `mongodb' (UID 111) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 113) ...
Done.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
[ ok ] Starting database: mongod.
Setting up mongodb-org-mongos (3.0.3) ...
Setting up mongodb-org-tools (3.0.3) ...
Setting up mongodb-org (3.0.3) ...

That’s it for the installation – Congratulations! By default, MongoDB listens on port 27017 for incoming requests. Please refer to /etc/mongod.conf for changing it, see section Configure MongoDB below

Run MongoDB

Once you’ve installed MongoDB here are the commands to control MongoDB.

Start MongoDB

sudo service mongod start

Verify status MongoDB

In order to verify the status of MongoDB have a look at log file located at

/var/log/mongodb/mongod.log

and watch out for the line

2015-06-14T10:21:05.027+0200 I NETWORK [initandlisten] waiting for connections on port 27017

Stop MongoDB

Like starting MongoDB use the service facilities to stop MongoDB:

sudo service mongod stop

Configure MongoDB

MongoDB can be configured using /etc/mongod.conf The file is pretty self-explanatory for the basic settings. Please refer to the Getting Started Guides for more information. Enjoy!

Posted on Leave a comment

JIRA WAR Setup NoClassDefFoundError TransactionUtil Exception

Jira Logo

When receiving a NoClassDefFoundError TransactionUtil exception when setting up JIRA using WAR make sure that all required libraries are installed.

java.lang.NoClassDefFoundError: org/ofbiz/core/entity/TransactionUtil
	com.atlassian.jira.web.filters.steps.requestcleanup.RequestCleanupStep.finallyAfterDoFilter(RequestCleanupStep.java:63)
	com.atlassian.jira.web.filters.steps.ChainedFilterStepRunner.doFilter(ChainedFilterStepRunner.java:85)
	com.atlassian.core.filters.cache.AbstractCachingFilter.doFilter(AbstractCachingFilter.java:33)
	com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	com.atlassian.core.filters.encoding.AbstractEncodingFilter.doFilter(AbstractEncodingFilter.java:41)
	com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	com.atlassian.jira.web.filters.PathMatchingEncodingFilter.doFilter(PathMatchingEncodingFilter.java:49)
	com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	com.atlassian.jira.startup.JiraStartupChecklistFilter.doFilter(JiraStartupChecklistFilter.java:74)
	com.atlassian.multitenant.servlet.MultiTenantServletFilter.doFilter(MultiTenantServletFilter.java:91)
	com.atlassian.jira.web.filters.steps.ChainedFilterStepRunner.doFilter(ChainedFilterStepRunner.java:78)
Posted on 3 Comments

Setup Varnish Cache Server for Magento 1.9 CE on Mac OSX

Magento Logo

When dealing with high traffic Magento installations you definitely want to implement caching mechanisms to ensure proper response times for your visitors. Apart from internal caching and indexing functionality provided by Magento there exist a couple of (external) extensions that help you speed of content delivery by e.g. caching entire pages, such as PageCache for Varnish.

Simply put, Varnish represents a reverse-proxy cache that serves as entry-point into you Magento installation and returns cached content rather than requesting Magento to re-build entire pages.

The following steps show you can setup Varnish cache server for Magento 1.9 CE on Mac OSX.

First off, make sure you have Homebrew installed and configured properly. Based on Homebrew we can easily setup Varnish by issuing the following command:

bash-3.2$ brew install varnish
==> Installing varnish dependency: pkg-config
==> Downloading http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
######################################################################## 100,0%
==> ./configure --prefix=/usr/local/Cellar/pkg-config/0.28 --disable-host-tool --with-internal-glib --with-pc-path=/usr/local/lib/p
==> make
==> make check
==> make install
  /usr/local/Cellar/pkg-config/0.28: 10 files, 600K, built in 97 seconds
==> Installing varnish dependency: pcre
==> Downloading ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.bz2
######################################################################## 100,0%
==> ./configure --prefix=/usr/local/Cellar/pcre/8.33 --enable-utf8 --enable-unicode-properties --enable-pcregrep-libz --enable-pcregrep-libbz2 --
==> make
==> make test
==> make install
   /usr/local/Cellar/pcre/8.33: 140 files, 4,1M, built in 49 seconds
==> Installing varnish
==> Downloading http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz
######################################################################## 100,0%
==> ./configure --prefix=/usr/local/Cellar/varnish/3.0.3 --localstatedir=/usr/local/var
==> make install
==> Caveats
To have launchd start varnish at login:
    ln -sfv /usr/local/opt/varnish/*.plist ~/Library/LaunchAgents
Then to load varnish now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.varnish.plist
Warning: /usr/local/sbin is not in your PATH
You can amend this by altering your ~/.bashrc file
==> Summary
 /usr/local/Cellar/varnish/3.0.3: 51 files, 1,8M, built in 43 seconds

As shown in Brew’s output you can start Varnish by issuing the following command:

==> Caveats
To have launchd start varnish at login:
    ln -sfv /usr/local/opt/varnish/*.plist ~/Library/LaunchAgents
Then to load varnish now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.varnish.plist

In case the following error occurs:

bash-3.2$ sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.varnish.plist"
launchctl: Couldn't" stat("~/Library/LaunchAgents/homebrew.mxcl.varnish.plist"): No such file or directory nothing found to load

try a re-install first (and additionally do a brew-update/updgrade):

bash-3.2$ sudo brew uninstall varnish
Uninstalling /usr/local/Cellar/varnish/3.0.3...

After a brew update/upgrade Varnish 4.0.0 is now being installed:

bash-3.2$ sudo brew install varnish
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/varnish-4.0.0.mavericks.bottle.tar.gz
######################################################################## 100,0%
==> Pouring varnish-4.0.0.mavericks.bottle.tar.gz
==> Caveats
To have launchd start varnish at login:
    ln -sfv /usr/local/opt/varnish/*.plist ~/Library/LaunchAgents
Then to load varnish now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.varnish.plist
==> Summary
 /usr/local/Cellar/varnish/4.0.0: 93 files, 1,9M

Unfortunately, this does not fix the missing plist file problem every time.

Nevertheless, you can easily create the plist file yourself, as mentioned here https://github.com/Homebrew/homebrew/issues/15922:

Simply copy the contents for the plist file by calling brew cat varnish:

bash-3.2$ sudo brew cat varnish
require 'formula'

class Varnish < Formula
  homepage 'http://www.varnish-cache.org/'
  url 'https://repo.varnish-cache.org/source/varnish-4.0.0.tar.gz'
  sha1 '6ad4fcf42a505a748ae993cb6ed579159e023633'

  bottle do
    sha1 "190bba2cf0e521b489cbd64cc698ba769b18cccd" => :mavericks
    sha1 "fd12d468c2328179bd402f1592b65ef69d6f1baa" => :mountain_lion
    sha1 "0e9717e705541a34906947eb7e49ab800204e2ff" => :lion
  end

  depends_on 'pkg-config' => :build
  depends_on 'pcre'

  resource "docutils" do
    url "https://pypi.python.org/packages/source/d/docutils/docutils-0.11.tar.gz"
    sha1 "3894ebcbcbf8aa54ce7c3d2c8f05460544912d67"
  end

  def install
    ENV.prepend_create_path "PYTHONPATH", buildpath+"lib/python2.7/site-packages"
    resource("docutils").stage do
      system "python", "setup.py", "install", "--prefix=#{buildpath}"
    end

    system "./configure", "--disable-dependency-tracking",
                          "--prefix=#{prefix}",
                          "--localstatedir=#{var}",
                          "--with-rst2man=#{buildpath}/bin/rst2man.py",
                          "--with-rst2html=#{buildpath}/bin/rst2html.py"
    system "make install"
    (var+'varnish').mkpath
  end

  test do
    system "#{opt_sbin}/varnishd", "-V"
  end

  def plist; <<-EOS.undent
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
        <key>Label</key>
        <string>#{plist_name}</string>
        <key>ProgramArguments</key>
        <array>
          <string>#{opt_sbin}/varnishd</string>
          <string>-n</string>
          <string>#{var}/varnish</string>
          <string>-f</string>
          <string>#{etc}/varnish/default.vcl</string>
          <string>-s</string>
          <string>malloc,1G</string>
          <string>-T</string>
          <string>127.0.0.1:2000</string>
          <string>-a</string>
          <string>0.0.0.0:80</string>
        </array>
        <key>KeepAlive</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>#{HOMEBREW_PREFIX}</string>
        <key>StandardErrorPath</key>
        <string>#{var}/varnish/varnish.log</string>
        <key>StandardOutPath</key>
        <string>#{var}/varnish/varnish.log</string>
      </dict>
      </plist>
    EOS
  end
end

The plist content in this case is:

<?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
        <key>Label</key>
        <string>#{plist_name}</string>
        <key>ProgramArguments</key>
        <array>
          <string>#{opt_sbin}/varnishd</string>
          <string>-n</string>
          <string>#{var}/varnish</string>
          <string>-f</string>
          <string>#{etc}/varnish/default.vcl</string>
          <string>-s</string>
          <string>malloc,1G</string>
          <string>-T</string>
          <string>127.0.0.1:2000</string>
          <string>-a</string>
          <string>0.0.0.0:80</string>
        </array>
        <key>KeepAlive</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>#{HOMEBREW_PREFIX}</string>
        <key>StandardErrorPath</key>
        <string>#{var}/varnish/varnish.log</string>
        <key>StandardOutPath</key>
        <string>#{var}/varnish/varnish.log</string>
      </dict>
      </plist>

Now starting Varnish via launchctl succeeds:

bash-3.2$ sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.varnish.plist

Time to test the service

Open a browser and navigate to 127.0.0.1:8080 (which is the port Varnish is listening to set by the configuration in the plist file from above) and check out the headers:

Accept-Ranges	bytes, bytes
Age	0
Connection	keep-alive
Content-Language	de
Content-Length	1087
Content-Type	text/html; charset=utf-8
Date	Fri, 30 May 2014 07:31:12 GMT
Server	Apache/2.4.4 (Unix) PHP/5.4.7 OpenSSL/1.0.1e
Vary	accept-language,accept-charset
Via	1.1 varnish
X-Varnish	1661470811

Congratulations, as you can see Varnish is working properly!

The next step is to configure Apache to listen to port 8080 (or any other port apart from 80) and Varnish on port 80.

That’s it 🙂

Posted on 2 Comments

Setting Custom Portlet Titles in Liferay

Liferay Logo

Setting custom portlet titles in Liferay can be a little tricky. Changing the title via the portlet configuration in the frontend is easy but when it comes to reading the custom title property programmatically things seem to get a little messy.

Setting the Title

So, first of set your portlet title as usual via the portlet configuration in the frontend. That’s the easy part.

Determining Portle Title Programmatically

Then, in order to determine custom portlet titles use the following code:

ThemeDisplay themeDisplay = ((ThemeDisplay) request
  .getAttribute(WebKeys.THEME_DISPLAY));
String portletId = themeDisplay.getPortletDisplay().getId();
javax.portlet.PortletPreferences portletSetup = PortletPreferencesFactoryUtil
  .getLayoutPortletSetup(themeDisplay.getLayout(), portletId);
String portletCustomTitle = themeDisplay.getPortletDisplay()
  .getTitle();
portletCustomTitle = portletSetup.getValue("portletSetupTitle_"
  + themeDisplay.getLanguageId(), portletCustomTitle);

This code will determine the current portlet’s ID, get its preferences, determine the current namespace and finally retrieve the custom portlet title.

In case you need to read other custom portlet properties simply look up their keys in the database and use the portletSetup.getValue(“yourKey_”, …) option as shown previously.

Posted on 4 Comments

Setting up ClamAV for Kerio Connect

Kerio Connect Logo

ClamAV represents a viable alternative to commercial antivirus solutions on the market. Fortunately, Kerio Connect (formerly Kerio Mailserver) offers support for ClamAV out-of-the-box. Nevertheless, it takes some steps in order to manage a working setup that will automatically update the virus database and carry out scheduled checks aside from simply checking emails. The following approach has proven to work on Windows 2003 and Windows 2008 servers using ClamWin/ClamAV 0.97 and up. If you run into problems please report them.

Basically, there are 2 versions of the Clam antivirus suite: ClamAV and ClamWin. Whereas ClamWin is aimed at desktop users that require a GUI and does not include the daemon clamd, ClamAV is the command line version that indeed includes the daemon which is required to setup Kerio Connect to be used together with the Clam suite.

UPDATE: Special thanks go to Bob H. at MIS Specialists for pointing out that Kerio is dropping support for all AV solutions except Sophos beginning with version 8. According to their blog Kerio “they are trying to make our life easier by providing an open source reference implementation, based on their current ClamAV plug-in”. I will try to have a look at this issue and post back with news.

Setup

Since we want to use the functionality provided by ClamWin (scheduled updates and scans, graphical configuration tools) we first need to set it up.

  1. Download and setup ClamWin

Be sure to use C:ClamAV as your destination path, since we do not want to have spaces in the path which would cause potential problems later when setting up the clamd daemon. Configure ClamWin as usual but additionally create a tmp and a db directory and set the update path to the db directory: Afterwards, run another definitions update to make sure the settings are correct and the files are being saved into the newly created db folder. That’s all there is to set up ClamWin. Unfortunately, ClamWin does not include the daemon required for Kerio Connect to do the checks. So, let’s install and configure ClamAV.

  1. Download and setup ClamAV

Extract the downloaded archive to C:ClamAV (the folder you installed ClamWin in the first step). Doing so will add some folder and files, such as clamd.exe, the daemon we need in our setup. The next step is to configure the daemon using a text file called clamd.conf:

  1. Create C:ClamAVclamd.conf using the following content:
PidFile C:ClamAVclamd.pid
LogFile C:ClamAVclamd.log
DatabaseDirectory C:ClamAVdb
TemporaryDirectory C:ClamAVtmp
TCPSocket 3310
TCPAddr 127.0.0.1
DetectPUA yes
DetectBrokenExecutables yes
HeuristicScanPrecedence yes
ArchiveBlockEncrypted yes
StreamMaxLength 30M

Thanks to Martijn for these settings. Of course there are a lot more options to set but these settings work and should suffice for a first setup. Now that we have all the settings required by the daemon let’s test it by starting it from the command line: If you don’t see any error messages here we are ready to move on to the setup of the daemon as a Windows service. Otherwise re-check the steps above, especially if you extracted ClamAV in the correct destination path and that clamd.conf has been saved in this directory too.

  1. Add clamd.exe as a Windows service

There are a lot of ways to add services under Windows, such as using sc.exe, cygwin or instsrv.exe included in the Windows Resource Kit. Basically, what we need to do is to add clamd.exe as a service and specify certain startup parameters for it to work, i.e. which config file (clamd.conf) to use. Thus, let’s add the service. My personal favorite when dealing with Windows services is sc.exe:

sc create clamd binpath= c:clamavclamd.exe type= own start= auto

This will as a service called clamd that will start clamd.exe. Note that you can easily delete services again using sc.exe in case something went wrong on the first attempt:

sc delete clamd

As previously mentioned, the clamd service must be configured to use clamd.conf as its configuration file. To do so open the service management console using services.msc and specify “-c c:clamAVclamd.conf” as startup parameter in the General tab. Note that you must stop the service first to edit the startup parameters in the management console. Once this is done be sure to test the service by starting and stopping it, using net start clamd and net stop clamd.

  1. Set ClamAV as antivirus scanner in Kerio Connect

Finally, once ClamWin, ClamAV and the daemon have been setup correctly it is time to configure Kerio Connect to use ClamAV as its antivirus suite. To do so open up Kerio’s administration interface and navigate to the Antivirus tab: In the ClamAV settings tab leave the default values: Be sure to check and save the settings using “Apply“. If the setup does not work Kerio Connect will complain immediately. In this case re-check your settings, especially if clamd is running as a service (e.g. netstat -a | findstr 3310). If the service does not start or keeps stopping for some reason try to add the service using instsrv.exe and srvany.exe from the Windows Resource Kit. Also make sure that the service is started with the “-c c:clamavclamd.conf” startup parameter. Finally, restart the machine just to make sure the service starts correctly when booting up. If everything went smoothly you now have an open source AV scanner configured using Kerio Connect.