Question

I've installed CouchDB 1.3.1 on FreeBSD from the portage. It runs find when started by the root user. However, when attempting to start it by rc-script it doesn't come up.

I've set the correct (couchdb owns it) permissions for /var/log/couchdb /var/run/couchdb and /usr/local/etc/couchdb

That didn't do the rick however. I've logged into the couchdb user account and tried to start couchdb. As a result I got this:

Apache CouchDB 1.3.1 (LogLevel=info) is starting.
[error] [<0.97.0>] {error_report,<0.30.0>,
                    {<0.97.0>,crash_report,
                     [[{initial_call,{couch_file,init,['Argument__1']}},
                       {pid,<0.97.0>},
                       {registered_name,[]},
                       {error_info,
                        {exit,
                         {{badmatch,{error,eacces}},
                          [{couch_file,init,1,
                            [{file,"couch_file.erl"},{line,314}]},
                           {gen_server,init_it,6,
                            [{file,"gen_server.erl"},{line,304}]},
                           {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,227}]}]},
                         [{gen_server,init_it,6,
                           [{file,"gen_server.erl"},{line,328}]},
                          {proc_lib,init_p_do_apply,3,
                           [{file,"proc_lib.erl"},{line,227}]}]}},
                       {ancestors,[<0.96.0>]},
                       {messages,[]},
                       {links,[#Port<0.2176>,<0.96.0>]},
                       {dictionary,[]},
                       {trap_exit,true},
                       {status,running},
                       {heap_size,610},
                       {stack_size,24},
                       {reductions,478}],
                      [{neighbour,
                        [{pid,<0.96.0>},
                         {registered_name,[]},
                         {initial_call,{erlang,apply,2}},
                         {current_function,{proc_lib,sync_wait,2}},
                         {ancestors,[]},
                         {messages,
                          [{ack,<0.97.0>,
                            {error,
                             {{badmatch,{error,eacces}},
                              [{couch_file,init,1,
                                [{file,"couch_file.erl"},{line,314}]},
                               {gen_server,init_it,6,
                                [{file,"gen_server.erl"},{line,304}]},
                               {proc_lib,init_p_do_apply,3,
                                [{file,"proc_lib.erl"},{line,227}]}]}}}]},
                         {links,[<0.86.0>,<0.97.0>]},
                         {dictionary,[]},
                         {trap_exit,false},
                         {status,runnable},
                         {heap_size,233},
                         {stack_size,20},
                         {reductions,28}]}]]}}
{"init terminating in do_boot",{{badmatch,{error,{bad_return,{{couch_app,start,[normal,["/usr/local/etc/couchdb/default.ini","/usr/local/etc/couchdb/local.ini"]]},{'EXIT',{{badmatch,{error,shutdown}},[{couch_server_sup,start_server,1,[{file,"couch_server_sup.erl"},{line,98}]},{application_master,start_it_old,4,[{file,"application_master.erl"},{line,274}]}]}}}}}},[{couch,start,0,[{file,"couch.erl"},{line,18}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
init terminating in do_boot ()

What else can I try to make couchdb start from a non-root account?

Was it helpful?

Solution

Problem solved. There where a couple of reasons for it not to work. Here's the short version:

After installing the port, DON'T run couchdb as root. Doing that upsets permissions.

The quick fix for that would be to remove couchdb completely and reinstall it. Of course that's only an option as long as there's nothing in the database. The following script will make sure that couchdb is purged from your system completely:

cd /usr/ports/database/couchdb
make deinstall
make clean
rm -rf /var/{db,lib,log,run}/couchdb /usr/local/etc/couchdb/

After that install couchdb again and run it as it's supposed to run

cd /usr/ports/database/couchdb
make install clean
service couchdb start

If re-installation is not an option for you run the following script to repair permissions.

chown -R couchdb:couchdb /var/{db,lib,log,run}/couchdb /usr/local/etc/couchdb/
chmod -R ug+rw /var/{db,lib,log,run}/couchdb /usr/local/etc/couchdb/local.ini
chmod -R o-rwx /var/{db,lib,log,run}/couchdb /usr/local/etc/couchdb/

The last line removes permissions for users other than couchdb as that's where all the data are stores. This is of course optional, but improves security.

These solutions hav been tested with FreeBSD 9.1 and CouchDB 1.3.1 from the portage.

Special thanks to this blogpost as it contained vital clues about what was wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top