How to properly start/stop CouchDB 2.0 on Ubuntu

3.4k views Asked by At

I have installed CouchDB 2.0 on Ubuntu 16.04, and can run it fine by launching ~couchdb/bin/couchdb.

Now I would like to make it start and stop properly on system boot/shutdown.

The doc states that daemonization scripts are no longer provided in 2.0, and I would like to avoid using runit.

I have tried to use start-stop-daemon, writing a shell-script (provided below if helpful). This way I can start CouchDB, but the stop does not work because no process have the name "couchdb" (everything is delegated to ERLang).

Moreover, when I update-rc.d couchdb.sh defaults I get an error insserv: warning: script 'couchdb.sh' missing LSB tags and overrides.

So how would you recommend to make a clean start/stop procedure? Many thanks!

#!/bin/sh -e

DAEMON="/home/couchdb/bin/couchdb" 
daemon_OPT=""  
DAEMONUSER="couchdb" 
daemon_NAME="couchdb" 
PATH="/sbin:/bin:/usr/sbin:/usr/bin" 

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

d_start () {
    log_daemon_msg "Starting system $daemon_NAME Daemon"
    start-stop-daemon --background --name $daemon_NAME --start --quiet --chuid $DAEMONUSER --exec $DAEMON -- $daemon_OPT
    log_end_msg $?
}

d_stop () {
    log_daemon_msg "Stopping system $daemon_NAME Daemon"
    start-stop-daemon --name $daemon_NAME --stop --retry 5 --quiet
    log_end_msg $?
}

case "$1" in

    start|stop)
        d_${1}
        ;;

    restart|reload|force-reload)
        d_stop
        d_start
        ;;

    force-stop)
        d_stop
        killall -q $daemon_NAME || true
        sleep 2
        killall -q -9 $daemon_NAME || true
        ;;

    status)
        status_of_proc "$daemon_NAME" "$DAEMON" "system-wide $daemon_NAME" && exit 0 || exit $?
        ;;
    *)
        echo "Usage: /etc/init.d/$daemon_NAME {start|stop|force-stop|restart|reload|force-reload|status}"
        exit 1
        ;;
esac
exit 0
2

There are 2 answers

0
star On

From here: https://www.jamescoyle.net/how-to/2527-add-systemd-startup-script-for-couchdb

# From: https://wiki.ubuntu.com/systemd
# This results in systemd being installed alongside upstart
apt-get -y install systemd libpam-systemd systemd-ui

# From: https://www.jamescoyle.net/how-to/2527-add-systemd-startup-script-for-couchdb ([Install] section is missing!)
# couchdb.service is a new file. Make it:
nano /etc/systemd/system/couchdb.service

--- file start (do not include this line) ---
[Unit]
Description=Couchdb service
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/opt/couchdb/bin/couchdb -o /dev/stdout -e /dev/stderr
Restart=always

[Install]
WantedBy=multi-user.target
--- file end (do not include this line) ---

# This enables CouchDB automatically after reboot
systemctl  daemon-reload
systemctl  start couchdb.service
systemctl  enable couchdb.service

# Logging: see more about journalctl elsewhere. This shows the latest 500 logs.
journalctl -u couchdb.service | tail -n 500

# *** update the configuration file, see above example of a configuration of local.ini ***
service couchdb stop
# update local.ini
service couchdb start
0
smasper On

ubuntu 16.04 LTS / couchdb v2.1.0
sudo service couchdb stop
and
sudo service couchdb start