You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by till <ti...@php.net> on 2011/05/23 18:01:23 UTC

init.d/couchdb

Hey guys,

I just re-ran some chef-recipes I had and noticed how CouchDB 1.0.1
didn't start (/etc/init.d/couchdb) return 1.
So I updated the recipe to use 1.0.2 and found the same problem.

After adding 'set -x' to the script, I discovered that the 'su' call
failed. Has anyone else seen this?
I replaced both (for start and stop) with sudo -u $COUCHDB_USER
$command which makes it work, but I reckon sudo is not too portable
across the different flavours of Linux.

I think the most clean and consistent approach is start-stop-daemon,
but I wanted to ask here first before I write a patch.

Till

Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 8:30 PM, Noah Slater <ns...@apache.org> wrote:
>
> On 23 May 2011, at 19:05, till wrote:
>
>> Great success:
>> foo:~# su -c couchdb -c 'echo "foo"'
>> foo
>
> How about:
>
> sudo -u couchdb /usr/local/bin/couchdb

Seems to work:

foo:~# su -c couchdb -c /usr/local/bin/couchdb
Apache CouchDB 1.0.2 (LogLevel=error) is starting.
Apache CouchDB has started. Time to relax.

Re: init.d/couchdb

Posted by Noah Slater <ns...@apache.org>.
On 23 May 2011, at 19:05, till wrote:

> Great success:
> foo:~# su -c couchdb -c 'echo "foo"'
> foo

How about:

sudo -u couchdb /usr/local/bin/couchdb


Re: init.d/couchdb

Posted by Randall Leeds <ra...@gmail.com>.
On Mon, May 23, 2011 at 11:05, till <ti...@php.net> wrote:
> On Mon, May 23, 2011 at 7:57 PM, Noah Slater <ns...@apache.org> wrote:
>>
>> On 23 May 2011, at 18:40, till wrote:
>>
>>> I think since the 127 comes from su, it doesn't even get to create
>>> .out and .err. I see them nowhere. Even after changing it to
>>> /tmp/couchdb.out (etc.).
>>>
>>> Googling says, "127 - a command could not be found", but I was unable
>>> to find a dedicated list of exit codes related to su.
>>
>> Have you tried with another command?
>>
>> What does this give you:
>>
>> su couchdb -c "echo test"
>>
>>
>
> Great success:
> foo:~# su -c couchdb -c 'echo "foo"'
> foo
>

Can you try changing

su $COUCHDB_USER -c "$command"

to

su $COUCHDB_USER -c "cd \$HOME && $command"

and report back?

I think I've seen something like this before.
CouchDB start scripts use the "find" command to look for .ini files in
the configuration directory.
Unfortunately, find tries to read the current directory (even if it's
not the target root directory for the search) and will die with
permission errors.
Since `su` doesn't change the cwd by default, find may be invoked in
your home directory (or wherever) which the couchdb user has no
permission read.

Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 7:57 PM, Noah Slater <ns...@apache.org> wrote:
>
> On 23 May 2011, at 18:40, till wrote:
>
>> I think since the 127 comes from su, it doesn't even get to create
>> .out and .err. I see them nowhere. Even after changing it to
>> /tmp/couchdb.out (etc.).
>>
>> Googling says, "127 - a command could not be found", but I was unable
>> to find a dedicated list of exit codes related to su.
>
> Have you tried with another command?
>
> What does this give you:
>
> su couchdb -c "echo test"
>
>

Great success:
foo:~# su -c couchdb -c 'echo "foo"'
foo

Re: init.d/couchdb

Posted by Noah Slater <ns...@apache.org>.
On 23 May 2011, at 18:40, till wrote:

> I think since the 127 comes from su, it doesn't even get to create
> .out and .err. I see them nowhere. Even after changing it to
> /tmp/couchdb.out (etc.).
> 
> Googling says, "127 - a command could not be found", but I was unable
> to find a dedicated list of exit codes related to su.

Have you tried with another command?

What does this give you:

su couchdb -c "echo test"


Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 7:40 PM, till <ti...@php.net> wrote:
> On Mon, May 23, 2011 at 7:07 PM, Noah Slater <ns...@apache.org> wrote:
>>
>> On 23 May 2011, at 17:47, till wrote:
>>
>>> I think su -c foo etc. is fundamentally wrong.
>>
>> Why?
>>
>>> In the end, it's why there's start-stop-daemon.
>>
>> This is one solution to the problem of starting and stopping daemons. There are many solutions. We have one already. One that has been working for a number of years. The system infrastructure has been one of the most stable parts of CouchDB since it was originally added.
>>
>>> foo:~# su couchdb -c /usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5
>>
>> In the script, we have:
>>
>> su $COUCHDB_USER -c "$command"
>>
>> So your example will fail because it is not quoted.
>>
>>> foo:~# su couchdb -c "/usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5"
>>> foo:~# echo $?
>>> 127
>>
>> So there's an error starting CouchDB. What is it?
>
> I really copied everything that was output. ;-)
>
> You tell me what 127 is. I think it's an exit code from su.
>
>> Try this instead, and report back what you see:
>>
>> su couchdb -c "/usr/local/bin/couchdb -b -o couchdb.out -e couchdb.err -r 5"
>> echo $?
>> cat couchdb.out
>> cat couchdb.err
>
> I think since the 127 comes from su, it doesn't even get to create
> .out and .err. I see them nowhere. Even after changing it to
> /tmp/couchdb.out (etc.).
>
> Googling says, "127 - a command could not be found", but I was unable
> to find a dedicated list of exit codes related to su.
>
> Til
>

Ran it through strace:
http://friendpaste.com/3Y9YhKmf7pFTeiW6pGT6TY

Till

Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 7:07 PM, Noah Slater <ns...@apache.org> wrote:
>
> On 23 May 2011, at 17:47, till wrote:
>
>> I think su -c foo etc. is fundamentally wrong.
>
> Why?
>
>> In the end, it's why there's start-stop-daemon.
>
> This is one solution to the problem of starting and stopping daemons. There are many solutions. We have one already. One that has been working for a number of years. The system infrastructure has been one of the most stable parts of CouchDB since it was originally added.
>
>> foo:~# su couchdb -c /usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5
>
> In the script, we have:
>
> su $COUCHDB_USER -c "$command"
>
> So your example will fail because it is not quoted.
>
>> foo:~# su couchdb -c "/usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5"
>> foo:~# echo $?
>> 127
>
> So there's an error starting CouchDB. What is it?

I really copied everything that was output. ;-)

You tell me what 127 is. I think it's an exit code from su.

> Try this instead, and report back what you see:
>
> su couchdb -c "/usr/local/bin/couchdb -b -o couchdb.out -e couchdb.err -r 5"
> echo $?
> cat couchdb.out
> cat couchdb.err

I think since the 127 comes from su, it doesn't even get to create
.out and .err. I see them nowhere. Even after changing it to
/tmp/couchdb.out (etc.).

Googling says, "127 - a command could not be found", but I was unable
to find a dedicated list of exit codes related to su.

Til

Re: Dependencies to install to be able to work on CouchDB Development

Posted by Randall Leeds <ra...@gmail.com>.
On Mon, May 23, 2011 at 10:47, Marcos Ortiz <ml...@uci.cu> wrote:
> Regards to all the CouchDB´s list
> I´m very interested to work on the CouchDB´s development simply for one
> strong reason(at least for me):
> It´s written in Erlang
>  - So, Which are the dependencies to install to be able to work on this?
>  All the Apache projects sources code are using SVN, Do you have a Git or
> Mercurial mirror for CouchDB?

Dependencies:
https://github.com/apache/couchdb/blob/trunk/INSTALL.Unix

Git:
Read-only git mirrors at http://git.apache.org/
Also, many devs have github accounts for their personal forks and
there's an apache one at github.com/apache/couchdb.

>
> Where are the issues for CouchDB?

https://issues.apache.org/jira/browse/COUCHDB

Also join us in #couchdb on freenode IRC.

Not really necessary to cross-post this to the user@ list, but in case
anyone sees this there and is interested, I responded to both.

Cheers and happy hacking!
-Randall

Re: Dependencies to install to be able to work on CouchDB Development

Posted by Randall Leeds <ra...@gmail.com>.
On Mon, May 23, 2011 at 10:47, Marcos Ortiz <ml...@uci.cu> wrote:
> Regards to all the CouchDB´s list
> I´m very interested to work on the CouchDB´s development simply for one
> strong reason(at least for me):
> It´s written in Erlang
>  - So, Which are the dependencies to install to be able to work on this?
>  All the Apache projects sources code are using SVN, Do you have a Git or
> Mercurial mirror for CouchDB?

Dependencies:
https://github.com/apache/couchdb/blob/trunk/INSTALL.Unix

Git:
Read-only git mirrors at http://git.apache.org/
Also, many devs have github accounts for their personal forks and
there's an apache one at github.com/apache/couchdb.

>
> Where are the issues for CouchDB?

https://issues.apache.org/jira/browse/COUCHDB

Also join us in #couchdb on freenode IRC.

Not really necessary to cross-post this to the user@ list, but in case
anyone sees this there and is interested, I responded to both.

Cheers and happy hacking!
-Randall

Dependencies to install to be able to work on CouchDB Development

Posted by Marcos Ortiz <ml...@uci.cu>.
Regards to all the CouchDB´s list
I´m very interested to work on the CouchDB´s development simply for one 
strong reason(at least for me):
It´s written in Erlang
  - So, Which are the dependencies to install to be able to work on this?
  All the Apache projects sources code are using SVN, Do you have a Git 
or Mercurial mirror for CouchDB?

Where are the issues for CouchDB?

Thanks a lot

-- 
Marcos Luís Ortíz Valmaseda
  Software Engineer (Large-Scaled Distributed Systems)
  University of Information Sciences,
  La Habana, Cuba
  Linux User # 418229
  http://about.me/marcosortiz


Dependencies to install to be able to work on CouchDB Development

Posted by Marcos Ortiz <ml...@uci.cu>.
Regards to all the CouchDB´s list
I´m very interested to work on the CouchDB´s development simply for one 
strong reason(at least for me):
It´s written in Erlang
  - So, Which are the dependencies to install to be able to work on this?
  All the Apache projects sources code are using SVN, Do you have a Git 
or Mercurial mirror for CouchDB?

Where are the issues for CouchDB?

Thanks a lot

-- 
Marcos Luís Ortíz Valmaseda
  Software Engineer (Large-Scaled Distributed Systems)
  University of Information Sciences,
  La Habana, Cuba
  Linux User # 418229
  http://about.me/marcosortiz


Re: init.d/couchdb

Posted by Noah Slater <ns...@apache.org>.
On 23 May 2011, at 17:47, till wrote:

> I think su -c foo etc. is fundamentally wrong.

Why?

> In the end, it's why there's start-stop-daemon.

This is one solution to the problem of starting and stopping daemons. There are many solutions. We have one already. One that has been working for a number of years. The system infrastructure has been one of the most stable parts of CouchDB since it was originally added.

> foo:~# su couchdb -c /usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5

In the script, we have:

su $COUCHDB_USER -c "$command" 

So your example will fail because it is not quoted.

> foo:~# su couchdb -c "/usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5"
> foo:~# echo $?
> 127

So there's an error starting CouchDB. What is it?

Try this instead, and report back what you see:

su couchdb -c "/usr/local/bin/couchdb -b -o couchdb.out -e couchdb.err -r 5"
echo $?
cat couchdb.out
cat couchdb.err



Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 6:29 PM, Noah Slater <ns...@apache.org> wrote:
>
> On 23 May 2011, at 17:26, till wrote:
>
>> Yes, I did. I'm just booting my vm. Will have it for you shortly.
>>
>> Btw, the couchdb's home is its db dir. And yes, all permissions are
>> correct. It wouldn't work otherwise when I used sudo -u.
>
> Well something odd is clearly going on, and I think we should understand what that is before attempting to fix it through guesswork. How would we even know if the underlying problem had been addressed?
>
>

I think su -c foo etc. is fundamentally wrong. sudo -u is not any
better because of the ulimit mess and inconsistencies. In the end,
it's why there's start-stop-daemon.

For completeness, here's the user:

foo:~# id couchdb
uid=1001(couchdb) gid=2000(couchdb) groups=2000(couchdb)
foo:~# cat /etc/passwd|grep couchdb
couchdb:x:1001:2000:CouchDB:/couchdb/:/bin/zsh
foo:~# ls -lah /couchdb/
total 28K
drwxr-xr-x  5 couchdb couchdb 4.0K 2011-05-23 07:34 .
drwxr-xr-x 28 root    root    4.0K 2011-05-23 09:22 ..
drwxr-xr-x  2 couchdb couchdb 4.0K 2011-05-23 07:08 db
drwxr-xr-x  2 couchdb couchdb 4.0K 2011-05-23 07:34 .delete
-rw-r--r--  1 couchdb couchdb 4.1K 2011-05-23 07:35 _users.couch
drwxr-xr-x  2 couchdb couchdb 4.0K 2011-05-23 07:08 views

Debugging the init-script:

After removing the pipe to /dev/null, it errors with invalid option --
'b'. So I extracted the call:

foo:~# su couchdb -c /usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5
su: invalid option -- 'b'
Usage: su [options] [LOGIN]

Options:
  -c, --command COMMAND         pass COMMAND to the invoked shell
  -h, --help                    display this help message and exit
  -, -l, --login                make the shell a login shell
  -m, -p,
  --preserve-environment        do not reset environment variables, and
                                keep the same shell
  -s, --shell SHELL             use SHELL instead of the default in passwd

So, the first thing that seems to be off -- the command is not quoted
which leads to the error.

Quoting it, doesn't help either:

foo:~# su couchdb -c "/usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5"
foo:~# echo $?
127


Any thoughts?

Again, the following call works:
sudo -u couchdb /usr/local/bin/couchdb -b -o /dev/null -e /dev/null -r 5

Till

Re: init.d/couchdb

Posted by Noah Slater <ns...@apache.org>.
On 23 May 2011, at 17:26, till wrote:

> Yes, I did. I'm just booting my vm. Will have it for you shortly.
> 
> Btw, the couchdb's home is its db dir. And yes, all permissions are
> correct. It wouldn't work otherwise when I used sudo -u.

Well something odd is clearly going on, and I think we should understand what that is before attempting to fix it through guesswork. How would we even know if the underlying problem had been addressed? 


Re: init.d/couchdb

Posted by till <ti...@php.net>.
On Mon, May 23, 2011 at 6:22 PM, Noah Slater <ns...@echolibre.com> wrote:
>
> On 23 May 2011, at 17:14, Noah Slater wrote:
>
>> Let's figure out why "su" is failing for you first.
>
> Did you try the command manually by the way?
>
> What happens when you try to execute that su invocation yourself?
>
> I'm guessing it's a problem with your root or couchdb user not having a valid home directory.

Yes, I did. I'm just booting my vm. Will have it for you shortly.

Btw, the couchdb's home is its db dir. And yes, all permissions are
correct. It wouldn't work otherwise when I used sudo -u.

Re: init.d/couchdb

Posted by Noah Slater <ns...@echolibre.com>.
On 23 May 2011, at 17:14, Noah Slater wrote:

> Let's figure out why "su" is failing for you first.

Did you try the command manually by the way?

What happens when you try to execute that su invocation yourself?

I'm guessing it's a problem with your root or couchdb user not having a valid home directory.

Re: init.d/couchdb

Posted by Noah Slater <ns...@apache.org>.
Hang on a second!

The most clean and consistent approach is to entirely rewrite the init script?

Let's figure out why "su" is failing for you first.

Because it's been working for most people, for a few years now. :)

On 23 May 2011, at 17:01, till wrote:

> Hey guys,
> 
> I just re-ran some chef-recipes I had and noticed how CouchDB 1.0.1
> didn't start (/etc/init.d/couchdb) return 1.
> So I updated the recipe to use 1.0.2 and found the same problem.
> 
> After adding 'set -x' to the script, I discovered that the 'su' call
> failed. Has anyone else seen this?
> I replaced both (for start and stop) with sudo -u $COUCHDB_USER
> $command which makes it work, but I reckon sudo is not too portable
> across the different flavours of Linux.
> 
> I think the most clean and consistent approach is start-stop-daemon,
> but I wanted to ask here first before I write a patch.
> 
> Till