diff --git a/Makefile b/Makefile index 12699f026..ff89a712a 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ PKG_REVISION ?= $(shell git describe --tags 2>/dev/null) PKG_BUILD = 1 BASE_DIR = $(shell pwd) ERLANG_BIN = $(shell dirname $(shell which erl 2>/dev/null) 2>/dev/null) -OTP_VER = $(shell echo $(ERLANG_BIN) | rev | cut -d "/" -f 2 | rev) +OTP_VER = $(shell erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell) REBAR ?= $(BASE_DIR)/rebar3 OVERLAY_VARS ?= -TEST_IGNORE ?= lager riak basho_bench +TEST_IGNORE ?= riak basho_bench TEST_DEPS_DIR ?= _build/test/lib REL_DIR ?= _build/default/rel DEPS = $(patsubst $(TEST_DEPS_DIR)/%, %, $(wildcard $(TEST_DEPS_DIR)/*)) @@ -21,21 +21,17 @@ export EXOMETER_PACKAGES $(if $(ERLANG_BIN),,$(warning "Warning: No Erlang found in your path, this will probably not work")) -.PHONY: rel stagedevrel deps +.PHONY: rel stagedevrel -all: deps compile +all: compile compile: $(REBAR) compile -deps: - $(if $(HEAD_REVISION),$(warning "Warning: you have checked out a tag ($(HEAD_REVISION)) and should use the compile target")) - $(REBAR) upgrade - clean: testclean $(REBAR) clean -distclean: clean devclean relclean ballclean +distclean: clean devclean relclean @rm -rf _build ## @@ -74,20 +70,35 @@ test : testclean eunit test-deps ## Release targets ## rel: compile - $(REBAR) as rel release - cp -a _build/rel/rel/riak rel/ + @$(REBAR) as rel release +# freebsd tar won't write to stdout, so: + @tar -c -f rel.tar --exclude '*/.git/*' -C _build/rel/rel riak && tar -x -f rel.tar -C rel && rm rel.tar rel-rpm: compile - $(REBAR) as rpm release - cp -a _build/rpm/rel/riak rel/ + @$(REBAR) as rpm release + @tar --exclude-vcs -c -C _build/rpm/rel riak | tar -x -C rel rel-deb: compile - $(REBAR) as deb release - cp -a _build/deb/rel/riak rel/ + @$(REBAR) as deb release + @tar --exclude=vcs -c -C _build/deb/rel riak | tar -x -C rel + +rel-osx: compile + @$(REBAR) as osx release + @tar --exclude=vcs -c -C _build/osx/rel riak | tar -x -C rel + +# this one is to be called from an external make (not from rel/pkg/Makefile) +rel-alpine: compile + @$(REBAR) as alpine release + @(cd _build/alpine/rel/riak/usr/bin && mv riak-nosu riak) + @tar --exclude=vcs -c -C _build/alpine/rel riak | tar -x -C rel + +rel-fbsdng: compile + @$(REBAR) as fbsdng release + @tar -c -f rel.tar --exclude '*/.git/*' -C _build/fbsdng/rel riak && tar -x -f rel.tar -C rel && rm rel.tar relclean: - rm -rf $(REL_DIR) - rm -rf rel/riak + @rm -rf $(REL_DIR) + @rm -rf rel/riak rel/.libs rel/.deps ## ## Developer targets @@ -123,7 +134,7 @@ perfdev : all mkdir -p perfdev rel/gen_dev $@ rel/vars/perf_vars.config.src rel/vars/perf_vars.config (cd rel && ../rebar generate target_dir=../perfdev overlay_vars=vars/perf_vars.config) - $(foreach dep,$(wildcard deps/*), rm -rf perfdev/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) perfdev/lib;) + $(foreach dep,$(wildcard _build/default/lib/*), rm -rf perfdev/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) perfdev/lib;) perf: perfdev/bin/riak stop || : @@ -136,7 +147,7 @@ devclean: clean rm -rf dev stage : rel - $(foreach dep,$(wildcard deps/*), rm -rf rel/riak/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) rel/riak/lib;) + $(foreach dep,$(wildcard _build/default/lib/*), rm -rf rel/riak/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) rel/riak/lib;) ## ## Doc targets @@ -231,7 +242,7 @@ PKG_ID := "$(REPO_TAG)-OTP$(OTP_VER)" PKG_VERSION = $(shell echo $(PKG_ID) | sed -e 's/^$(REPO)-//') package: - mkdir rel/pkg/out/riak-$(PKG_ID) + mkdir -p rel/pkg/out/$(PKG_ID) git archive --format=tar HEAD | gzip >rel/pkg/out/$(PKG_ID).tar.gz $(MAKE) -f rel/pkg/Makefile diff --git a/apps/riak/src/riak.app.src b/apps/riak/src/riak.app.src index 8b8155ed0..1ab885d21 100644 --- a/apps/riak/src/riak.app.src +++ b/apps/riak/src/riak.app.src @@ -14,7 +14,6 @@ riak, cuttlefish, runtime_tools, - lager_syslog, cluster_info, riak_kv, riak_repl, diff --git a/config/vm.args b/config/vm.args new file mode 100644 index 000000000..e65cd3f49 --- /dev/null +++ b/config/vm.args @@ -0,0 +1,2 @@ +-setcookie riak +-name riak@127.0.0.1 diff --git a/pkg.vars.config b/pkg.vars.config deleted file mode 100644 index 2339cf38f..000000000 --- a/pkg.vars.config +++ /dev/null @@ -1,37 +0,0 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ts=4 sw=4 et - -%% -%% Packaging -%% -{package_name, "riak"}. -{package_install_name, "riak"}. -{package_install_user, "riak"}. -{package_install_group, "riak"}. -{package_install_user_desc, "Riak user"}. -{package_commands, {list, [[{name, "riak"}], [{name, "riak-admin"}], [{name, "riak-repl"}], [{name, "riak-debug"}]]}}. -{package_shortdesc, "Riak is a distributed data store"}. -{package_desc, "Riak is a distributed data store"}. -{bin_or_sbin, "sbin"}. -{package_patch_dir, "basho-patches"}. -{solaris_pkgname, "BASHOriak"}. -{license_type, "Apache 2"}. -{copyright, "2013 Basho Technologies, Inc"}. -{vendor_name, "Basho Technologies, Inc"}. -{vendor_url, "http://basho.com"}. -{vendor_contact_name, "Basho Package Maintainer"}. -{vendor_contact_email, "packaging@basho.com"}. -{cuttlefish_conf, "riak.conf"}. -{license_full_text, "This file is provided to you under the Apache License,\n" -"Version 2.0 (the \"License\"); you may not use this file\n" -"except in compliance with the License. You may obtain\n" -"a copy of the License at\n" -"\n" -" http://www.apache.org/licenses/LICENSE-2.0\n" -"\n" -"Unless required by applicable law or agreed to in writing,\n" -"software distributed under the License is distributed on an\n" -"\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" -"KIND, either express or implied. See the License for the\n" -"specific language governing permissions and limitations\n" -"under the License."}. diff --git a/priv/riak.schema b/priv/riak.schema index 6a153503c..21260a896 100644 --- a/priv/riak.schema +++ b/priv/riak.schema @@ -2,7 +2,7 @@ %% @doc The severity level of the console log, default is 'info'. {mapping, "logger.level", "kernel.logger_level", [ - {default, info}, + {default, {{logger_level}} }, {datatype, {enum, [debug, info, notice, warning, error, critical, alert, emergency, none]}} ]}. diff --git a/rebar.config b/rebar.config index 58a9054a7..14b256d1f 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1,4 @@ %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -{sub_dirs, ["rel", "apps/riak"]}. - {minimum_otp_vsn, "22.0"}. {cover_enabled, true}. @@ -11,7 +9,7 @@ {deps, [ {syslogger, {git, "https://github.com/basho/syslogger", {branch, "master"}}}, {cluster_info, {git, "https://github.com/basho/cluster_info", {branch, "develop"}}}, - {riak_kv, {git, "https://github.com/basho/riak_kv", {branch, "develop"}}}, + {riak_kv, {git, "https://github.com/TI-Tokyo/riak_kv", {branch, "develop"}}}, {riak_auth_mods, {git, "https://github.com/basho/riak_auth_mods", {branch, "develop"}}}, {riak_repl, {git, "https://github.com/basho/riak_repl", {branch, "develop"}}} @@ -79,6 +77,7 @@ {overlay, [ {mkdir, "lib/patches"}, {mkdir, "data/ring"}, + {mkdir, "log"}, {template, "rel/files/advanced.config", "etc/advanced.config"}, @@ -89,12 +88,12 @@ {template, "rel/files/riak-repl", "bin/riak-repl"}, {template, "rel/files/riak", "usr/bin/riak"}, - {copy, "rel/files/check_ulimit", "bin/hooks/check_ulimit"}, - {copy, "rel/files/erl_maxlogsize", "bin/hooks/erl_maxlogsize"}, - {copy, "rel/files/erl_codeloadingmode","bin/hooks/erl_codeloadingmode"}, - {copy, "rel/files/riak_not_running", "bin/hooks/riak_not_running"}, - {copy, "rel/files/app_epath.sh", "lib/app_epath.sh"} - + {copy, "rel/files/hooks/check_ulimit", "bin/hooks/check_ulimit"}, + {copy, "rel/files/hooks/erl_maxlogsize", "bin/hooks/erl_maxlogsize"}, + {copy, "rel/files/hooks/erl_codeloadingmode","bin/hooks/erl_codeloadingmode"}, + {template, "rel/files/hooks/riak_not_running", "bin/hooks/riak_not_running"}, + {template, "rel/files/lib.sh", "lib/lib.sh"}, + {copy, "rel/files/app_epath.escript", "lib/app_epath.escript"} ]}, {generate_start_script, true}, @@ -102,6 +101,7 @@ {extended_start_script_extensions, [ {admin, "riak-admin"}, {repl, "riak-repl"}, + {debug, "riak-debug"}, {chkconfig, "riak-chkconfig"} ]} @@ -109,70 +109,121 @@ {dialyzer, [{plt_apps, all_deps}]}. -{profiles, [ - {rel, [ - {relx, [ - {overlay_vars, "rel/vars.config"}, - {extended_start_script_hooks, - [{pre_start, - [{custom, "hooks/riak_not_running"}, - {custom, "hooks/check_ulimit"}, - {custom, "hooks/erl_maxlogsize"}, - {custom, "hooks/erl_codeloadingmode"}]}, - {post_start, - [{wait_for_process, riak_core_node_watcher}]} - ]} - ]} - ]}, - {dev, [{relx, [ - {dev_mode, true}, - {extended_start_script_hooks, - [{pre_start, - [{custom, "hooks/riak_not_running"}, - {custom, "hooks/check_ulimit"}, - {custom, "hooks/erl_maxlogsize"}, - {custom, "hooks/erl_codeloadingmode"}]}, - {post_start, - [{wait_for_process, riak_core_node_watcher}]} - ]} - ]} - ]}, - {rpm, [ - {relx, [ - {overlay_vars, "rel/pkg/rpm/vars.config"}, - {overlay, [ - {template, "rel/files/riak", "usr/sbin/riak"}, - {template, "rel/pkg/rpm/init.script", "etc/init.d/init.script"} - ]}, - {extended_start_script_hooks, - [{pre_start, - [{custom, "hooks/riak_not_running"}, - {custom, "hooks/check_ulimit"}, - {custom, "hooks/erl_maxlogsize"}, - {custom, "hooks/erl_codeloadingmode"}]}, - {post_start, - [{pid, "/var/run/riak/riak.pid"}, - {wait_for_process, riak_core_node_watcher}]} - ]} - ]} - ]}, - {deb, [ - {relx, [ - {overlay_vars, "debian/vars.config"}, - {overlay, [ - {template, "rel/files/riak", "usr/bin/riak"} - ]}, - {extended_start_script_hooks, - [{pre_start, - [{custom, "hooks/riak_not_running"}, - {custom, "hooks/check_ulimit"}, - {custom, "hooks/erl_maxlogsize"}, - {custom, "hooks/erl_codeloadingmode"}]}, - {post_start, - [wait_for_vm_start, - {pid, "/run/riak/riak.pid"}, - {wait_for_process, riak_core_node_watcher}]} - ]} - ]} - ]} +{profiles, + [{rel, + [{relx, + [{overlay_vars, "rel/vars.config"}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"}]}, + {post_start, + [{wait_for_process, riak_core_node_watcher} + ]} + ]} + ]} + ]}, + + {dev, + [{relx, + [{dev_mode, true}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"} + ]}, + {post_start, + [{wait_for_process, riak_core_node_watcher}]} + ]} + ]} + ]}, + + {rpm, + [{relx, + [{overlay_vars, "rel/pkg/rpm/vars.config"}, + {overlay, + [{template, "rel/files/riak", "usr/sbin/riak"}, + {template, "rel/pkg/rpm/init.script", "etc/init.d/init.script"} + ]}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"} + ]}, + {post_start, + [{pid, "/var/run/riak/riak.pid"}, + {wait_for_process, riak_core_node_watcher}]} + ]} + ]} + ]}, + + {deb, + [{relx, + [{overlay_vars, "rel/pkg/deb/vars.config"}, + {overlay, + [{template, "rel/files/riak", "usr/bin/riak"} + ]}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"} + ]}, + {post_start, + [wait_for_vm_start, + {pid, "/run/riak/riak.pid"}, + {wait_for_process, riak_core_node_watcher}]} + ]} + ]} + ]}, + + {alpine, + [{relx, + [{overlay_vars, "rel/pkg/alpine/vars.config"}, + {overlay, + [{template, "rel/pkg/alpine/riak-nosu", "usr/bin/riak-nosu"} %% to be renamed to riak in Makefile + ]}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"}]}, + {post_start, + [wait_for_vm_start, + {pid, "/run/riak/riak.pid"}, + {wait_for_process, riak_core_node_watcher}]} + ]} + ]} + ]}, + + {osx, + [{relx, + [{overlay_vars, "rel/pkg/osx/vars.config"} + ]} + ]}, + + {fbsdng, + [{relx, + [{overlay_vars, "rel/pkg/fbsdng/vars.config"}, + {extended_start_script_hooks, + [{pre_start, + [{custom, "hooks/riak_not_running"}, + {custom, "hooks/check_ulimit"}, + {custom, "hooks/erl_maxlogsize"}, + {custom, "hooks/erl_codeloadingmode"}]}, + {post_start, + [wait_for_vm_start, + {pid, "/var/run/riak/riak.pid"}, + {wait_for_process, riak_core_node_watcher}]} + ]} + ]} + ]} ]}. diff --git a/rebar3 b/rebar3 index a83d554a5..c1597bbc5 100755 Binary files a/rebar3 and b/rebar3 differ diff --git a/rel/.gitignore b/rel/.gitignore new file mode 100644 index 000000000..e615c91bc --- /dev/null +++ b/rel/.gitignore @@ -0,0 +1,2 @@ +.deps/ +.libs/ diff --git a/rel/files/advanced.config b/rel/files/advanced.config index 9b8ba36f6..bf31ecd77 100644 --- a/rel/files/advanced.config +++ b/rel/files/advanced.config @@ -7,7 +7,7 @@ %% cluster_leader will service requests. This can change as nodes %% enter and leave the cluster. {cluster_mgr, {"{{cluster_manager_ip}}", {{cluster_manager_port}} } }, - {schema_dirs, ["./share/schema"]} + {schema_dirs, ["{{platform_lib_dir}}/../share/schema"]} ]}, {riak_repl, diff --git a/rel/files/app_epath.escript b/rel/files/app_epath.escript new file mode 100644 index 000000000..f84608c9a --- /dev/null +++ b/rel/files/app_epath.escript @@ -0,0 +1,9 @@ +-module(app_epath). +-export([main/1]). + +main([AdvancedConfig]) -> + {ok, [AA]} = file:consult(AdvancedConfig), + [p(A) || A <- AA]. + +p({App, CC}) -> + [io:format("~s ~s ~9999p\n", [App, K, V]) || {K, V} <- CC]. diff --git a/rel/files/app_epath.sh b/rel/files/app_epath.sh deleted file mode 100755 index a3de910b0..000000000 --- a/rel/files/app_epath.sh +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/sh - -## --------------------------------------------------------------------- -## -## app_epath.sh: Parse Erlang app.config with POSIX tools for automation -## -## Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved. -## -## This file is provided to you 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. -## -## --------------------------------------------------------------------- - -## Example usage: -# -# #!/bin/sh -# -# # Load the functions -# . path/to/app_epath.sh -# -# # Build the path info -# epaths=`make_app_epaths path/to/app.config` -# -# # View all of the settings. Quotes are important. -# echo "$epaths" -# -# # Grep around in the paths for various items. -# echo "$epaths" | grep 'riak_core ring_creation_size' -# echo "$epaths" | grep "lager handlers lager_file_backend" | grep info -# -# # Use the epath function to get directly at settings -# epath 'riak_core ring_creation_size' "$epaths" -# epath 'riak_core platform_bin_dir' "$epaths" -# epath 'riak_kv storage_backend' "$epaths" -# -# # Use epath to view all of the riak_core settings -# epath riak_core -# -## End example - -## Here is a command you can put in your path for general cli use. -# -# #!/bin/sh -# -# # $1 quoted eterm path for search: 'riak_core ring_creation_size' -# # $2 path/to/app.config -# -# . path/to/app_epath.sh -# -# epaths=`make_app_epaths "$2"` -# epath "$1" "$epaths" -# -## End epath command - -# make_app_epaths takes a path to an app.config file as its argument and -# and returns (prints) a flattened text structure of configuration settings. - -make_app_epaths () { - # Remove all lines containing comments - # Remove all blank lines - # Remove the first [ - # Remove the last ]. - # Remove all blank lines again (just in case) - appconfig=`cat $1 \ - | sed '/^[ \t]*%/d' \ - | sed '/^[ \t]*$/d' \ - | sed -e '/\[/{s///;:a' -e '$!N;$!ba' -e '}' \ - | sed '$ s/\]\.//g' \ - | sed '/^[ \t]*$/d'` - - STACK= - INQUOTE=0 - # The awk puts each char, spaces included, on their own line for parsing. - echo "$appconfig" | awk '{gsub(//,"\n");print}' | while read i; do - case "x${i}x" in - "x\"x") - # Flip the INQUOTE state and echo the quote - if [ 1 -eq $INQUOTE ]; then - INQUOTE=0 - else - INQUOTE=1 - fi - STACK="${STACK}${i}" - ;; - "xx") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this space - STACK="${STACK} " - fi - ;; - "x,x") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this comma - STACK="${STACK}," - else - # Commas outside quotes means a new item is next - STACK="${STACK} " - fi - ;; - "x{x") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this bracket - STACK="${STACK}{" - else - # Add brace to the stack; will pop off from here on next } - STACK="${STACK} __EBRACE__ " - fi - ;; - "x}x") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this bracket - STACK="${STACK}}" - else - # We're only interested in printing leaves, not - # intermediates like 'riak_core http', which contain lists. - # See if the current stack ends with ] (end of list). - echo $STACK | grep -E "__EBRACKET__$" >/dev/null 2>&1 - if [ 1 -eq $? ]; then - # If not, print the stack without all of the mess. - echo "$STACK" | \ - sed 's/ *__EBRACE__//g;s/ *__EBRACKET__//g;s/^ *//' - fi - # Pop off everything from the last brace on. - STACK=`echo "$STACK" | sed 's/\(.*\) __EBRACE__.*/\1/g'` - fi - ;; - "x[x") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this bracket - STACK="${STACK}[" - else - # Add a placeholder to aid in determining whether or not to - # print. That is, we don't want to print 'riak_core http'. - STACK="${STACK} __EBRACKET__ " - fi - ;; - "x]x") - if [ 1 -eq $INQUOTE ]; then - # If in quotes, keep this bracket - STACK="${STACK}]" - fi - # Don't actually do anything with ], as the starting brackets - # are instead removed with }. - ;; - *) - # Anything else is just pushed. - STACK="${STACK}${i}" - ;; - esac - done -} - -epath () { - # arg1 - a pattern to search for - # arg2 - output of make_app_epaths, passed in quoted - # output - search of arg2 for arg1, trimming arg1 from the beginning - # Note: there may be multiple lines of output. - pat=$1 - shift - echo "$*" | grep "$pat " | sed "s/^${pat} *//" -} - diff --git a/rel/files/check_ulimit b/rel/files/hooks/check_ulimit similarity index 100% rename from rel/files/check_ulimit rename to rel/files/hooks/check_ulimit diff --git a/rel/files/erl_codeloadingmode b/rel/files/hooks/erl_codeloadingmode old mode 100644 new mode 100755 similarity index 100% rename from rel/files/erl_codeloadingmode rename to rel/files/hooks/erl_codeloadingmode diff --git a/rel/files/erl_maxlogsize b/rel/files/hooks/erl_maxlogsize old mode 100644 new mode 100755 similarity index 100% rename from rel/files/erl_maxlogsize rename to rel/files/hooks/erl_maxlogsize diff --git a/rel/files/riak_not_running b/rel/files/hooks/riak_not_running old mode 100644 new mode 100755 similarity index 64% rename from rel/files/riak_not_running rename to rel/files/hooks/riak_not_running index b63ca8278..5ee75f109 --- a/rel/files/riak_not_running +++ b/rel/files/hooks/riak_not_running @@ -2,7 +2,9 @@ # -*- tab-width:4;indent-tabs-mode:nil -*- # ex: ts=4 sw=4 et -if relx_nodetool "ping" > /dev/null; then +RIAK="{{platform_bin_dir}}/riak" + +if $RIAK "ping" > /dev/null; then echo "Node is already running!" exit 1 fi diff --git a/rel/files/lib.sh b/rel/files/lib.sh new file mode 100644 index 000000000..460b961d5 --- /dev/null +++ b/rel/files/lib.sh @@ -0,0 +1,92 @@ +fmt() { + printf "[[" + local n=$# + if [ $n -ne 0 ]; then + printf "\"$1\"" + shift + n=$((n-1)) + fi + while [ $n -ne 0 ]; do + printf ", \"$1\"" + shift + n=$((n-1)) + done + printf "]]\n" +} + +rpc() { + local mod=$1 + local fun=$2 + shift 2 + if [ $# -gt 0 ]; then + "${PLATFORM_BIN_DIR}/riak" rpc $mod $fun `fmt "$@"` + else + "${PLATFORM_BIN_DIR}/riak" rpc $mod $fun "[[]]" + fi +} + +rpc_raw() { + local mod=$1 + local fun=$2 + "${PLATFORM_BIN_DIR}/riak" rpc $mod $fun "$3" +} + +## Example usage: +# +# #!/bin/sh +# +# # Load the functions +# . path/to/app_epath.sh +# +# # Build the path info +# epaths=`make_app_epaths path/to/app.config` +# +# # View all of the settings. Quotes are important. +# echo "$epaths" +# +# # Grep around in the paths for various items. +# echo "$epaths" | grep 'riak_core ring_creation_size' +# echo "$epaths" | grep "lager handlers lager_file_backend" | grep info +# +# # Use the epath function to get directly at settings +# epath 'riak_core ring_creation_size' "$epaths" +# epath 'riak_core platform_bin_dir' "$epaths" +# epath 'riak_kv storage_backend' "$epaths" +# +# # Use epath to view all of the riak_core settings +# epath riak_core +# +## End example + +## Here is a command you can put in your path for general cli use. +# +# #!/bin/sh +# +# # $1 quoted eterm path for search: 'riak_core ring_creation_size' +# # $2 path/to/app.config +# +# . path/to/app_epath.sh +# +# epaths=`make_app_epaths "$2"` +# epath "$1" "$epaths" +# +## End epath command + +# make_app_epaths takes a path to an app.config file as its argument and +# and returns (prints) a flattened text structure of configuration settings. + +make_app_epaths () { + ERTS_VER=$(cd ${PLATFORM_BASE_DIR} && ls -d erts-*) + ERTS_PATH="${PLATFORM_BASE_DIR}/$ERTS_VER/bin" + $ERTS_PATH/escript $riak_lib_dir/app_epath.escript "$1" +} + +epath () { + # arg1 - a pattern to search for + # arg2 - output of make_app_epaths, passed in quoted + # output - search of arg2 for arg1, trimming arg1 from the beginning + # Note: there may be multiple lines of output. + pat=$1 + shift + echo "$*" | grep "$pat " | sed "s/^${pat} *//" +} diff --git a/rel/files/riak b/rel/files/riak index a04281509..ccb8fcb8e 100755 --- a/rel/files/riak +++ b/rel/files/riak @@ -1,57 +1,56 @@ #!/bin/bash -RUNNER_GEN_DIR="${RUNNER_GEN_DIR:-{{ platform_gen_dir }}}" -RELEASE_ROOT_DIR="${RELEASE_ROOT_DIR:-{{ runner_base_dir }}}" -PID_DIR={{pid_dir}} -COMMAND={{platform_bin_dir}}/riak -DEBUG_COMMAND={{platform_bin_dir}}/riak-debug -RUNNER_LOG_DIR={{platform_log_dir}} -RELX_CONFIG_PATH=${RUNNER_GEN_DIR}/sys.config -VMARGS_PATH=${RUNNER_GEN_DIR}/vm.args +RUNNER_GEN_DIR={{platform_gen_dir}} +RELX_RIAK={{platform_bin_dir}}/riak +export PID_DIR={{pid_dir}} +export RUNNER_LOG_DIR={{platform_log_dir}} +mkdir -p $PID_DIR +chown riak:riak $PID_DIR -# On first running the sys.config and vm.args will not be a link -# as cfconfig has not yet been run as a pre_start hook. If there's no -# link use the default for now -if [ ! -L $RELX_CONFIG_PATH ]; then - cp $RELEASE_ROOT_DIR/releases/{{release_version}}/sys.config $RELX_CONFIG_PATH -fi -if [ ! -L $VMARGS_PATH ]; then - cp $RELEASE_ROOT_DIR/releases/{{release_version}}/vm.args $VMARGS_PATH -fi - -# When running as a service, running as riak not as root, and systemd has created PID folder -if [[ $EUID -ne 0 ]]; then - case "$1" in - start|console|foreground) - RELX_CONFIG_PATH=${RELX_CONFIG_PATH} VMARGS_PATH=${VMARGS_PATH} RUNNER_LOG_DIR=${RUNNER_LOG_DIR} PIPE_DIR=${PIPE_DIR} ${COMMAND} ${*} -pa {{platform_lib_dir}}/patches - ;; - *) - RELX_CONFIG_PATH=${RELX_CONFIG_PATH} VMARGS_PATH=${VMARGS_PATH} RUNNER_LOG_DIR=${RUNNER_LOG_DIR} PIPE_DIR=${PIPE_DIR} ${COMMAND} ${*} - ;; - esac +# centos7-based distros have a su that contacts pam and prints the "Last logged in" message +if [ "`cat /etc/redhat-release 2>&1`" = "CentOS Stream release 7" ] || + [ "`cat /etc/system-release 2>&1`" = "Amazon Linux release 2 (Karoo)" ]; then + COPTION="--session-command" else - # In this case we're running sudo riak - so have root access, but cannot rely - # systemd having created the PID dir, and need to sudo to the riak user - if [ ! -d $PID_DIR ]; then - mkdir $PID_DIR - chown riak:riak $PID_DIR - fi - case "$1" in - start|console|foreground) - su - riak -c "NODETOOL_NODE_PREFIX=${NODETOOL_NODE_PREFIX} RELX_CONFIG_PATH=${RELX_CONFIG_PATH} VMARGS_PATH=${VMARGS_PATH} RUNNER_LOG_DIR=${RUNNER_LOG_DIR} PIPE_DIR=${PIPE_DIR} ${COMMAND} ${*} -pa {{platform_lib_dir}}/patches" - ;; - debug) - # Drop the "debug" from the args as we're going to directly call riak-debug now - shift - # Debug may fail if run via relx script due to use of relative start location, and also need for root access - NODETOOL_NODE_PREFIX=${NODETOOL_NODE_PREFIX} RELX_CONFIG_PATH=${RELX_CONFIG_PATH} VMARGS_PATH=${VMARGS_PATH} RUNNER_LOG_DIR=${RUNNER_LOG_DIR} PIPE_DIR=${PIPE_DIR} ${DEBUG_COMMAND} ${*} - ;; - *) - ESCAPED_ARGS=`echo "$@" | sed -e 's/\([\\\(\\\){}"\x27]\)/\\\\\1/g'` - su - riak -c "NODETOOL_NODE_PREFIX=${NODETOOL_NODE_PREFIX} RELX_CONFIG_PATH=${RELX_CONFIG_PATH} VMARGS_PATH=${VMARGS_PATH} RUNNER_LOG_DIR=${RUNNER_LOG_DIR} PIPE_DIR=${PIPE_DIR} ${COMMAND} ${ESCAPED_ARGS}" - ;; - esac + COPTION="-c" fi +function maybe_su { + if [[ $EUID -ne 0 ]]; then + $* + else + # if we are executing an admin command that spins up a + # (hidden) node to then execute custom erlang code via -eval, + # we need to cd to a dir containing the erlang cookie + # (previously implicitly done by su -, which option we have + # removed in order to allow any env vars to be available for + # the ultimate invocation of riak/riak-cs/stanchion) + cd "{{platform_base_dir}}" + # freebsd su is fairly limited, so: + mkdir -p "$RUNNER_GEN_DIR" + chown riak:riak "$RUNNER_GEN_DIR" + f=`mktemp "$RUNNER_GEN_DIR"/su_piggy-XXXXXXX` + cat >"$f" < /dev/null | cut -d = -f 2 | tr -d ' '` + +NODE={{node}} +HOST=${NODE#*@} + +BOOT_FILE="${PLATFORM_BASE_DIR}/releases/{{release_version}}/start_clean" usage() { echo "Usage: $SCRIPT { cluster | join | leave | backup | restore | test | " - echo " reip | js-reload | erl-reload | wait-for-service | " + echo " reip | erl-reload | wait-for-service | " echo " ringready | transfers | force-remove | down |" echo " cluster-info | member-status | ring-status | vnode-status |" echo " aae-status | diag | stat | status | transfer-limit | reformat-indexes |" echo " top [-interval N] [-sort reductions|memory|msg_q] [-lines N] |" echo " downgrade-objects | security | bucket-type | repair-2i |" - echo " search | services | ensemble-status | handoff | set |" + echo " services | ensemble-status | handoff | set |" echo " show | describe }" } @@ -33,23 +55,23 @@ stat_admin() case "$1" in show) shift - relx_nodetool rpc riak_core_console stat_show "$*" + rpc riak_core_console stat_show "$@" ;; - info) + info) shift - relx_nodetool rpc riak_core_console stat_info "$*" + rpc riak_core_console stat_info "$@" ;; enable) shift - relx_nodetool rpc riak_core_console stat_enable "$*" + rpc riak_core_console stat_enable "$@" ;; disable) shift - relx_nodetool rpc riak_core_console stat_disable "$*" + rpc riak_core_console stat_disable "$@" ;; reset) shift - relx_nodetool rpc riak_core_console stat_reset "$*" + rpc riak_core_console stat_reset "$@" ;; help) shift @@ -235,13 +257,13 @@ cluster_admin() echo "Usage: $SCRIPT cluster join " exit 1 fi - relx_nodetool rpc riak_kv_console staged_join "$2" + rpc riak_kv_console staged_join "$2" ;; leave) if [ $# -eq 1 ]; then - relx_nodetool rpc riak_core_console stage_leave + rpc riak_core_console stage_leave elif [ $# -eq 2 ]; then - relx_nodetool rpc riak_core_console stage_leave "$2" + rpc riak_core_console stage_leave "$2" else echo "Usage: $SCRIPT cluster leave []" exit 1 @@ -252,21 +274,21 @@ cluster_admin() echo "Usage: $SCRIPT cluster force-remove " exit 1 fi - relx_nodetool rpc riak_core_console stage_remove "$2" + rpc riak_core_console stage_remove "$2" ;; replace) if [ $# -ne 3 ]; then echo "Usage: $SCRIPT cluster replace " exit 1 fi - relx_nodetool rpc riak_core_console stage_replace "$2" "$3" + rpc riak_core_console stage_replace "$2" "$3" ;; force-replace) if [ $# -ne 3 ]; then echo "Usage: $SCRIPT cluster force-replace " exit 1 fi - relx_nodetool rpc riak_core_console stage_force_replace "$2" "$3" + rpc riak_core_console stage_force_replace "$2" "$3" ;; resize-ring) if [ $# -ne 2 ]; then @@ -274,30 +296,30 @@ cluster_admin() echo " $SCRIPT cluster resize-ring abort" exit 1 fi - relx_nodetool rpc riak_core_console stage_resize_ring "$2" + rpc riak_core_console stage_resize_ring "$2" ;; plan) - relx_nodetool rpc riak_core_console print_staged + rpc riak_core_console print_staged ;; commit) - relx_nodetool rpc riak_core_console commit_staged + rpc riak_core_console commit_staged ;; clear) - relx_nodetool rpc riak_core_console clear_staged + rpc riak_core_console clear_staged ;; status) - relx_nodetool rpc riak_core_console command $SCRIPT cluster $@ + rpc riak_core_console command $SCRIPT cluster "$@" ;; partitions|partition) - relx_nodetool rpc riak_core_console command $SCRIPT cluster $@ + rpc riak_core_console command $SCRIPT cluster "$@" ;; partition[_-]count) shift - relx_nodetool rpc riak_core_console command $SCRIPT cluster partition-count $@ + rpc riak_core_console command $SCRIPT cluster partition-count "$@" ;; location) shift - relx_nodetool rpc riak_core_console command $SCRIPT cluster location $@ + rpc riak_core_console command $SCRIPT cluster location "$@" ;; *) echo "\ @@ -360,9 +382,9 @@ security_admin() echo "Usage: $SCRIPT security add-user [