Installing OpenCms with PostgreSQL

This post explains you how to set up OpenCms with PostgreSQL on Ubuntu Linux.

In case you are not aware: PostgreSQL is an enterprise-grade open-source relational database system. IMHO it’s the most powerful and interesting open-source database, and the first choice if you do not need or want to use a commercial product.

I do not focus on installing Tomcat (or any other web container), nor PostgreSQL itself, but mainly on the database-related tasks you need to fulfill during the OpenCms set-up.

Versions used for this tutorial:

  • Ubuntu 12.10 / 64 bit
  • PostgreSQL 9.1.7
  • Java 1.7.0_09
  • Tomcat 6.0.36
  • OpenCms 8.5.0

Adding the setup-user

The OpenCms installer needs a user which can create users and databases. Here is how you can create it:

sudo -u postgres createuser
Enter name of role to add: opencmssetup
Shall the new role be a superuser? (y/n) y

Then we set a password for the newly created user:

sudo -u postgres psql
psql (9.1.7)
Type “help” for help.
postgres=# alter user opencmssetup with encrypted password 'opencmssetup';
ALTER ROLE
postgres=# \q

Important: There is no need to change the password of the postgres Linux-system-user. In Ubuntu (and probably Debian as well) you execute the psql-command as user postgres through sudo.

Deploying the war-file

Next you should start Tomcat, and deploy the opencms.war file into the webapps-folder. After some seconds Tomcat will deploy it and you should see a folder named opencms.

Running the installer

Now you are ready to launch the installer at http://localhost:8080/opencms/setup

After going to the first two basic screens, you will launch the most important screen where you set up the database connection:

opencms-postgresql

Now there are a few important things to note:

  • The user opencmssetup (Setup connection) is used only to create the database, plus the separate user for actually running OpenCms. The user opencmssetup will be deleted after installing.
  • The user opencms (OpenCms Connection) is the separate user which OpenCms uses to connect to its database. It is created by the installer.
  • The “Database Name”. The database is also created by the installer.

The database and the user can be named as you like, of course, as long as they don’t yet exist on the target database server.

When you press Continue, the OpenCms-installer will ask a few more questions about its setup. You can safely leave the defaults.

While the installer does its job, it’s important not to close the browser tab or window it’s running in. It can take quite some time since it “manually” imports the whole content into the OpenCms VFS. On my aging dual-core P8400-based notebook it took almost an hour. Note that I had a default-install of PostgreSQL. Probably it could be sped up by changing the fsync or synchronous_commit parameters.

Removing the setup-user again

Once the installer is done, you can remove the user opencmssetup, since it’s not needed to run OpenCms:

sudo -u postgres dropuser opencmssetup

If you have general questions about setting-up or configuring OpenCms, you can subscribe to the mailing list.

Advertisements

BCEE S-net under Linux with OpenJDK/IcedTea7

In case you are trying to log into S-net from Linux, using OpenJDK, you are probably running into permission issues.

In my case they could be solved by creating ~/.java.policy with the following content:

grant codeBase "https://bcee.snet.lu/ssogate/*" {
	permission java.lang.RuntimePermission "setIO", "read,write";
};

grant codeBase "https://bcee.snet.lu/ssogate/*" {
	permission java.util.PropertyPermission "lu.luxtrust.logging.conf.custom", "read";
};

grant codeBase "https://bcee.snet.lu/ssogate/*" {
	permission java.net.SocketPermission "ssforwarder.luxtrust.lu:443", "connect,resolve";
};

What are you doing anyway the whole day staring at your screen?

Here is a handy script which logs the current timestamp and the title of the currently focused window in an SQLite3 database.

It does not insert a row if the current window title is the same than on the previous run.

You can run it by cron every minute, and will help you to find out where you spent most time 🙂

#!/bin/bash

# sqlite3 ~.windowlog.db
# CREATE TABLE windowlog(moment integer not null primary key, window);
# echo "select * from windowlog order by moment desc;" | sqlite3 ~.windowlog.db

: ${DISPLAY:=:0}
export DISPLAY

WIN_ID=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| cut -d ' ' -f 5`
WIN_NAME=`xwininfo -id $WIN_ID |awk 'BEGIN {FS="\""}/xwininfo: Window id/{print $2}' | sed 's/-[^-]*$//g'`
OLD_WIN_NAME=`echo "select window from windowlog order by moment desc limit 1;" | sqlite3 ~.windowlog.db`

if [ "$WIN_NAME" != "$OLD_WIN_NAME" ]; then
        #echo "$WIN_NAME ----- $OLD_WIN_NAME"
        timestamp=`date +%s`
        #echo `date +%s`,$WIN_NAME >> ~.windowlog
        sqlite3 ~.windowlog.db "insert into windowlog (moment,window) values ('$timestamp','$WIN_NAME');"
fi

Before running it you need to create the database and the table:

$ sqlite3 ~.windowlog.db
sqlite> CREATE TABLE windowlog(moment integer not null primary key, window);

Edit: This code is now living in github, and being greatly improved. Thanks to flazzarini!

Scripting in Java

It can sometimes be useful to externalize some business logic from Java to a scripting environment which allows you to modify the logic at runtime. You can store the script in an external file or in database, and load it on each run. With little effort you can even add a code editor (e.g. using the excellent Editarea) to your application.

Meet javax.script.

A well-known implementation of javax.script. ScriptEngine is Mozilla Rhino.

Java 6 SE comes with Rhino 1.6r2 bundled, so you don’t even need to add any jar to your project.

The nice thing about Rhino is that you can access the full Java API from the JavaScript it executes, and you can inject objects from Java to JavaScript, and the operations you perform on those objects from inside the scripting, are directly reflected into the Java instances of the Object.

Let’s take a look at an example:

Java code

final Session session = HibernateUtil.getSession(); 
session.getTransaction().begin(); 

final Code code = (Code) session.get(Code.class, "1"); 

final ScriptEngineManager manager = new ScriptEngineManager(); 
final ScriptEngine jsEngine = manager.getEngineByName(code.getType());

final Employee employee = new Employee();

jsEngine.put("employee", employee); 

Integer result = (Integer) jsEngine.eval(code.getCode()); 

session.close();

JavaScript code (from code.getCode())

main(); 

function main() { 
    employee.setName("JavaScript is my Name"); 
    employee.setName(employee.getName()+" !!!"); 
    return 1+2+3+4+5; 
}

This illustrates on how to load some JavaScript from a database, and have it executed by the ScriptEngine. The JavaScript can directly call the setter methods on the injected Employee object. The return code from the function main() is stored in the result variable.

By the way, you are not bound to use JavaScript. There are several JSR-223 script implementations, e.g. Groovy, Python, Ruby, Scheme, PHP, …

I think this can be really useful and I will certainly use it in some of my projects in the near future.

Handy one-liner

To keep my OS updated and clean I use the following one-liner:

# sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get clean && sudo apt-get autoremove --purge && sudo apt-get remove `deborphan`

Cyanogenmod on the HTC Desire

Lately I was fed up with the firmware situation of my HTC Desire, which was somehow stuck at Android 2.2.  HTC has merely released a developer-only release of Android 2.3, which has the following disadvantages:

  • Stuck at Android version 2.3.3
  • Has security vulnerabilities
  • Will never see an update any more
  • Crashes sometimes immediately after taking a photo

Now, enter Cyanogenmod. Since its 7.1 release my device was among the officially supported, so I decided to give it a try.

The installation went smooth using the detailed instructions on the Cyanogenmod wiki.

To root the device, the popular unrevoked method did not work since it assumes you have a Froyo-based firmware.

I had the Gingerbread-based one so I had to use Revolutionary. Hint: After rooting your device with Revolutionary, follow the wiki from the section ClockworkMod Recovery process.

After all was up and running, I spent some time finding widgets as substitute for HTC Sense. As it came out I only needed Simple Calendar Widget, the stock Gingerbread-weather widget provided to be good enough.

Eventually I can say that I do not look back, and that I am happy to have prolonged the live of my not so ancient HTC Desire (18 month old), and breathed some fresh air into it’s soul by using Cyanogenmod.

And it is good to know that I will continue receiving updates for some time.

HTC, it was a really nice time with your firmware, but since you decided to provide no more firmware-updates for one of your most successful devices, I chose to defect. And, as said, I do not look back and recommend it to everyone in my situation. Cyanogenmod is truly a nice, polished, fast and beautiful experience.

We have a Samsung Galaxy S at home as well, and it received the Cyanogenmod-love as well, as early as yesterday. On a side note, that has really blown oyxgen into the Galaxy S, especially since the Samsung-RFS-fuckup became history through the flashing.

I think, a must-have criteria for buying devices in the future will be that they are able to run Cyanogenmod.

iPhone Jailbreaking now considered “a right” of the device owner

Arstechnica writes: Apple loses big in DRM ruling: jailbreaks are “fair use”

Really a pity it needed to come that far. Especially since the real issue seems to be that people are fed up with Apple dictating which software they can load on their phone, and which not.

This could have been easily solved another way. The Android way, if you like. All without rooting/jailbreaking. It goes like this:

Add a checkbox “Allow manual software installation” to the phone settings. If you like, even with the usual 20 page long “iAgree song”. Once the user has clicked it, let him/her install any app he/she downloaded, either through iTunes or more easily, by just copying it to the phones storage.

And boy, no you can’t patent that one.

And btw: Nokia has since ever allowed manual software installation. They went opposite way since their Ovi-Store only appeared afterwards. And when installing manually, they also have a checkbox à la “Allow installation of unsigned packages”