summaryrefslogtreecommitdiff
path: root/databases/couchdb/files/couchdb.in
blob: 25b66e6043c762211629bf799ce9a18b7428d26f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

# $FreeBSD$
#
# PROVIDE: couchdb
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# couchdb_enable (bool):	Set to NO by default.
# 				Set it to YES to enable couchdb.
#
# couchdb_enablelogs (bool):	Set to YES by default.
#
# couchdb_etcdir (string):	In case you want another dir
# 				for default.ini/local.ini.
#
# couchdb_respawn (int):	Set to none by default. If CouchDB crashes,
# 				respawn after this many seconds.
#
# couchdb_erl_flags (string):	Set to none by default. Additional Erlang flags
# 				that are appended via ERL_ZFLAGS to the Erlang VM parameters.

. /etc/rc.subr

name="couchdb"
rcvar=couchdb_enable

load_rc_config $name

: ${couchdb_enable:="NO"}
couchdb_user="${couchdb_user:-"couchdb"}"
couchdb_enablelogs="${couchdb_enablelogs:-"YES"}"
couchdb_etcdir="${couchdb_etcdir:-"%%PREFIX%%/etc/couchdb"}"
couchdb_respawn="${couchdb_respawn:-"0"}"
couchdb_erl_flags="${couchdb_erl_flags:-""}"

command="%%PREFIX%%/bin/${name}"
pidfile="/var/run/${name}/${name}.pid"
urifile="/var/run/${name}/couch.uri"

command_args="-p ${pidfile} -b"

couchdb_prestart()
{
	install -o $couchdb_user /dev/null $pidfile
	install -o $couchdb_user /dev/null $urifile

	if [ -n "$couchdb_flags" ]; then
		case "$couchdb_flags" in
		*-[bp]*) err 1 'The -b and -p options should be removed from couchdb_flags' ;;
		esac
		return 0
	fi

	if [ $couchdb_respawn -gt 0 ]; then
		respawn="-r ${couchdb_respawn}"
	fi

	if checkyesno couchdb_enablelogs; then
		logfile=/var/log/${name}/couch.log
		errfile=/var/log/${name}/err.log
	else
		logfile=/dev/null
		errfile=/dev/null
	fi

	# couchdb supports passing options through to the erlang vm directly in
	# ERL_ZFLAGS which is appended to CouchDB own flags.
	ERL_ZFLAGS=${couchdb_erl_flags}
	export ERL_ZFLAGS

	command_args="-a ${couchdb_etcdir}/default.ini -a ${couchdb_etcdir}/local.ini ${respawn} -o ${logfile} -e ${errfile} ${command_args}"
}

start_precmd=${name}_prestart
stop_cmd="${command} -d"
status_cmd="${command} -s"

run_rc_command "$1"