The final step in the installation of CouchDB is to integrate it into Solaris’ Service Management Facility (smf).

First we will create a user couchdb who is used to run the database. Furthermore we have to modify some user-permissions of the CouchDB folders.

root@test:~# mkdir -p /export/home
root@test:~# useradd -d /export/home/couchdb -s /usr/bin/false -m couchdb
root@test:~# groupadd couchdb
root@test:~# usermod -g couchdb couchdb
root@test:~# chown -R couchdb:couchdb /opt/local/var/run/couchdb
root@test:~# chown -R couchdb:couchdb /opt/local/var/log/couchdb
root@test:~# chown -R couchdb:couchdb /opt/local/var/lib/couchdb

Now we can add CouchDB to the SMF, which requires a XML config file with the description of the CouchDB service.
The required file can be found here:
couchdb-smf.xml

root@test:~# wget http://www.dev-eth0.de/wp-content/uploads/2011/07/couchdb-smf.xml
--2011-07-31 18:21:09--  http://www.dev-eth0.de/wp-content/uploads/2011/07/couchdb-smf.xml
Connecting to www.dev-eth0.de|87.238.193.118|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1913 (1.9K) [application/xml]
Saving to: `couchdb-smf.xml'

100%[======================================================================>] 1,913       --.-K/s   in 0s

2011-07-31 18:21:09 (87.6 MB/s) - `couchdb-smf.xml' saved [1913/1913]

root@test:~# svccfg import -V couchdb-smf.xml

Now we have installed CouchDB as a Solaris Service and can start and stop it with the svcadm command and check it’s status with svcs.

Commands:

svcadm enable couchdb
svcadm disable couchdb

The following commands will start CouchDB and check if everything is ok and running.

root@test:~# svcadm enable couchdb
root@test:~# svcs -x couchdb
svc:/application/database/couchdb:couchdb (Apache CouchDB)
 State: online since Sun Jul 31 18:24:48 2011
   See: http://couchdb.apache.org/
   See: /var/svc/log/application-database-couchdb:couchdb.log
Impact: None.

Now it’s time to test if we can connect to our CouchDB:

root@test:~# curl http://localhost:5984
{"couchdb":"Welcome","version":"1.1.0"}

You can find all logs of CouchDB in /opt/local/var/log/couchdb.

After the installation of the required software (Erlang, ICU and Spidermonkey) we can finally install CouchDB which is the easiest part of the whole story…

Basics

root@test:~# cd /tmp
root@test:/tmp# wget http://apache.linux-mirror.org//couchdb/1.1.0/apache-couchdb-1.1.0.tar.gz
--2011-07-31 16:47:07--  http://apache.linux-mirror.org//couchdb/1.1.0/apache-couchdb-1.1.0.tar.gz
Connecting to apache.linux-mirror.org|80.237.211.23|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1088226 (1.0M) [application/x-gzip]
Saving to: `apache-couchdb-1.1.0.tar.gz'

100%[=========================================================================>] 1,088,226    652K/s   in 1.6s

2011-07-31 16:47:09 (652 KB/s) - `apache-couchdb-1.1.0.tar.gz' saved [1088226/1088226]

root@test:/tmp# tar xvf apache-couchdb-1.1.0.tar.gz
Decompressing 'apache-couchdb-1.1.0.tar.gz' with '/usr/bin/gzcat'...
x apache-couchdb-1.1.0, 0 bytes, 0 tape blocks
x apache-couchdb-1.1.0/README, 2748 bytes, 6 tape blocks
x apache-couchdb-1.1.0/share, 0 bytes, 0 tape blocks

Perparations

root@test:/tmp# cd apache-couchdb-1.1.0
root@test:/tmp/apache-couchdb-1.1.0# PATH=/usr/bin:/usr/gcc/4.3/bin:/opt/local/bin:$PATH
root@test:/tmp/apache-couchdb-1.1.0# ./configure --prefix=/opt/local --with-js-include=/opt/local/include --with-js-lib=/opt/local/lib --with-erlang=/opt/local/lib/erlang/usr/include

checking for a BSD-compatible install... build-aux/install-sh -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... build-aux/install-sh -c -d
checking for gawk... no
...
config.status: executing libtool commands
You have configured Apache CouchDB, time to relax.
Run `make && sudo make install' to install.

Building

root@test:/tmp/apache-couchdb-1.1.0# gmake
gmake  all-recursive
gmake[1]: Entering directory `/tmp/apache-couchdb-1.1.0'
Making all in bin
gmake[2]: Entering directory `/tmp/apache-couchdb-1.1.0/bin'
sed -e "s|%ERL%|/usr/bin/erl|g" \
            -e "s|%ICU_CONFIG%|/opt/icu/bin/icu-config|g" \
            -e "s|%bindir%|/opt/local/bin|g" \
...

root@test:/tmp/apache-couchdb-1.1.0# gmake install
Making install in bin
gmake[1]: Entering directory `/tmp/apache-couchdb-1.1.0/bin'
gmake[2]: Entering directory `/tmp/apache-couchdb-1.1.0/bin'
test -z "/opt/local/bin" || ../build-aux/install-sh -c -d "/opt/local/bin"

Next steps

Now that we have installed CouchDB, we can start to set it up and create a Solaris Service for it. This will be discussed in Part 5 of this Guide.

Now comes the tricky part of the installation. After the installation of ICU, the next dependency is the Mozilla JS Engine 1.7.0. Thankfully CouchDB only requires 1.7.0 or up.

Basics

root@test:~# cd /tmp
root@test:/tmp# wget https://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
--2011-07-31 16:28:08--  https://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
Connecting to ftp.mozilla.org|63.245.209.137|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1165607 (1.1M) [application/x-gzip]
Saving to: `js-1.7.0.tar.gz'

100%[=========================================================================>] 1,165,607    378K/s   in 3.0s

2011-07-31 16:28:12 (378 KB/s) - `js-1.7.0.tar.gz' saved [1165607/1165607]

root@test:/tmp# tar xvf js-1.7.0.tar.gz
Decompressing 'js-1.7.0.tar.gz' with '/usr/bin/gzcat'...
x js, 0 bytes, 0 tape blocks
x js/src, 0 bytes, 0 tape blocks
x js/src/Makefile.in, 9622 bytes, 19 tape blocks
x js/src/jsproto.tbl, 4989 bytes, 10 tape blocks
...

Perparations

SpiderMonkey has no install script for OpenSolaris. Therefore we need to use the default Solaris script with minor modifications.

root@test:/tmp# cd js/src/config
root@test:/tmp/js/src/config# ln -s SunOS5.5.mk SunOS5.11_i86pc.mk
root@test:/tmp/js/src# cd ..
root@test:/tmp/js/src# mv config.mk config.mk.bak
root@test:/tmp/js/src# sed 's|NS_USE_NATIVE = 1|#NS_USE_NATIVE = 1|g' config.mk.bak > config.mk
root@test:/tmp/js/src# rm lock_SunOS.s
root@test:/tmp/js/src# PATH=/usr/bin:/usr/gcc/4.3/bin:$PATH

Building

The building-process should work flawless with the modified config.

root@test:/tmp/js/src# gmake -f Makefile.ref
cat: cannot open ../../dist/SunOS5.11_i86pc_DBG.OBJ/nspr/Version: No such file or directory
cd editline; gmake -f Makefile.ref all
gmake[1]: Entering directory `/tmp/js/src/editline'
gcc -o SunOS5.11_i86pc_DBG.OBJ/editline.o -c -Wall -Wno-format -DXP_UNIX -g -DXP_UNIX -DSVR4 -DSYSV -DSOLARIS -DHAVE_LOCALTIME_R  -DDEBUG -DDEBUG_  -DJSFILE  -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX -DHAVE_STDLIB -DUNIQUE_HISTORY editline.c
...

root@test:/tmp/js/src# JS_DIST=/opt/local gmake -f Makefile.ref export
cat: cannot open ../../dist/SunOS5.11_i86pc_DBG.OBJ/nspr/Version: No such file or directory
cd editline; gmake -f Makefile.ref export
gmake[1]: Entering directory `/tmp/js/src/editline'
gmake[1]: Nothing to be done for `export'.
...

Next steps

After installing SpiderMonkey, we can finally install CouchDB:
CouchDB on OpenSolaris: Part 4 – CouchDB

After the installation of Erlang, the next dependency is ICU.

ICU is a set of libraries providing Unicode and Globalization support for software applications. It’s source-code is available from http://download.icu-project.org/files/icu4c/

Basics

root@test:~# cd /tmp/
root@test:/tmp#  wget http://download.icu-project.org/files/icu4c/4.8.1/icu4c-4_8_1-src.tgz
--2011-07-31 16:16:16--  http://download.icu-project.org/files/icu4c/4.8.1/icu4c-4_8_1-src.tgz
Connecting to download.icu-project.org|208.109.248.225|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18677882 (18M) [application/x-gzip]
Saving to: `icu4c-4_8_1-src.tgz'

100%[=======================================================>] 18,677,882   662K/s   in 29s

2011-07-31 16:16:45 (628 KB/s) - `icu4c-4_8_1-src.tgz' saved [18677882/18677882]

root@test:/tmp# tar xvf icu4c-4_8_1-src.tgz
Decompressing 'icu4c-4_8_1-src.tgz' with '/usr/bin/gzcat'...
x icu, 0 bytes, 0 tape blocks
x icu/license.html, 1981 bytes, 4 tape blocks
x icu/as_is, 0 bytes, 0 tape blocks
...
root@test:/tmp# cd icu/source/
root@test:/tmp/icu/source#

Preparations

The downloaded tar is a little bit faulty, therefore we need to fix the permissions of some files before we can configure and build ICU.

root@test:/tmp/icu/source# chmod +x runConfigureICU configure install-sh
root@test:/tmp/icu/source# PATH=/usr/bin:/usr/gcc/4.3/bin:$PATH
root@test:/tmp/icu/source# ./runConfigureICU Solaris/GCC --prefix=/opt/local
export CPP= CC=gcc CXX=g++ CPPFLAGS= CFLAGS= -O1 CXXFLAGS= -O3 LDFLAGS= MAKE=
Running ./configure  --prefix=/opt/local for SOLARIS using the GNU C++ compiler

checking for ICU version numbers... release 4.8.1, library 48.1, unicode version 6.0
...

root@test:/tmp/icu/source# ./configure --prefix=/opt/local
checking for ICU version numbers... release 4.8.1, library 48.1, unicode version 6.0
checking build system type... i386-pc-solaris2.11
checking host system type... i386-pc-solaris2.11
...

Building

If the config went flawless, we can proceed with the build-process.

root@test:/tmp/icu/source# gmake
rebuilding config/icucross.mk
cd ./config; \
                gmake -f pkgdataMakefile
gmake[1]: Entering directory `/tmp/icu/source/config'
rm -rf pkgdata.inc
...
root@test:/tmp/icu/source# gmake install
gmake[0]: Making `install' in `stubdata'
gmake[1]: Entering directory `/tmp/icu/source/stubdata'
/bin/sh ../mkinstalldirs /opt/local/lib
.././install-sh -c libicudata.so.48.1 /opt/local/lib

Next steps

After installing ICU, Part 3 of this guide will be about SpiderMonkey:
CouchDB on OpenSolaris: Part 3 – SpiderMonkey

The first step to a CouchDB server is the installation of the Erlang programming language. It’s available as source on http://www.erlang.org/download.html.

The required software should already be installed on your system. We will install Erlang to /opt/local like the other software required for CouchDB.

Basics

root@test:~# cd /tmp/
root@test:/tmp# wget http://www.erlang.org/download/otp_src_R14B03.tar.gz
--2011-07-31 15:31:25--  http://www.erlang.org/download/otp_src_R14B03.tar.gz
Connecting to www.erlang.org|192.121.151.107|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 70620709 (67M) 1
Saving to: `otp_src_R14B03.tar.gz'

100%[========================================================>] 70,620,709   709K/s   in 98s

2011-07-31 15:33:03 (702 KB/s) - `otp_src_R14B03.tar.gz' saved [70620709/70620709]

root@test:/tmp# tar xvf otp_src_R14B03.tar.gz
Decompressing 'otp_src_R14B03.tar.gz' with '/usr/bin/gzcat'...
x otp_src_R14B03, 0 bytes, 0 tape blocks
x otp_src_R14B03/.mailmap, 128 bytes, 1 tape blocks
...

root@test:/tmp# cd otp_src_R14B03

Preparations

Erlang will not compile unless we remove some lines from ./erts/emulator/drivers/common/inet_drv.c. In this file you can find the following lines:

#ifdef SIOCGIFHWADDR
            if (ioctl(desc->s, SIOCGIFHWADDR, (char *)&ifreq) < 0)
                break;
            buf_check(sptr, s_end, 1+2+IFHWADDRLEN);
            *sptr++ = INET_IFOPT_HWADDR;
            put_int16(IFHWADDRLEN, sptr); sptr += 2;
            /* raw memcpy (fix include autoconf later) */
            sys_memcpy(sptr, (char*)(&ifreq.ifr_hwaddr.sa_data), IFHWADDRLEN);
            sptr += IFHWADDRLEN;
#elif defined(SIOCGENADDR)

Those have to be changed to:

#ifdef SIOCGIFHWADDR
#elif defined(SIOCGENADDR)

Another issue is a missing +x for the install script which prevents the execution of gmake install.

root@test:/tmp/otp_src_R14B03# chmod +x lib/erl_interface/src/auxdir/install-sh

Finally we have to ensure that gmake uses the Solaris linker (LD) and GCC 4.3

root@test:/tmp/otp_src_R14B03# PATH=/usr/bin:/usr/gcc/4.3/bin:$PATH

Building

After those preparations, the build process is straight forward.

root@test:/tmp/otp_src_R14B03# ./configure --prefix=/opt/local
Ignoring the --cache-file argument since it can cause the system to be erroneously configured
Disabling caching
checking build system type... i386-pc-solaris2.11
checking host system type... i386-pc-solaris2.11
...

root@test:/tmp/otp_src_R14B03# gmake
test X"$ERTS_SKIP_DEPEND" = X"true" || (cd erts/emulator && ERL_TOP=/tmp/otp_src_R14B03 make generate depend)
make[1]: Entering directory `/tmp/otp_src_R14B03/erts/emulator'
make -f i386-pc-solaris2.11/Makefile generate
...
drink a coffee or two...

root@test:/tmp/otp_src_R14B03# gmake install
cd erts && ERL_TOP=/tmp/otp_src_R14B03 make NO_START_SCRIPTS=true  FLAVOR=
make[1]: Entering directory `/tmp/otp_src_R14B03/erts'
make[2]: Entering directory `/tmp/otp_src_R14B03/erts/emulator'
...

Test

Now we can test if Erlang is installed and works (including OpenSSL).

root@test:/tmp/otp_src_R14B03# cd /opt/local/bin/
root@test:/opt/local/bin# ./erl
Erlang R14B03 (erts-5.8.4) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.4  (abort with ^G)
1> crypto:start().
ok
2> q().
ok
3> root@test:/opt/local/bin#

Next steps

After installing Erlang we can proceed to Part 2 of this guide:
CouchDB on OpenSolaris: Part 2 – ICU