Running couchdb under an unprivileged user account.

When helping a friend last night with couchdb a got stuck when trying to start it as an unprivileged user. The error messages you get from couchdb is far from easy to understand.

This is my way of solving it.

1
2
3
4
5
6
7
$ couchdb
kernel-poll not supported; "K" parameter ignored
Apache CouchDB 0.9.0 (LogLevel=info) is starting.
{"init terminating in do_boot",{{badmatch,{error,shutdown}},[{couch_server_sup,start_server,1},{erl_eval,do_apply,5},{erl_eval,exprs,5},{init,start_it,1},{init,start_em,1}]}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()

Even with debug turned on it’s pretty hard to understand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
kernel-poll not supported; "K" parameter ignored
Apache CouchDB 0.9.0 (LogLevel=debug) is starting.
Configuration Settings ["./couchdb/local.ini"]:
  [Couch] BindAddress="127.0.0.1"
  [Couch] ConsoleStartupMsg="Apache CouchDB is starting."
  [Couch] DbRootDir="/home/mathias/couchdb"
  [Couch] DocumentRoot="/home/mathias/couchdb/www"
  [Couch] LogFile="/home/mathias/couchdb/couch.log"
  [Couch] LogLevel="debug"
  [Couch] Port="5984"
  [Couch] UtilDriverDir="/usr/local/lib/couchdb/erlang/lib/couch-0.8.1-incubating/priv/lib"
  [Couch Query Servers] javascript="/usr/local/bin/couchjs /usr/local/share/couchdb/server/main.js"
  [couchdb] database_dir="/home/mathias/couchdb"
  [couchdb] view_index_dir="/home/mathias/couchdb"
  [httpd] bind_address="127.0.0.1"
  [httpd] port="5984"
  [log] level="debug"
[error] [<0.41.0>] {error_report,<0.21.0>,
    {<0.41.0>,crash_report,
     [[{pid,<0.41.0>},
       {registered_name,couch_server},
       {error_info,
           {exit,
               {badarg,
                   [{erlang,list_to_integer,[undefined]},
                    {couch_server,init,1},
                    {gen_server,init_it,6},
                    {proc_lib,init_p_do_apply,3}]},
               [{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}},
       {initial_call,{couch_server,init,['Argument__1']}},
       {ancestors,[couch_primary_services,couch_server_sup,<0.1.0>]},
       {messages,[]},
       {links,[<0.36.0>]},
       {dictionary,[]},
       {trap_exit,false},
       {status,running},
       {heap_size,233},
       {stack_size,23},
       {reductions,113}],
      []]}}
{"init terminating in do_boot",{{badmatch,{error,shutdown}},[{couch_server_sup,start_server,1},{erl_eval,do_apply,5},{erl_eval,exprs,5},{init,start_it,1},{init,start_em,1}]}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()

When running things as unprivileged users the usual problems are that you do not have access to read/write files or binding to the lower ports A.K.A. “well known ports”. With that in mind I located the original config files for couchdb with the plan of copying or overriding them.

My config files where located under /usr/local/etc/couchdb/

1
2
3
$ ls -lsa /usr/local/etc/couchdb/
4 -rw-r--r-- 1 root root 2626 2009-04-10 11:58 default.ini
4 -rw-r--r-- 1 root root  847 2009-04-10 14:17 local.ini

Reading the documentation I found out that local.ini is just for overriding stuff and local.ini will never be overwritten by any upgrades. The config files contain lots of settings, but my aim is just to get it to start so I focus on the things that I think is the problem and thats all the PATH settings.

In my unprivileged users home folder I created a folder named couchdb to hold my config and datafiles. I also created a www folder inside it.

After that I create my local.ini to override my settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat couchdb/local.ini

[couchdb]
database_dir = ./couchdb
view_index_dir = ./couchdb

[httpd]
port = 5984
bind_address = 127.0.0.1

[log]
level = info
file=./couchdb/couch.log

When our new config is in place we can try to start couchdb again.

1
2
$ couchdb -C ./couchdb/local.ini -p ./couchdb/couch.pid -b
Apache CouchDB has started, time to relax.

-C means use configuration FILE (chainable, does not reset system default). If we do not want to use the system config at all we can use a lowercase -c but we want to keep our overridden config as small as possible right now.

-p is the path to our pid file and -b tells couchdb to spawn in the background.

If you are on your local machine you can just launch your browser and point it to http://127.0.0.1:5984/

1
{"couchdb":"Welcome","version":"0.9.0"}

or you can access the admin gui trough: http://127.0.0.1:5984/_utils/index.html.

After I started to write this blogpost I did found a page on the Couchdb wiki that explains Error messages and solutions and here it is: http://wiki.apache.org/couchdb/Error_messages.

Happy haxxing!

Posted in Databases, Hosting at April 10th, 2009. Trackback URI: trackback Tags: , , Written by: 
  • http://couchdb.apache.org/ Jan

    Hi,

    I see you’re mixing CouchDB 0.8 and 0.9 ini files. 0.8 had only couch.ini and CamelCaps ini directives. 0.9 has default.ini and local.ini (you described the use of local.ini correctly) and under_score directive names.

    You might want to clean this up :)

    Cheers
    Jan

  • Mathias Stjernström

    Appreciate it Jan!

    I have updated my post to reflect your comment.

  • http://www.edavies.nildram.co.uk/ Ed Davies

    For any others coming this way: it seems like

    1
    -C

    doesn’t work in 0.10,

    1
    -a

    worked for me with the local.ini file described above (though I haven’t tried with the PID file and putting it in the background yet).

  • Mathias Stjernström

    I’ve not used couchDB myself since I wrote this post so I have no clue, but thanks for sharing ;)

  • Pingback: ehcache.net

It's past my bedtime is using WP-Gravatar