CouchDB
  1. CouchDB
  2. COUCHDB-128

couchdb is not starting properly from init.d script in trunk

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: Build System
    • Labels:
      None
    1. couchdb-init.diff
      1 kB
      Duncan Mac-Vicar P.
    2. 0001-always-pass-options-in-init-script-COUCHDB-128.patch
      3 kB
      Randall Leeds

      Activity

      Noah Slater created issue -
      Noah Slater made changes -
      Field Original Value New Value
      Fix Version/s 0.9 [ 12313208 ]
      Priority Major [ 3 ] Blocker [ 1 ]
      Hide
      Paul Joseph Davis added a comment -

      Is there no more information on this ticket? I routinely us /usr/local/etc/init.d/couchdb to start and stop couchdb on Linux.

      Show
      Paul Joseph Davis added a comment - Is there no more information on this ticket? I routinely us /usr/local/etc/init.d/couchdb to start and stop couchdb on Linux.
      Hide
      Patrick Antivackis added a comment -

      On my side there are two things that should be changed in this file

      1) change the first line
      #!/bin/sh -e
      by
      #!/bin/sh
      in fact, i tested Linux Fedora, CentOs and Linux Mandriva and all not succeed to start with the -e flag.

      If i do with the original init script :
      /opt/couchdb/etc/rc.d/couchdb start
      Nothing is started

      if i do with the original script :
      /bin/sh /opt/couchdb/etc/rc.d/couchdb start
      I get a :
      Starting database server couchdb
      And couch is indeed started.

      If i edit the init script and remove the -e flag and launch
      /opt/couchdb/etc/rc.d/couchdb start
      I get a :
      Starting database server couchdb
      And couch is indeed started.

      I look in all the scripts in /etc/init.d and none have the -e flag

      2) it should be necesssary to add
      COUCHDB_USER=couchdb
      in the init script to reflect the security consideration in the README file in order to not start couch as a root user

      Regards

      Show
      Patrick Antivackis added a comment - On my side there are two things that should be changed in this file 1) change the first line #!/bin/sh -e by #!/bin/sh in fact, i tested Linux Fedora, CentOs and Linux Mandriva and all not succeed to start with the -e flag. If i do with the original init script : /opt/couchdb/etc/rc.d/couchdb start Nothing is started if i do with the original script : /bin/sh /opt/couchdb/etc/rc.d/couchdb start I get a : Starting database server couchdb And couch is indeed started. If i edit the init script and remove the -e flag and launch /opt/couchdb/etc/rc.d/couchdb start I get a : Starting database server couchdb And couch is indeed started. I look in all the scripts in /etc/init.d and none have the -e flag 2) it should be necesssary to add COUCHDB_USER=couchdb in the init script to reflect the security consideration in the README file in order to not start couch as a root user Regards
      Hide
      Noah Slater added a comment -

      The "-e" line should be POSIX compatible.

      Debian mandates the use of POSIX compatible shell scripts so that the shell can
      be changed from bash, sh, ash, or dash. If it is claimed that this is the case,
      I would like to see pointers to man pages detailing the problems.

      The CouchDB username is set from /etc/default/couchdb. Please check here.

      Show
      Noah Slater added a comment - The "-e" line should be POSIX compatible. Debian mandates the use of POSIX compatible shell scripts so that the shell can be changed from bash, sh, ash, or dash. If it is claimed that this is the case, I would like to see pointers to man pages detailing the problems. The CouchDB username is set from /etc/default/couchdb. Please check here.
      Noah Slater made changes -
      Priority Blocker [ 1 ] Major [ 3 ]
      Fix Version/s 0.9 [ 12313208 ]
      Hide
      Duncan Mac-Vicar P. added a comment -

      The attached patch fixes the same issue on openSUSE.

      The problem was that the status and stop functions did not pass the custom pid file (which was moved from /var/run/couchdb.pid to /var/run/couchdb/couchdb.pid to have it running as couchdb user).

      With this patch the init script reports the correct status and starts/stops the server without problem.

      Show
      Duncan Mac-Vicar P. added a comment - The attached patch fixes the same issue on openSUSE. The problem was that the status and stop functions did not pass the custom pid file (which was moved from /var/run/couchdb.pid to /var/run/couchdb/couchdb.pid to have it running as couchdb user). With this patch the init script reports the correct status and starts/stops the server without problem.
      Duncan Mac-Vicar P. made changes -
      Attachment couchdb-init.diff [ 12414550 ]
      Hide
      Randall Leeds added a comment -

      It pains me to see this ticket open for so long. Since I've been in the habit of mucking about in the build system lately, here's a patch. It reduces code duplication in the init script and solves OP's problem.

      Show
      Randall Leeds added a comment - It pains me to see this ticket open for so long. Since I've been in the habit of mucking about in the build system lately, here's a patch. It reduces code duplication in the init script and solves OP's problem.
      Randall Leeds made changes -
      Attachment 0001-always-pass-options-in-init-script-COUCHDB-128.patch [ 12469022 ]
      Hide
      Noah Slater added a comment -

      Randall, I do not understand what your patch is doing. Could you explain what the problem is, and how your patch attempts to solve it. Why did the patch submitted by Duncan not work? What, exactly, is the problem here? Your patch seems to take out a lot of functionality, and I cannot understand why. Thanks!

      Show
      Noah Slater added a comment - Randall, I do not understand what your patch is doing. Could you explain what the problem is, and how your patch attempts to solve it. Why did the patch submitted by Duncan not work? What, exactly, is the problem here? Your patch seems to take out a lot of functionality, and I cannot understand why. Thanks!
      Hide
      Randall Leeds added a comment -

      Aha! I'll explain, in too much detail, why I did what I did in a moment. I see why you think I removed functionality, and that's just a quirk of how code moved interacting with my default diff settings. Here's a new patch that's identical except for having a different hunk context size for the diff.

      The patch passes the pid file option to the stop and status invocations as in Duncan's patch. The original patch uses the environment variable $COUCHDB_PID_FILE that's not currently used (documented) in the etc/default/couchdb in the source. However, the -p option, in order to pass to couchdb, can already be added to $COUCHDB_OPTIONS instead.

      Rather than expand the set of options, I rewrote the patch to pass $COUCHDB_OPTIONS to every invocation of couchdb. At that point, display_status, stop_couchdb, and start_couchdb all had code to add $COUCHDB_OPTIONS to the couchdb command line. Additionally, start_couchdb and stop_couchdb both set the user according to the environment. I took all these duplicate lines of command assembly and put them into a function called run_command.

      It's mostly equivalent to the original patch. It reduces LoC and fixes the problem while avoiding a new environment variable. I'll grant that it needlessly switches users for status (root could read a pid file), but it was late and I just got a twitch.

      Heh. That was a lot of justification for some diff context confusion. I think. Ow.

      Show
      Randall Leeds added a comment - Aha! I'll explain, in too much detail, why I did what I did in a moment. I see why you think I removed functionality, and that's just a quirk of how code moved interacting with my default diff settings. Here's a new patch that's identical except for having a different hunk context size for the diff. The patch passes the pid file option to the stop and status invocations as in Duncan's patch. The original patch uses the environment variable $COUCHDB_PID_FILE that's not currently used (documented) in the etc/default/couchdb in the source. However, the -p option, in order to pass to couchdb, can already be added to $COUCHDB_OPTIONS instead. Rather than expand the set of options, I rewrote the patch to pass $COUCHDB_OPTIONS to every invocation of couchdb. At that point, display_status, stop_couchdb, and start_couchdb all had code to add $COUCHDB_OPTIONS to the couchdb command line. Additionally, start_couchdb and stop_couchdb both set the user according to the environment. I took all these duplicate lines of command assembly and put them into a function called run_command. It's mostly equivalent to the original patch. It reduces LoC and fixes the problem while avoiding a new environment variable. I'll grant that it needlessly switches users for status (root could read a pid file), but it was late and I just got a twitch. Heh. That was a lot of justification for some diff context confusion. I think. Ow.
      Randall Leeds made changes -
      Randall Leeds made changes -
      Attachment 0001-always-pass-options-in-init-script-COUCHDB-128.patch [ 12469022 ]
      Hide
      Noah Slater added a comment -

      Looks good!

      Show
      Noah Slater added a comment - Looks good!
      Hide
      Randall Leeds added a comment -

      resolved in r1146997

      Show
      Randall Leeds added a comment - resolved in r1146997
      Randall Leeds made changes -
      Status Open [ 1 ] Closed [ 6 ]
      Fix Version/s 1.2 [ 12315198 ]
      Resolution Fixed [ 1 ]

        People

        • Assignee:
          Noah Slater
          Reporter:
          Noah Slater
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development