couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bogdan Andu <bog...@gmail.com>
Subject Re: CouchDB 2.0 start/stop dilemma
Date Fri, 14 Oct 2016 09:33:24 GMT
I see this topic does not appears important for community
but for me is important, and I want to share my solution to this
problem.

Maybe somebody will benefit from this.

First, I created a service unit in systemd:
$ cat /usr/lib/systemd/system/couchdb20.service
[Unit]
Description=Apache CouchDB Server 2.0
After=network.target

[Service]
User=_couchdb
Type=forking
Environment="HOME=/var/couchdb"
ExecStart="/home/andu/couchdb2.0/bin/couchdb"
#ExecReload=
ExecStop=/bin/kill -TERM $MAINPID

[Install]
WantedBy=multi-user.target

But this didn't start the server as expected because of
start script of couchdb: home/andu/couchdb2.0/bin/couchdb

I had to make minor modifications to this to work with systemd, namely:

$ cat /home/andu/couchdb2.0/bin/couchdb
#!/bin/sh

# Licensed under the Apache License, Version 2.0 (the "License"); you may
not
# use this file except in compliance with the License. You may obtain a
copy of
# the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
under
# the License.

COUCHDB_BIN_DIR=$(cd "${0%/*}" && pwd)
ERTS_BIN_DIR=$COUCHDB_BIN_DIR/../
cd "$COUCHDB_BIN_DIR/../"

export ROOTDIR=${ERTS_BIN_DIR%/*}

START_ERL=`cat "$ROOTDIR/releases/start_erl.data"`
ERTS_VSN=${START_ERL% *}
APP_VSN=${START_ERL#* }

export BINDIR="$ROOTDIR/erts-$ERTS_VSN/bin"
export EMU=beam
export PROGNAME=`echo $0 | sed 's/.*\///'`

exec "$BINDIR/erlexec" -boot "$ROOTDIR/releases/$APP_VSN/couchdb" \
     -args_file "$ROOTDIR/etc/vm.args" \
     -config "$ROOTDIR/releases/$APP_VSN/sys.config" &

exit 0

Without these modifications systemd cannot handle the Type=forking
correctly,
so the server cannot start.

Now one can start and stop the server with:
$ sudo systemctl start couchdb20
$ sudo systemctl stop couchdb20

or see the status:

$ sudo systemctl status couchdb20

/Bogdan

On Wed, Oct 12, 2016 at 1:14 PM, Bogdan Andu <bog495@gmail.com> wrote:

> Hi,
>
> I see Couch 2.0 comes with a free style start / stop mechanism
> and the user is encouraged to use runit or whatever mechanism
> he already has on his system.
>
> I do not want to use runit when I have modern systems like centos 7 or f
> edora 24 server editions that have systemd to start/stop couchdb 2.0 using
> a command like this:
> $ sudo systemctl status couchdb20
>
> Couch 2.0 does not make use of a pid file anymore .
> A pid file is usefull even for systemd-managed services
>
> Anyway I wrote a simple couchdb20.service unit file in systemd for this
> purpose.
>
> the status shows:
> $ sudo systemctl status couchdb20
> ● couchdb20.service - Apache CouchDB Server 2.0
>    Loaded: loaded (/usr/lib/systemd/system/couchdb20.service; disabled;
> vendor preset: disabled)
>    Active: active (running) since Wed 2016-10-12 12:24:20 EEST; 37min ago
>   Process: 7950 ExecStart=/home/andu/couchdb2.0/bin/couchdb (code=exited,
> status=0/SUCCESS)
>  Main PID: 7956 (beam.smp)
>     Tasks: 28 (limit: 512)
>    CGroup: /system.slice/couchdb20.service
>            ├─7956 /home/andu/couchdb2.0/bin/../erts-7.3.1/bin/beam.smp -K
> true -A 16 -Bd -- -root /home/andu/couchdb2.0/bin/.. -progname couchdb --
> -home /var/couchdb -- -boot /home/andu/couchdb2.0/bin/../releas
>            ├─7982 sh -s disksup
>            ├─7984 /home/andu/couchdb2.0/bin/../
> lib/os_mon-2.4/priv/bin/memsup
>            ├─7985 /home/andu/couchdb2.0/bin/../
> lib/os_mon-2.4/priv/bin/cpu_sup
>            ├─7986 inet_gethost 4
>            └─7987 inet_gethost 4
>
> Oct 12 12:24:20 nosql systemd[1]: Starting Apache CouchDB Server 2.0...
> Oct 12 12:24:20 nosql systemd[1]: Started Apache CouchDB Server 2.0.
>
> The script appears to work correctly.
> All processes a cleanly-shutdown when stopped.
>
> Do you think this is a sane approach to manage couch 2.0 ?
>
> /Bogdan
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message