Permalink
Browse files

add release example & README

  • Loading branch information...
1 parent b6cbc0e commit 0705b1f82124c28f885131430dcf6942cfc8fdda @benoitc benoitc committed Mar 22, 2012
View
11 .gitignore
@@ -18,10 +18,7 @@ build-aux
*.dSYM
*.sw*
*.gz
-
-# relase
-rel/couch
-dev
+*.beam
# couch
apps/couch/couchjs
@@ -32,7 +29,11 @@ apps/couch/priv/couchspawnkillable
apps/couch/libs
apps/couch/share/server/main.js
apps/couch/share/server/main-coffee.js
+apps/couch_index/ebin
+apps/couch_replicator/ebin
+apps/couch_mrview/ebin
+apps/couch_changes/ebin
# other
deps
-ebin
+ebin/*.beam
View
15 LICENSE
@@ -0,0 +1,15 @@
+2011 (c) Benoît Chesneau <benoitc@e-engura.org>
+2011 (c) Nicolas R Dufour <nrdufour@gmail.com>
+
+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.
+
View
17 NOTICE
@@ -0,0 +1,17 @@
+refuge
+------
+
+2011 (c) Benoît Chesneau <benoitc@e-engura.org>
+2011 (c) Nicolas R Dufour <nrdufour@gmail.com>
+
+refuge is released under the Apache 2 license. See the LICENSE file for
+the complete license.
+
+third parties attributions
+--------------------------
+
+- packages/*
+ under Apache 2 license
+ 2010 (c) Basho Technologies
+
+
View
68 README.md
@@ -0,0 +1,68 @@
+couch_core
+----------
+
+couch_core is a static distribution of couchdb using rebar. It aims to be
+embed in your applications or be part of custom distribution of couchdb.
+
+couch_core is brought you by the [Refugre project](http://refuge.io)/
+
+Based on the couchdb code it is tagged from time to time for stability
+purpose. At some point some supported branch may appear.
+
+couch_core differs from refuge by only focusing on Apache CouchDB. It won't
+contain any of the refuge features like P2P nodes handling, ... .
+Internally we are using it to test couchdb and as an example on how to
+embed couchdb in your own applications. A working release example is
+provided.
+
+## Features:
+
+- Apache CouchDB based
+- rebar
+- relocatable
+- Fully opensource. All the sources are on refuge GIT repository
+ (http://github.com/refuge) under Apache License 2.
+
+## Requirements
+
+- OS supported: Linux, OSX, BSDs (windows support is coming)
+- Erlang R14
+- Curl
+- ICU (if not built statically)
+- Latest version of [rebar](http://github.com/basho/rebar) installed on
+ your system.
+
+An example of release file is provided in the `example` folder.
+
+
+##Notes on building a truly distributable package
+
+The package built above will still depend on some libraries from your
+system, so additional work has to be done to distribute it to
+older/newer systems.
+
+1. CouchDB will depend on the ICU library version that was present in
+ your system at build time. To easily bundle this library with the
+ package, build with:
+
+ $ make rel USE_STATIC_ICU=1
+
+1. Check whether your package depends on Ncurses:
+
+ $ ldd ./rel/couch/erts-*/bin/erlexec|grep ncurses
+
+ If it does, copy the .so file to ./rel/myapp/lib/ or rebuild Erlang
+ without this dependency.
+
+1. Decide whether you need SSL support in your package and check whether it
+ depends on OpenSSL:
+
+ $ ldd ./rel/couch/lib/ssl-*/priv/bin/ssl_esock|grep 'libcrypto\|libssl'
+
+ If it does, copy the .so file to ./rel/couch/lib/ or rebuild Erlang
+ without this dependency.
+
+If you copied any .so files in the last 2 steps, run this command, so
+that your app can find the libraries:
+
+ $ sed -i '/^RUNNER_USER=/a\\nexport LD_LIBRARY_PATH="$RUNNER_BASE_DIR/lib"' ./rel/couch/bin/couch
View
11 apps/couch_index/rebar.config
@@ -1,11 +0,0 @@
-%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ft=erlang ts=4 sw=4 et
-
-{cover_enabled, true}.
-{eunit_opts, [{report,{eunit_surefire,[{dir,"."}]}}]}.
-{erl_opts, [debug_info]}.
-{require_otp_vsn, "R14|R15"}.
-
-{deps, [
- {couch, ".*", {git, "git://github.com/refuge/couch.git", "master"}}
-]}.
View
11 apps/couch_mrview/rebar.config
@@ -1,11 +0,0 @@
-%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ft=erlang ts=4 sw=4 et
-
-{cover_enabled, true}.
-{eunit_opts, [{report,{eunit_surefire,[{dir,"."}]}}]}.
-{erl_opts, [debug_info]}.
-{require_otp_vsn, "R14|R15"}.
-
-{deps, [
- {couch_index, ".*", {git, "git://github.com/benoitc/couch_index.git", "master"}}
-]}.
View
11 apps/couch_replicator/rebar.config
@@ -1,11 +0,0 @@
-%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ft=erlang ts=4 sw=4 et
-
-{cover_enabled, true}.
-{eunit_opts, [{report,{eunit_surefire,[{dir,"."}]}}]}.
-{erl_opts, [debug_info]}.
-{require_otp_vsn, "R14|R15"}.
-
-{deps, [
- {couch, ".*", {git, "git://github.com/refuge/couch.git", "master"}}
-]}.
View
5 ebin/couch_core.app
@@ -0,0 +1,5 @@
+{application, couch_core, [
+ {vsn, "0.1"},
+ {description, "CouchDB core."},
+ {modules, []}
+]}.
View
33 example/rel/couch.config
@@ -0,0 +1,33 @@
+%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
+
+%% Platform-specific installation paths
+{platform_bin_dir, "./bin"}.
+{platform_data_dir, "./data"}.
+{platform_view_dir, "./data"}.
+{platform_etc_dir, "./etc"}.
+{platform_lib_dir, "./lib"}.
+{platform_log_dir, "./log"}.
+{platform_run_dir, "./run"}.
+{platform_share_dir, "./share"}.
+
+%% vendor info
+{vendor_name, "refuge"}.
+
+%% app config
+{couchdb_ip, "127.0.0.1"}.
+{couchdb_port, 5984}.
+{ssl_port, 6986}.
+{sasl_error_log, "log/sasl-error.log"}.
+{sasl_log_dir, "log/sasl"}.
+
+%% node
+{node, "couch@127.0.0.1"}.
+{crash_dump, "log/erl_crash.dump"}.
+
+{runner_script_dir, "$(cd ${0%/*} && pwd)"}.
+{runner_base_dir, "${RUNNER_SCRIPT_DIR%/*}"}.
+{runner_etc_dir, "$RUNNER_BASE_DIR/etc"}.
+{runner_log_dir, "$RUNNER_BASE_DIR/log"}.
+{pipe_dir, "/tmp/$RUNNER_BASE_DIR/"}.
+{runner_user, ""}.
View
27 example/rel/files/app.config
@@ -0,0 +1,27 @@
+%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
+
+[
+
+ {couch, [
+ {config_dir, "{{platform_etc_dir}}"}
+ ]},
+
+ %% os_mon config
+ {os_mon, [
+ {start_memsup, false},
+ {start_cpu_sup, false},
+ {disk_space_check_interval, 1},
+ {disk_almost_full_thresold, 1}
+ ]},
+
+ %% SASL config
+ {sasl, [
+ {sasl_error_logger, {file, "{{sasl_error_log}}"}},
+ {errlog_type, error},
+ {error_logger_mf_dir, "{{sasl_log_dir}}"}, % Log directory
+ {error_logger_mf_maxbytes, 10485760}, % 10 MB max file size
+ {error_logger_mf_maxfiles, 5} % 5 files max
+ ]}
+].
+
View
231 example/rel/files/couch
@@ -0,0 +1,231 @@
+#!/bin/sh
+# -*- tab-width:4;indent-tabs-mode:nil -*-
+# ex: ts=4 sw=4 et
+
+RUNNER_SCRIPT_DIR={{runner_script_dir}}
+RUNNER_SCRIPT=${0##*/}
+
+RUNNER_BASE_DIR={{runner_base_dir}}
+RUNNER_ETC_DIR={{runner_etc_dir}}
+RUNNER_LOG_DIR={{runner_log_dir}}
+PIPE_DIR={{pipe_dir}}
+RUNNER_USER={{runner_user}}
+
+# Make sure this script is running as the appropriate user
+if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
+ exec sudo -u $RUNNER_USER -i $0 $@
+fi
+
+# Make sure CWD is set to runner base dir
+cd $RUNNER_BASE_DIR
+
+# Make sure log directory exists
+mkdir -p $RUNNER_LOG_DIR
+
+# Extract the target node name from node.args
+NAME_ARG=`egrep '^-s?name' $RUNNER_ETC_DIR/vm.args`
+if [ -z "$NAME_ARG" ]; then
+ echo "vm.args needs to have either -name or -sname parameter."
+ exit 1
+fi
+
+# Extract the target cookie
+COOKIE_ARG=`grep '^-setcookie' $RUNNER_ETC_DIR/vm.args`
+if [ -z "$COOKIE_ARG" ]; then
+ echo "vm.args needs to have a -setcookie parameter."
+ exit 1
+fi
+
+# Identify the script name
+SCRIPT=`basename $0`
+
+# Parse out release and erts info
+START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
+ERTS_VSN=${START_ERL% *}
+APP_VSN=${START_ERL#* }
+
+# Add ERTS bin dir to our path
+ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
+
+# Setup command to control the node
+NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
+
+# Check the first argument for instructions
+case "$1" in
+ start)
+ # Make sure there is not already a node running
+ RES=`$NODETOOL ping`
+ if [ "$RES" = "pong" ]; then
+ echo "Node is already running!"
+ exit 1
+ fi
+ HEART_COMMAND="$RUNNER_SCRIPT_DIR/$SCRIPT start"
+ export HEART_COMMAND
+ mkdir -p $PIPE_DIR
+ $ERTS_PATH/run_erl -daemon $PIPE_DIR/ $RUNNER_LOG_DIR \
+ "exec $RUNNER_SCRIPT_DIR/$SCRIPT console" 2>&1
+
+
+ WAIT=${WAIT_FOR_ERLANG:-15}
+ while [ $WAIT -gt 0 ]; do
+ WAIT=`expr $WAIT - 1`
+ sleep 1
+ RES=`$NODETOOL ping`
+ if [ "$?" -ne 0 ]; then
+ continue
+ fi
+ NODEWATCHER=`$NODETOOL rpcterms erlang whereis "'couch_server'."`
+ if [ "$NODEWATCHER" != "undefined" ]; then
+ exit 0
+ fi
+ done
+ echo "rcouch failed to start within ${WAIT_FOR_ERLANG:-15} seconds."
+ echo "If you want to wait longer, set the environment variable"
+ echo "WAIT_FOR_ERLANG to the number of seconds to wait."
+ exit 1
+ ;;
+ start_front)
+ # Make sure there is not already a node running
+ RES=`$NODETOOL ping`
+ if [ "$RES" = "pong" ]; then
+ echo "Node is already running!"
+ exit 1
+ fi
+
+
+ # Setup beam-required vars
+ ROOTDIR=$RUNNER_BASE_DIR
+ BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+ EMU=beam
+ PROGNAME=`echo $0 | sed 's/.*\\///'`
+ CMD="$BINDIR/erlexec -boot
+ $RUNNER_BASE_DIR/releases/$APP_VSN/$SCRIPT -Bd -noinput \
+ -embedded -config $RUNNER_ETC_DIR/app.config \
+ -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
+ export EMU
+ export ROOTDIR
+ export BINDIR
+ export PROGNAME
+
+ # Log the startup
+ logger -t "$SCRIPT[$$]" "Starting up"
+
+ # Start the VM
+ exec $CMD
+ ;;
+ stop)
+ # Wait for the node to completely stop...
+ case `uname -s` in
+ Linux|Darwin|FreeBSD|DragonFly|NetBSD|OpenBSD)
+ # PID COMMAND
+ PID=`ps ax -o pid= -o command=|\
+ grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $1}'`
+ ;;
+ SunOS)
+ # PID COMMAND
+ PID=`ps -ef -o pid= -o args=|\
+ grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $1}'`
+ ;;
+ CYGWIN*)
+ # UID PID PPID TTY STIME COMMAND
+ PID=`ps -efW|grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $2}'`
+ ;;
+ esac
+ $NODETOOL stop
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
+ while `kill -0 $PID 2>/dev/null`;
+ do
+ sleep 1
+ done
+ ;;
+
+ restart)
+ ## Restart the VM without exiting the process
+ $NODETOOL restart
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
+ ;;
+
+ reboot)
+ ## Restart the VM completely (uses heart to restart it)
+ $NODETOOL reboot
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
+ ;;
+
+ ping)
+ ## See if the VM is alive
+ $NODETOOL ping
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
+ ;;
+
+ attach)
+ # Make sure a node IS running
+ RES=`$NODETOOL ping`
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ echo "Node is not running!"
+ exit $ES
+ fi
+
+ shift
+ exec $ERTS_PATH/to_erl $PIPE_DIR
+ ;;
+
+ console|console_clean)
+
+ RES=`$NODETOOL ping`
+ if [ "$RES" = "pong" ]; then
+ echo "Node is already running - use '$SCRIPT attach' instead"
+ exit 1
+ fi
+
+ # .boot file typically just $SCRIPT (ie, the app name)
+ # however, for debugging, sometimes start_clean.boot is useful:
+ case "$1" in
+ console) BOOTFILE=$SCRIPT ;;
+ console_clean) BOOTFILE=start_clean ;;
+ esac
+
+ # Setup beam-required vars
+ ROOTDIR=$RUNNER_BASE_DIR
+ BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+ EMU=beam
+ PROGNAME=`echo $0 | sed 's/.*\\///'`
+ CMD="$BINDIR/erlexec -boot
+ $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE \
+ -embedded -config $RUNNER_ETC_DIR/app.config \
+ -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
+ export EMU
+ export ROOTDIR
+ export BINDIR
+ export PROGNAME
+
+ # Dump environment info for logging purposes
+ echo "Exec: $CMD"
+ echo "Root: $ROOTDIR"
+
+ # Log the startup
+ logger -t "$SCRIPT[$$]" "Starting up"
+
+ # Start the VM
+ exec $CMD
+ ;;
+
+ *)
+ echo "Usage: $SCRIPT {start|start_front|stop|restart|reboot|ping|console|console_clean|attach}"
+ exit 1
+ ;;
+esac
+
+exit 0
View
309 example/rel/files/default.ini
@@ -0,0 +1,309 @@
+; @configure_input@
+
+; Upgrading CouchDB will overwrite this file.
+[vendor]
+name = {{vendor_name}}
+version = {{rel_vsn}}
+
+[couchdb]
+database_dir = {{platform_data_dir}}
+index_dir = {{platform_view_dir}}
+max_document_size = 4294967296 ; 4 GB
+os_process_timeout = 5000 ; 5 seconds. for view and external servers.
+max_dbs_open = 100
+delayed_commits = true ; set this to false to ensure an fsync before 201 Created is returned
+uri_file = {{platform_run_dir}}/couch.uri
+; Method used to compress everything that is appended to database and view index files, except
+; for attachments (see the attachments section). Available methods are:
+;
+; none - no compression
+; snappy - use google snappy, a very fast compressor/decompressor
+; deflate_[N] - use zlib's deflate, N is the compression level which ranges from 1 (fastest,
+; lowest compression ratio) to 9 (slowest, highest compression ratio)
+file_compression = snappy
+
+[database_compaction]
+; larger buffer sizes can originate smaller files
+doc_buffer_size = 524288 ; value in bytes
+checkpoint_after = 5242880 ; checkpoint after every N bytes were written
+
+[view_compaction]
+; larger buffer sizes can originate smaller files
+keyvalue_buffer_size = 2097152 ; value in bytes
+
+[httpd]
+port = {{couchdb_port}}
+bind_address = {{couchdb_ip}}
+authentication_handlers = {couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
+default_handler = {couch_httpd_db, handle_request}
+secure_rewrites = true
+vhost_global_handlers = _utils, _uuids, _session, _oauth, _users
+allow_jsonp = false
+; Options for the MochiWeb HTTP server.
+;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
+; For more socket options, consult Erlang's module 'inet' man page.
+;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
+log_max_chunk_size = 1000000
+
+[ssl]
+port = {{ssl_port}}
+
+[log]
+file = {{platform_log_dir}}/couch.log
+level = info
+include_sasl = true
+
+[couch_httpd_auth]
+authentication_db = _users
+authentication_redirect = /_utils/session.html
+require_valid_user = false
+timeout = 600 ; number of seconds before automatic logout
+auth_cache_size = 50 ; size is number of cache entries
+
+[couch_httpd_oauth]
+; If set to 'true', oauth token and consumer secrets will be looked up
+; in the authentication database (_users). These secrets are stored in
+; a top level property named "oauth" in user documents. Example:
+; {
+; "_id": "org.couchdb.user:joe",
+; "type": "user",
+; "name": "joe",
+; "password_sha": "fe95df1ca59a9b567bdca5cbaf8412abd6e06121",
+; "salt": "4e170ffeb6f34daecfd814dfb4001a73"
+; "roles": ["foo", "bar"],
+; "oauth": {
+; "consumer_keys": {
+; "consumerKey1": "key1Secret",
+; "consumerKey2": "key2Secret"
+; },
+; "tokens": {
+; "token1": "token1Secret",
+; "token2": "token2Secret"
+; }
+; }
+; }
+use_users_db = false
+
+[query_servers]
+javascript = {{platform_bin_dir}}/couchjs {{platform_share_dir}}/server/main.js
+coffeescript = {{platform_bin_dir}}/couchjs {{platform_share_dir}}/server/main-coffee.js
+
+
+; Changing reduce_limit to false will disable reduce_limit.
+; If you think you're hitting reduce_limit with a "good" reduce function,
+; please let us know on the mailing list so we can fine tune the heuristic.
+[query_server_config]
+reduce_limit = true
+os_process_limit = 25
+
+[daemons]
+index_server={couch_index_server, start_link, []}
+external_manager={couch_external_manager, start_link, []}
+query_servers={couch_query_servers, start_link, []}
+vhosts={couch_httpd_vhost, start_link, []}
+httpd={couch_httpd, start_link, []}
+stats_aggregator={couch_stats_aggregator, start, []}
+stats_collector={couch_stats_collector, start, []}
+uuids={couch_uuids, start, []}
+auth_cache={couch_auth_cache, start_link, []}
+os_daemons={couch_os_daemons, start_link, []}
+compaction_daemon={couch_compaction_daemon, start_link, []}
+
+
+[httpd_global_handlers]
+/ = {couch_httpd_misc_handlers, handle_welcome_req, <<"Welcome">>}
+favicon.ico = {couch_httpd_misc_handlers, handle_favicon_req, "{{platform_share_dir}}/www"}
+
+_utils = {couch_httpd_misc_handlers, handle_utils_dir_req, "{{platform_share_dir}}/www"}
+_all_dbs = {couch_httpd_misc_handlers, handle_all_dbs_req}
+_active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
+_config = {couch_httpd_misc_handlers, handle_config_req}
+_replicate = {couch_replicator_httpd, handle_req}
+_uuids = {couch_httpd_misc_handlers, handle_uuids_req}
+_restart = {couch_httpd_misc_handlers, handle_restart_req}
+_stats = {couch_httpd_stats_handlers, handle_stats_req}
+_log = {couch_httpd_misc_handlers, handle_log_req}
+_session = {couch_httpd_auth, handle_session_req}
+_oauth = {couch_httpd_oauth, handle_oauth_req}
+
+[httpd_db_handlers]
+_all_docs = {couch_mrview_http, handle_all_docs_req}
+_changes = {couch_httpd_changes, handle_changes_req}
+_compact = {couch_httpd_db, handle_compact_req}
+_design = {couch_httpd_db, handle_design_req}
+_temp_view = {couch_mrview_http, handle_temp_view_req}
+_view_cleanup = {couch_mrview_http, handle_cleanup_req}
+
+; The external module takes an optional argument allowing you to narrow it to a
+; single script. Otherwise the script name is inferred from the first path section
+; after _external's own path.
+; _mypath = {couch_httpd_external, handle_external_req, <<"mykey">>}
+; _external = {couch_httpd_external, handle_external_req}
+
+[httpd_design_handlers]
+_compact = {couch_mrview_http, handle_compact_req}
+_info = {couch_mrview_http, handle_info_req}
+_list = {couch_mrview_show, handle_view_list_req}
+_rewrite = {couch_httpd_rewrite, handle_rewrite_req}
+_show = {couch_mrview_show, handle_doc_show_req}
+_update = {couch_mrview_show, handle_doc_update_req}
+_view = {couch_mrview_http, handle_view_req}
+
+; enable external as an httpd handler, then link it with commands here.
+; note, this api is still under consideration.
+; [external]
+; mykey = /path/to/mycommand
+
+; Here you can setup commands for CouchDB to manage
+; while it is alive. It will attempt to keep each command
+; alive if it exits.
+; [os_daemons]
+; some_daemon_name = /path/to/script -with args
+
+
+[uuids]
+; Known algorithms:
+; random - 128 bits of random awesome
+; All awesome, all the time.
+; sequential - monotonically increasing ids with random increments
+; First 26 hex characters are random. Last 6 increment in
+; random amounts until an overflow occurs. On overflow, the
+; random prefix is regenerated and the process starts over.
+; utc_random - Time since Jan 1, 1970 UTC with microseconds
+; First 14 characters are the time in hex. Last 18 are random.
+algorithm = sequential
+
+[stats]
+; rate is in milliseconds
+rate = 1000
+; sample intervals are in seconds
+samples = [0, 60, 300, 900]
+
+[attachments]
+compression_level = 8 ; from 1 (lowest, fastest) to 9 (highest, slowest), 0 to disable compression
+compressible_types = text/*, application/javascript, application/json, application/xml
+
+[replicator]
+db = _replicator
+; Maximum replicaton retry count can be a non-negative integer or "infinity".
+max_replication_retry_count = 10
+; More worker processes can give higher network throughput but can also
+; imply more disk and network IO.
+worker_processes = 4
+; With lower batch sizes checkpoints are done more frequently. Lower batch sizes
+; also reduce the total amount of used RAM memory.
+worker_batch_size = 500
+; Maximum number of HTTP connections per replication.
+http_connections = 20
+; HTTP connection timeout per replication.
+; Even for very fast/reliable networks it might need to be increased if a remote
+; database is too busy.
+connection_timeout = 30000
+; If a request fails, the replicator will retry it up to N times.
+retries_per_request = 10
+; Some socket options that might boost performance in some scenarios:
+; {nodelay, boolean()}
+; {sndbuf, integer()}
+; {recbuf, integer()}
+; {priority, integer()}
+; See the `inet` Erlang module's man page for the full list of options.
+socket_options = [{keepalive, true}, {nodelay, false}]
+; Path to a file containing the user's certificate.
+;cert_file = /full/path/to/server_cert.pem
+; Path to file containing user's private PEM encoded key.
+;key_file = /full/path/to/server_key.pem
+; String containing the user's password. Only used if the private keyfile is password protected.
+;password = somepassword
+; Set to true to validate peer certificates.
+verify_ssl_certificates = false
+; File containing a list of peer trusted certificates (in the PEM format).
+;ssl_trusted_certificates_file = /etc/ssl/certs/ca-certificates.crt
+; Maximum peer certificate depth (must be set even if certificate validation is off).
+ssl_certificate_max_depth = 3
+
+[compaction_daemon]
+; The delay, in seconds, between each check for which database and view indexes
+; need to be compacted.
+check_interval = 300
+; If a database or view index file is smaller then this value (in bytes),
+; compaction will not happen. Very small files always have a very high
+; fragmentation therefore it's not worth to compact them.
+min_file_size = 131072
+
+[compactions]
+; List of compaction rules for the compaction daemon.
+; The daemon compacts databases and their respective view groups when all the
+; condition parameters are satisfied. Configuration can be per database or
+; global, and it has the following format:
+;
+; database_name = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ... ]
+; _default = [ {ParamName, ParamValue}, {ParamName, ParamValue}, ... ]
+;
+; Possible parameters:
+;
+; * db_fragmentation - If the ratio (as an integer percentage), of the amount
+; of old data (and its supporting metadata) over the database
+; file size is equal to or greater then this value, this
+; database compaction condition is satisfied.
+; This value is computed as:
+;
+; (file_size - data_size) / file_size * 100
+;
+; The data_size and file_size values can be obtained when
+; querying a database's information URI (GET /dbname/).
+;
+; * view_fragmentation - If the ratio (as an integer percentage), of the amount
+; of old data (and its supporting metadata) over the view
+; index (view group) file size is equal to or greater then
+; this value, then this view index compaction condition is
+; satisfied. This value is computed as:
+;
+; (file_size - data_size) / file_size * 100
+;
+; The data_size and file_size values can be obtained when
+; querying a view group's information URI
+; (GET /dbname/_design/groupname/_info).
+;
+; * from _and_ to - The period for which a database (and its view groups) compaction
+; is allowed. The value for these parameters must obey the format:
+;
+; HH:MM - HH:MM (HH in [0..23], MM in [0..59])
+;
+; * strict_window - If a compaction is still running after the end of the allowed
+; period, it will be canceled if this parameter is set to 'true'.
+; It defaults to 'false' and it's meaningful only if the *period*
+; parameter is also specified.
+;
+; * parallel_view_compaction - If set to 'true', the database and its views are
+; compacted in parallel. This is only useful on
+; certain setups, like for example when the database
+; and view index directories point to different
+; disks. It defaults to 'false'.
+;
+; Before a compaction is triggered, an estimation of how much free disk space is
+; needed is computed. This estimation corresponds to 2 times the data size of
+; the database or view index. When there's not enough free disk space to compact
+; a particular database or view index, a warning message is logged.
+;
+; Examples:
+;
+; 1) [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}]
+; The `foo` database is compacted if its fragmentation is 70% or more.
+; Any view index of this database is compacted only if its fragmentation
+; is 60% or more.
+;
+; 2) [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}]
+; Similar to the preceding example but a compaction (database or view index)
+; is only triggered if the current time is between midnight and 4 AM.
+;
+; 3) [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}]
+; Similar to the preceding example - a compaction (database or view index)
+; is only triggered if the current time is between midnight and 4 AM. If at
+; 4 AM the database or one of its views is still compacting, the compaction
+; process will be canceled.
+;
+; 4) [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "00:00"}, {to, "04:00"}, {strict_window, true}, {parallel_view_compaction, true}]
+; Similar to the preceding example, but a database and its views can be
+; compacted in parallel.
+;
+;_default = [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {from, "23:00"}, {to, "04:00"}]
View
34 example/rel/files/erl
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+## This script replaces the default "erl" in erts-VSN/bin. This is necessary
+## as escript depends on erl and in turn, erl depends on having access to a
+## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect
+## of running escript -- the embedded node bypasses erl and uses erlexec directly
+## (as it should).
+##
+## Note that this script makes the assumption that there is a start_clean.boot
+## file available in $ROOTDIR/release/VSN.
+
+# Determine the abspath of where this script is executing from.
+ERTS_BIN_DIR=$(cd ${0%/*} && pwd)
+
+# Now determine the root directory -- this script runs from erts-VSN/bin,
+# so we simply need to strip off two dirs from the end of the ERTS_BIN_DIR
+# path.
+ROOTDIR=${ERTS_BIN_DIR%/*/*}
+
+# Parse out release and erts info
+START_ERL=`cat $ROOTDIR/releases/start_erl.data`
+ERTS_VSN=${START_ERL% *}
+APP_VSN=${START_ERL#* }
+
+BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+EMU=beam
+PROGNAME=`echo $0 | sed 's/.*\\///'`
+CMD="$BINDIR/erlexec"
+export EMU
+export ROOTDIR
+export BINDIR
+export PROGNAME
+
+exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}
View
85 example/rel/files/local.ini
@@ -0,0 +1,85 @@
+; CouchDB Configuration Settings
+
+; Custom settings should be made in this file. They will override settings
+; in default.ini, but unlike changes made to default.ini, this file won't be
+; overwritten on server upgrade.
+
+[couchdb]
+;max_document_size = 4294967296 ; bytes
+
+[httpd]
+;port = 5984
+;bind_address = 127.0.0.1
+; Options for the MochiWeb HTTP server.
+;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
+; For more socket options, consult Erlang's module 'inet' man page.
+;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
+
+; Uncomment next line to trigger basic-auth popup on unauthorized requests.
+;WWW-Authenticate = Basic realm="administrator"
+
+; Uncomment next line to set the configuration modification whitelist. Only
+; whitelisted values may be changed via the /_config URLs. To allow the admin
+; to change this value over HTTP, remember to include {httpd,config_whitelist}
+; itself. Excluding it from the list would require editing this file to update
+; the whitelist.
+;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
+
+[httpd_global_handlers]
+;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}
+
+[couch_httpd_auth]
+; If you set this to true, you should also uncomment the WWW-Authenticate line
+; above. If you don't configure a WWW-Authenticate header, CouchDB will send
+; Basic realm="server" in order to prevent you getting logged out.
+; require_valid_user = false
+
+[log]
+;level = debug
+
+[os_daemons]
+; For any commands listed here, CouchDB will attempt to ensure that
+; the process remains alive. Daemons should monitor their environment
+; to know when to exit. This can most easily be accomplished by exiting
+; when stdin is closed.
+;foo = /path/to/command -with args
+
+[daemons]
+; enable SSL support by uncommenting the following line and supply the PEM's below.
+; the default ssl port CouchDB listens on is 6984
+; httpsd = {couch_httpd, start_link, [https]}
+
+[ssl]
+;cert_file = /full/path/to/server_cert.pem
+;key_file = /full/path/to/server_key.pem
+;password = somepassword
+; set to true to validate peer certificates
+verify_ssl_certificates = false
+; Path to file containing PEM encoded CA certificates (trusted
+; certificates used for verifying a peer certificate). May be omitted if
+; you do not want to verify the peer.
+;cacert_file = /full/path/to/cacertf
+; The verification fun (optionnal) if not specidied, the default
+; verification fun will be used.
+;verify_fun = {Module, VerifyFun}
+ssl_certificate_max_depth = 1
+; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
+; the Virual Host will be redirected to the path. In the example below all requests
+; to http://example.com/ are redirected to /database.
+; If you run CouchDB on a specific port, include the port number in the vhost:
+; example.com:5984 = /database
+
+[vhosts]
+;example.com = /database/
+
+[update_notification]
+;unique notifier name=/full/path/to/exe -with "cmd line arg"
+
+; To create an admin account uncomment the '[admins]' section below and add a
+; line in the format 'username = password'. When you next start CouchDB, it
+; will change the password to a hash (so that your passwords don't linger
+; around in plain-text files). You can add more admin accounts with more
+; 'username = password' lines. Don't forget to restart CouchDB after
+; changing this.
+[admins]
+;admin = mysecretpassword
View
138 example/rel/files/nodetool
@@ -0,0 +1,138 @@
+%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
+%% -------------------------------------------------------------------
+%%
+%% nodetool: Helper Script for interacting with live nodes
+%%
+%% -------------------------------------------------------------------
+
+main(Args) ->
+ ok = start_epmd(),
+ %% Extract the args
+ {RestArgs, TargetNode} = process_args(Args, [], undefined),
+
+ %% See if the node is currently running -- if it's not, we'll bail
+ case {net_kernel:hidden_connect_node(TargetNode), net_adm:ping(TargetNode)} of
+ {true, pong} ->
+ ok;
+ {_, pang} ->
+ io:format("Node ~p not responding to pings.\n", [TargetNode]),
+ halt(1)
+ end,
+
+ case RestArgs of
+ ["ping"] ->
+ %% If we got this far, the node already responsed to a ping, so just dump
+ %% a "pong"
+ io:format("pong\n");
+ ["stop"] ->
+ io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]);
+ ["restart"] ->
+ io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]);
+ ["reboot"] ->
+ io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]);
+ ["rpc", Module, Function | RpcArgs] ->
+ case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function),
+ [RpcArgs], 60000) of
+ ok ->
+ ok;
+ {badrpc, Reason} ->
+ io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
+ halt(1);
+ _ ->
+ halt(1)
+ end;
+ ["rpcterms", Module, Function, ArgsAsString] ->
+ case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function),
+ consult(ArgsAsString), 60000) of
+ {badrpc, Reason} ->
+ io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
+ halt(1);
+ Other ->
+ io:format("~p\n", [Other])
+ end;
+ Other ->
+ io:format("Other: ~p\n", [Other]),
+ io:format("Usage: nodetool {ping|stop|restart|reboot}\n")
+ end,
+ net_kernel:stop().
+
+process_args([], Acc, TargetNode) ->
+ {lists:reverse(Acc), TargetNode};
+process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) ->
+ erlang:set_cookie(node(), list_to_atom(Cookie)),
+ process_args(Rest, Acc, TargetNode);
+process_args(["-name", TargetName | Rest], Acc, _) ->
+ ThisNode = append_node_suffix(TargetName, "_maint_"),
+ {ok, _} = net_kernel:start([ThisNode, longnames]),
+ process_args(Rest, Acc, nodename(TargetName));
+process_args(["-sname", TargetName | Rest], Acc, _) ->
+ ThisNode = append_node_suffix(TargetName, "_maint_"),
+ {ok, _} = net_kernel:start([ThisNode, shortnames]),
+ process_args(Rest, Acc, nodename(TargetName));
+process_args([Arg | Rest], Acc, Opts) ->
+ process_args(Rest, [Arg | Acc], Opts).
+
+
+start_epmd() ->
+ [] = os:cmd(epmd_path() ++ " -daemon"),
+ ok.
+
+epmd_path() ->
+ ErtsBinDir = filename:dirname(escript:script_name()),
+ Name = "epmd",
+ case os:find_executable(Name, ErtsBinDir) of
+ false ->
+ case os:find_executable(Name) of
+ false ->
+ io:format("Could not find epmd.~n"),
+ halt(1);
+ GlobalEpmd ->
+ GlobalEpmd
+ end;
+ Epmd ->
+ Epmd
+ end.
+
+
+nodename(Name) ->
+ case string:tokens(Name, "@") of
+ [_Node, _Host] ->
+ list_to_atom(Name);
+ [Node] ->
+ [_, Host] = string:tokens(atom_to_list(node()), "@"),
+ list_to_atom(lists:concat([Node, "@", Host]))
+ end.
+
+append_node_suffix(Name, Suffix) ->
+ case string:tokens(Name, "@") of
+ [Node, Host] ->
+ list_to_atom(lists:concat([Node, Suffix, os:getpid(), "@", Host]));
+ [Node] ->
+ list_to_atom(lists:concat([Node, Suffix, os:getpid()]))
+ end.
+
+
+%%
+%% Given a string or binary, parse it into a list of terms, ala file:consult/0
+%%
+consult(Str) when is_list(Str) ->
+ consult([], Str, []);
+consult(Bin) when is_binary(Bin)->
+ consult([], binary_to_list(Bin), []).
+
+consult(Cont, Str, Acc) ->
+ case erl_scan:tokens(Cont, Str, 0) of
+ {done, Result, Remaining} ->
+ case Result of
+ {ok, Tokens, _} ->
+ {ok, Term} = erl_parse:parse_term(Tokens),
+ consult([], Remaining, [Term | Acc]);
+ {eof, _Other} ->
+ lists:reverse(Acc);
+ {error, Info, _} ->
+ {error, Info}
+ end;
+ {more, Cont1} ->
+ consult(Cont1, eof, Acc)
+ end.
View
24 example/rel/files/vm.args
@@ -0,0 +1,24 @@
+## Name of the node
+-name {{node}}
+
+## Cookie for distributed erlang
+-setcookie couch
+
+## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
+-heart
+
+## Enable kernel poll and a few async threads
++K true
++A 16
+
+## Treat error_logger warnings as warnings
++W w
+
+## Increase number of concurrent ports/sockets
+-env ERL_MAX_PORTS 4096
+
+## Tweak GC to run more often
+-env ERL_FULLSWEEP_AFTER 10
+
+## Set the location of crash dumps
+-env ERL_CRASH_DUMP {{crash_dump}}
View
76 example/rel/reltool.config
@@ -0,0 +1,76 @@
+%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
+%%
+{sys, [
+ {lib_dirs, ["../deps", "../apps"]},
+ {rel, "couch", "0.1",
+ [
+ kernel,
+ stdlib,
+ sasl,
+ public_key,
+ ssl,
+ os_mon,
+ crypto,
+ inets,
+ xmerl,
+ runtime_tools,
+ mochiweb,
+ ibrowse,
+ oauth,
+ jiffy,
+ snappy,
+ couch,
+ couch_index,
+ couch_mrview,
+ couch_changes,
+ couch_replicator
+ ]},
+ {rel, "start_clean", "", [kernel, stdlib]},
+ {boot_rel, "couch"},
+ {profile, embedded},
+ {relocatable, true},
+ {app_file, strip},
+ {debug_info, strip},
+
+ {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]},
+ {excl_archive_filters, [".*"]},
+
+ {app, sasl, [{incl_cond, include}]},
+ {app, crypto, [{incl_cond, include}]},
+ {app, public_key, [{incl_cond, include}]},
+ {app, ssl, [{incl_cond, include}]},
+
+ %% dependencies
+ {app, mochiweb, [{incl_cond, include}]},
+ {app, oauth, [{incl_cond, include}]},
+ {app, jiffy, [{incl_cond, include}]},
+ {app, snappy, [{incl_cond, include}]},
+ {app, ibrowse, [{incl_cond, include}]},
+
+ %% couchdb
+ {app, couch, [{incl_cond, include}]},
+ {app, couch_index, [{incl_cond, include}]},
+ {app, couch_mrview, [{incl_cond, include}]},
+ {app, couch_changes, [{incl_cond, include}]},
+ {app, couch_replicator, [{incl_cond, include}]}
+ ]}.
+
+{target_dir, "couch"}.
+
+{overlay_vars, "couch.config"}.
+
+{overlay, [
+ {mkdir, "log"},
+ {mkdir, "run"},
+ {mkdir, "data"},
+ {copy, "files/erl", "{{erts_vsn}}/bin/erl"},
+ {template, "files/nodetool", "{{erts_vsn}}/bin/nodetool"},
+ {template, "files/couch", "bin/couch"},
+ {template, "files/app.config", "etc/app.config"},
+ {template, "files/vm.args", "etc/vm.args"},
+ {template, "files/default.ini", "etc/default.ini"},
+ {template, "files/local.ini", "etc/local.ini"},
+ {copy, "../apps/couch/share"},
+ {copy, "../apps/couch/couchjs", "bin/couchjs"}
+ ]}.
View
5 rebar.config
@@ -0,0 +1,5 @@
+%%-*- mode: erlang -*-
+
+{sub_dirs, ["apps/*"]}.
+
+{require_otp_vsn, "R14|R15"}.

0 comments on commit 0705b1f

Please sign in to comment.