diff options
author | varac <varacanero@zeromail.org> | 2013-03-12 14:10:54 +0100 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2013-03-12 14:10:54 +0100 |
commit | 546350d6f6e83e9ea22db79d07bdc38c694fbcdb (patch) | |
tree | 555e42591968cdddba668da7f2bf2f4b2f4e0eb5 | |
parent | b915a67c6e7e3b1b75400dbbd4a9ac961c8eb032 (diff) | |
parent | 3647bc9cb0137bdfa1dfeeb1bd58c2f099fb5df0 (diff) |
Merge remote-tracking branch 'remotes/origin/feature/bigcouch'
Conflicts:
manifests/init.pp
-rwxr-xr-x | files/Debian/couchdb | 160 | ||||
-rw-r--r-- | files/couch-doc-update | 16 | ||||
-rw-r--r-- | manifests/add_user.pp | 16 | ||||
-rw-r--r-- | manifests/base.pp | 64 | ||||
-rw-r--r-- | manifests/bigcouch.pp | 40 | ||||
-rw-r--r-- | manifests/bigcouch/debian.pp | 9 | ||||
-rw-r--r-- | manifests/debian.pp | 9 | ||||
-rw-r--r-- | manifests/init.pp | 12 | ||||
-rw-r--r-- | manifests/query/setup.pp | 9 | ||||
-rw-r--r-- | manifests/update.pp | 4 | ||||
-rw-r--r-- | templates/bigcouch/vm.args | 27 |
11 files changed, 341 insertions, 25 deletions
diff --git a/files/Debian/couchdb b/files/Debian/couchdb new file mode 100755 index 0000000..ccdfe71 --- /dev/null +++ b/files/Debian/couchdb @@ -0,0 +1,160 @@ +#!/bin/sh -e + +# 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. + +### BEGIN INIT INFO +# Provides: couchdb +# Required-Start: $local_fs $remote_fs +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Apache CouchDB init script +# Description: Apache CouchDB init script for the database server. +### END INIT INFO + +SCRIPT_OK=0 +SCRIPT_ERROR=1 + +DESCRIPTION="database server" +NAME=couchdb +SCRIPT_NAME=`basename $0` +COUCHDB=/usr/bin/couchdb +CONFIGURATION_FILE=/etc/default/couchdb +RUN_DIR=/var/run/couchdb +LSB_LIBRARY=/lib/lsb/init-functions + +if test ! -x $COUCHDB; then + exit $SCRIPT_ERROR +fi + +if test -r $CONFIGURATION_FILE; then + . $CONFIGURATION_FILE +fi + +log_daemon_msg () { + # Dummy function to be replaced by LSB library. + + echo $@ +} + +log_end_msg () { + # Dummy function to be replaced by LSB library. + + if test "$1" != "0"; then + echo "Error with $DESCRIPTION: $NAME" + fi + return $1 +} + +if test -r $LSB_LIBRARY; then + . $LSB_LIBRARY +fi + +run_command () { + command="$1" + if test -n "$COUCHDB_OPTIONS"; then + command="$command $COUCHDB_OPTIONS" + fi + if test -n "$COUCHDB_USER"; then + if su $COUCHDB_USER -c "$command"; then + return $SCRIPT_OK + else + return $SCRIPT_ERROR + fi + else + if $command; then + return $SCRIPT_OK + else + return $SCRIPT_ERROR + fi + fi +} + +start_couchdb () { + # Start Apache CouchDB as a background process. + + mkdir -p "$RUN_DIR" + chown -R "$COUCHDB_USER" "$RUN_DIR" + command="$COUCHDB -b" + if test -n "$COUCHDB_STDOUT_FILE"; then + command="$command -o $COUCHDB_STDOUT_FILE" + fi + if test -n "$COUCHDB_STDERR_FILE"; then + command="$command -e $COUCHDB_STDERR_FILE" + fi + if test -n "$COUCHDB_RESPAWN_TIMEOUT"; then + command="$command -r $COUCHDB_RESPAWN_TIMEOUT" + fi + run_command "$command" > /dev/null +} + +stop_couchdb () { + # Stop the running Apache CouchDB process. + + run_command "$COUCHDB -d" > /dev/null + pkill -u couchdb + # always return true even if no remaining couchdb procs got killed + /bin/true +} + +display_status () { + # Display the status of the running Apache CouchDB process. + + run_command "$COUCHDB -s" +} + +parse_script_option_list () { + # Parse arguments passed to the script and take appropriate action. + + case "$1" in + start) + log_daemon_msg "Starting $DESCRIPTION" $NAME + if start_couchdb; then + log_end_msg $SCRIPT_OK + else + log_end_msg $SCRIPT_ERROR + fi + ;; + stop) + log_daemon_msg "Stopping $DESCRIPTION" $NAME + if stop_couchdb; then + log_end_msg $SCRIPT_OK + else + log_end_msg $SCRIPT_ERROR + fi + ;; + restart|force-reload) + log_daemon_msg "Restarting $DESCRIPTION" $NAME + if stop_couchdb; then + if start_couchdb; then + log_end_msg $SCRIPT_OK + else + log_end_msg $SCRIPT_ERROR + fi + else + log_end_msg $SCRIPT_ERROR + fi + ;; + status) + display_status + ;; + *) + cat << EOF >&2 +Usage: $SCRIPT_NAME {start|stop|restart|force-reload|status} +EOF + exit $SCRIPT_ERROR + ;; + esac +} + +parse_script_option_list $@ diff --git a/files/couch-doc-update b/files/couch-doc-update index 9ba6db7..45d9f87 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -14,7 +14,7 @@ # # USAGE # -# couch-doc-update --db <db> --id <doc_id> --data <json> +# couch-doc-update --port <port> --db <db> --id <doc_id> --data <json> # # EXAMPLE # @@ -24,6 +24,8 @@ # update a user: # couch-doc-update --db _users --id org.couchdb.user:ca_daemon --data '{"password":"sssshhh"}' # +# To update the _users DB on bigcouch, you must connect to port 5986 instead of the default couchdb port 5984 +# begin; require 'rubygems'; rescue LoadError; end # optionally load rubygems require 'couchrest' @@ -33,11 +35,13 @@ def main # # parse options # + @port = "5984" @db_name = nil @doc_id = nil @new_data = nil loop do case ARGV[0] + when '--port' then ARGV.shift; @port = ARGV.shift when '--db' then ARGV.shift; @db_name = ARGV.shift when '--id' then ARGV.shift; @doc_id = ARGV.shift when '--data' then ARGV.shift; @new_data = ARGV.shift @@ -47,12 +51,12 @@ def main end usage("Missing required option") unless @db_name && @doc_id && @new_data @new_data = JSON.parse(@new_data) - + # # update document # begin - @db = CouchRest.database(connection_string(@db_name)) + @db = CouchRest.database(connection_string(@db_name, @port)) @doc = get_document(@db, @doc_id) result = if @doc update_document(@db, @doc, @new_data) @@ -87,10 +91,10 @@ def create_document(db, doc_id, data) db.save_doc(data) end -def connection_string(database) +def connection_string(database, port) protocol = "http" hostname = "127.0.0.1" - port = "5984" + #port = "5984" username = "admin" password = "" @@ -109,7 +113,7 @@ end def usage(s) $stderr.puts(s) - $stderr.puts("Usage: #{File.basename($0)} --db <db> --id <doc_id> --data <json>") + $stderr.puts("Usage: #{File.basename($0)} --port <port> --db <db> --id <doc_id> --data <json>") exit(2) end diff --git a/manifests/add_user.pp b/manifests/add_user.pp index 26fc5dc..e455124 100644 --- a/manifests/add_user.pp +++ b/manifests/add_user.pp @@ -1,7 +1,15 @@ -define couchdb::add_user ( $roles, $pw, $host='127.0.0.1:5984' ) { +define couchdb::add_user ( $roles, $pw ) { + + if $::couchdb::bigcouch == true { + $port = 5986 + } else { + $port = 5984 +} + couchdb::update { "update_user_$name": - db => '_users', - id => "org.couchdb.user:$name", - data => "{\"type\": \"user\", \"name\": \"$name\", \"roles\": $roles, \"password\": \"$pw\"}", + port => $port, + db => '_users', + id => "org.couchdb.user:$name", + data => "{\"type\": \"user\", \"name\": \"$name\", \"roles\": $roles, \"password\": \"$pw\"}", } } diff --git a/manifests/base.pp b/manifests/base.pp index d4d50d1..45d991b 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -1,5 +1,13 @@ class couchdb::base { + if $::couchdb::bigcouch == true { + $couchdb_user = 'bigcouch' + include couchdb::bigcouch + } else { + $couchdb_user = 'couchdb' + } + + package {'couchdb': ensure => present, } @@ -18,12 +26,56 @@ class couchdb::base { } File['/usr/local/bin/couch-doc-update'] -> Couchdb::Update <| |> - file { '/usr/local/bin/couch-doc-update': - source => 'puppet:///modules/couchdb/couch-doc-update', - mode => '0755', - owner => 'root', - group => 'root', - require => Package['couchrest'], + + file { + '/usr/local/bin/couch-doc-update': + source => 'puppet:///modules/couchdb/couch-doc-update', + mode => '0755', + owner => 'root', + group => 'root', + require => Package['couchrest']; + + '/etc/couchdb/local.ini': + source => [ "puppet:///modules/site_couchdb/${::fqdn}/local.ini", + 'puppet:///modules/site_couchdb/local.ini', + 'puppet:///modules/couchdb/local.ini' ], + notify => Service[couchdb], + owner => $couchdb_user, + group => $couchdb_user, + mode => '0660', + require => Package['couchdb']; + + '/etc/couchdb/local.d': + ensure => directory, + require => Package['couchdb']; } + # salt and encrypt admin pw + $sha1_and_salt = str2sha1_and_salt($::couchdb::admin_pw) + $sha1 = $sha1_and_salt[0] + $salt = $sha1_and_salt[1] + + file {'/etc/couchdb/local.d/admin.ini': + content => "[admins] +admin = -hashed-${sha1},${salt} +", + mode => '0600', + owner => $couchdb_user, + group => $couchdb_user, + notify => Service[couchdb], + require => File ['/etc/couchdb/local.d']; + } + + exec { 'couchdb_restart': + command => $::couchdb::bigcouch ? { + true => '/etc/init.d/bigcouch restart; sleep 6', + default => '/etc/init.d/couchdb restart; sleep 6', + }, + path => ['/bin', '/usr/bin',], + subscribe => File['/etc/couchdb/local.d/admin.ini', + '/etc/couchdb/local.ini'], + refreshonly => true + } + + } diff --git a/manifests/bigcouch.pp b/manifests/bigcouch.pp new file mode 100644 index 0000000..00d9da9 --- /dev/null +++ b/manifests/bigcouch.pp @@ -0,0 +1,40 @@ +class couchdb::bigcouch inherits couchdb::base { + + apt::sources_list {'bigcouch-cloudant.list': + content => "deb http://packages.cloudant.com/debian $::lsbdistcodename main" + } + + # currently, there's no other way with puppet to install unauthenticated + # pacakges: http://projects.puppetlabs.com/issues/556 + # so we need to globally allow apt to install unauthenticated + # packages. + + apt::apt_conf { 'allow_unauthenticated': + content => 'APT::Get::AllowUnauthenticated yes;', + } + + file {'/etc/couchdb': + ensure => link, + target => '/opt/bigcouch/etc', + require => Package['couchdb'] + } + + Package ['couchdb'] { + name => 'bigcouch', + require => [ Apt::Sources_list ['bigcouch-cloudant.list'], + Apt::Apt_conf ['allow_unauthenticated'], Exec[refresh_apt] ] + } + + file { '/opt/bigcouch/etc/vm.args': + content => template('couchdb/bigcouch/vm.args'), + mode => '0640', + owner => 'bigcouch', + group => 'bigcouch', + require => Package['couchdb'] + } + + Service ['couchdb'] { + name => 'bigcouch' + } + +} diff --git a/manifests/bigcouch/debian.pp b/manifests/bigcouch/debian.pp new file mode 100644 index 0000000..54ca882 --- /dev/null +++ b/manifests/bigcouch/debian.pp @@ -0,0 +1,9 @@ +class couchdb::bigcouch::debian inherits couchdb::debian { + File ['/etc/init.d/couchdb'] { + ensure => absent + } + file {'/etc/init.d/bigcouch': + ensure => link, + target => '/usr/bin/sv' + } +} diff --git a/manifests/debian.pp b/manifests/debian.pp index 14678e2..2a7417e 100644 --- a/manifests/debian.pp +++ b/manifests/debian.pp @@ -3,5 +3,12 @@ class couchdb::debian inherits couchdb::base { package {'libjs-jquery': ensure => present, } - + file {'/etc/init.d/couchdb': + source => [ 'puppet:///modules/site_couchdb/Debian/couchdb', + 'puppet:///modules/couchdb/Debian/couchdb' ], + mode => '0755', + owner => 'root', + group => 'root', + require => Package['couchdb'] + } } diff --git a/manifests/init.pp b/manifests/init.pp index 75a638f..d62bb9e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,8 +1,16 @@ -class couchdb { +class couchdb ( + $admin_pw, + $bigcouch = false, + $bigcouch_cookie = '' ) { case $::operatingsystem { Debian: { case $::lsbdistcodename { - /lenny|squeeze|wheezy/: { include couchdb::debian } + /lenny|squeeze|wheezy/: { + include couchdb::debian + if $bigcouch == true { + include couchdb::bigcouch::debian + } + } default: { fail "couchdb not available for ${::operatingsystem}/${::lsbdistcodename}" } } } diff --git a/manifests/query/setup.pp b/manifests/query/setup.pp index a5d1657..a36cade 100644 --- a/manifests/query/setup.pp +++ b/manifests/query/setup.pp @@ -1,8 +1,9 @@ -define couchdb::query::setup ($host='127.0.0.1', $user, $pw) { +define couchdb::query::setup ($user, $pw, $host='127.0.0.1') { file { '/etc/couchdb/couchdb.netrc': - content => "machine $host login $user password $pw", + content => "machine ${host} login ${user} password ${pw}", mode => '0600', - owner => 'couchdb', - group => 'couchdb', + owner => $::couchdb::base::couchdb_user, + group => $::couchdb::base::couchdb_user, + require => Package['couchdb']; } } diff --git a/manifests/update.pp b/manifests/update.pp index 129d875..3cb6ece 100644 --- a/manifests/update.pp +++ b/manifests/update.pp @@ -1,3 +1,3 @@ -define couchdb::update ($db, $id, $data) { - exec { "couch-doc-update --db $db --id $id --data \'$data\'": } +define couchdb::update ($db, $id, $data, $port='5984') { + exec { "couch-doc-update --port $port --db $db --id $id --data \'$data\'": } } diff --git a/templates/bigcouch/vm.args b/templates/bigcouch/vm.args new file mode 100644 index 0000000..15e1f91 --- /dev/null +++ b/templates/bigcouch/vm.args @@ -0,0 +1,27 @@ +# Each node in the system must have a unique name. A name can be short +# (specified using -sname) or it can by fully qualified (-name). There can be +# no communication between nodes running with the -sname flag and those running +# with the -name flag. +-name bigcouch + +# All nodes must share the same magic cookie for distributed Erlang to work. +# Comment out this line if you synchronized the cookies by other means (using +# the ~/.erlang.cookie file, for example). +-setcookie <%= scope.lookupvar('::couchdb::bigcouch_cookie') %> + +# Tell SASL not to log progress reports +-sasl errlog_type error + +# Use kernel poll functionality if supported by emulator ++K true + +# Start a pool of asynchronous IO threads ++A 16 + +# Comment this line out to enable the interactive Erlang shell on startup ++Bd -noinput + +# read config files +# otherwise /etc/couchdb/local.d/admin.ini wouldn't be read mysteriously +-couch_ini /etc/couchdb/default.ini /etc/couchdb/local.ini /etc/couchdb/local.d/admin.ini /etc/couchdb/default.ini /etc/couchdb/local.ini /etc/couchdb/local.d/admin.ini +# |