1

我已经在 Ubuntu 16.04 上安装了 CouchDB 2.0,并且可以通过启动 ~couchdb/bin/couchdb 来正常运行它。

现在我想让它在系统启动/关闭时正确启动和停止。

该文档指出 2.0 中不再提供守护程序脚本,我想避免使用runit.

我尝试使用start-stop-daemon,编写一个 shell 脚本(如果有帮助,请在下面提供)。这样我可以start使用 CouchDB,但stop它不起作用,因为没有进程名称为“couchdb”(一切都委托给 ERLang)。

此外,当我 update-rc.d couchdb.sh defaults收到错误消息时insserv: warning: script 'couchdb.sh' missing LSB tags and overrides

那么你会如何推荐一个干净的启动/停止程序呢?非常感谢!

#!/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
4

2 回答 2

0

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

sudo service couchdb start

于 2017-11-03T23:22:58.277 回答
0

从这里: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
于 2017-02-22T16:46:15.833 回答