Permalink
Browse files

Merge branch '2.0'

  • Loading branch information...
Jared Morrow
Jared Morrow committed Sep 4, 2014
2 parents d56b1bb + a56fe9b commit e535ac0fddcbc15f33edc502c158802cd6bdbe9a
Showing with 881 additions and 326 deletions.
  1. +47 −34 Makefile
  2. +9 −0 README.org
  3. +121 −42 priv/base/env.sh
  4. +22 −15 priv/base/nodetool
  5. +183 −155 priv/base/runner
  6. +2 −1 priv/templates/deb/Makefile
  7. +1 −1 priv/templates/deb/Makefile.bootstrap
  8. +1 −2 priv/templates/deb/control
  9. +12 −6 priv/templates/deb/init.script
  10. +1 −0 priv/templates/deb/postinst
  11. +1 −1 priv/templates/fbsd/Makefile
  12. +1 −1 priv/templates/fbsd/Makefile.bootstrap
  13. +18 −0 priv/templates/fbsdng/+MANIFEST
  14. +98 −0 priv/templates/fbsdng/Makefile
  15. +12 −0 priv/templates/fbsdng/Makefile.bootstrap
  16. +25 −0 priv/templates/fbsdng/fbsdng.template
  17. +19 −0 priv/templates/fbsdng/rc.d
  18. +20 −0 priv/templates/fbsdng/vars.config
  19. +1 −1 priv/templates/osx/Makefile
  20. +1 −1 priv/templates/osx/Makefile.bootstrap
  21. +14 −2 priv/templates/rpm/Makefile
  22. +1 −1 priv/templates/rpm/Makefile.bootstrap
  23. +11 −0 priv/templates/rpm/{init.script → rhel.init.script}
  24. +2 −1 priv/templates/rpm/rpm.template
  25. +44 −8 priv/templates/rpm/specfile
  26. +156 −0 priv/templates/rpm/suse.init.script
  27. +1 −1 priv/templates/smartos/+DISPLAY
  28. +33 −11 priv/templates/smartos/+INSTALL
  29. +2 −12 priv/templates/smartos/Makefile
  30. +1 −1 priv/templates/smartos/Makefile.bootstrap
  31. +0 −4 priv/templates/smartos/env.patch
  32. +16 −22 priv/templates/smartos/runner.patch
  33. +0 −1 priv/templates/smartos/smartos.template
  34. +3 −0 priv/templates/solaris/Makefile
  35. +1 −1 priv/templates/solaris/Makefile.bootstrap
  36. +1 −1 priv/templates/solaris/solaris.template
View
@@ -3,78 +3,91 @@
##
export
-OS = $(shell uname -s)
-ERLANG_BIN ?= $(shell dirname $(shell which erl))
+OS = $(shell uname -s)
+ERLANG_BIN ?= $(shell dirname $(shell which erl))
+DEPS_DIR ?= deps
##
## Support RPM and Debian based linux systems
##
ifeq ($(OS),Linux)
-ARCH = $(shell uname -m)
-ISRPM = $(shell cat /etc/redhat-release 2> /dev/null)
-ISDEB = $(shell cat /etc/debian_version 2> /dev/null)
+ARCH = $(shell uname -m)
+ISRPM = $(shell cat /etc/redhat-release 2> /dev/null)
+ISDEB = $(shell cat /etc/debian_version 2> /dev/null)
+ISSLES = $(shell cat /etc/SuSE-release 2> /dev/null)
ifneq ($(ISRPM),)
-OSNAME= RedHat
-PKGERDIR = rpm
-BUILDDIR = rpmbuild
+OSNAME = RedHat
+PKGERDIR = rpm
+BUILDDIR = rpmbuild
else
ifneq ($(ISDEB),)
-OSNAME = Debian
-PKGERDIR = deb
-BUILDDIR = debuild
+OSNAME = Debian
+PKGERDIR = deb
+BUILDDIR = debuild
+else
+ifneq ($(ISSLES),)
+OSNAME = SLES
+PKGERDIR = rpm
+BUILDDIR = rpmbuild
+endif # SLES
endif # deb
endif # rpm
endif # linux
ifeq ($(OS),Darwin) # OSX
-OSNAME = OSX
-ARCH = $(shell file `which erlc` | grep -c x86_64 2> /dev/null | awk \
- '{if ($$1 == "0") {print "i386"} else {print "x86_64"}}')
-PKGERDIR = osx
-BUILDDIR = osxbuild
+OSNAME = OSX
+ARCH = $(shell file `which erlc` | grep -c x86_64 2> /dev/null | awk \
+ '{if ($$1 == "0") {print "i386"} else {print "x86_64"}}')
+PKGERDIR = osx
+BUILDDIR = osxbuild
endif
ifeq ($(OS),FreeBSD)
-OSNAME = FreeBSD
-ARCH = $(shell uname -m)
-PKGERDIR = fbsd
-BUILDDIR = fbsdbuild
+OSNAME = FreeBSD
+ARCH = $(shell uname -m)
+BUILDDIR = fbsdbuild
+PKGNG = $(shell uname -r | awk -F. '{ print ($$1 > 9) ? "true" : "false" }')
+ifeq ($(PKGNG),true) # FreeBSD 10.0 or greater
+PKGERDIR = fbsdng
+else # Older FreeBSD pkg_add
+PKGERDIR = fbsd
+endif
endif
ifeq ($(OS),SunOS) # Solaris flavors
-KERNELVER = $(shell uname -v | grep -c joyent 2> /dev/null)
-ARCH = $(shell file `which erlc` | grep -c 64-bit 2> /dev/null | awk \
+KERNELVER = $(shell uname -v | grep -c joyent 2> /dev/null)
+ARCH = $(shell file `which erlc` | grep -c 64-bit 2> /dev/null | awk \
'{if ($$1 == "0") {print "i386"} else {print "x86_64"}}')
ifneq ($(KERNELVER),0) # SmartOS
-OSNAME = SmartOS
-PKGERDIR = smartos
-BUILDDIR = smartosbuild
+OSNAME = SmartOS
+PKGERDIR = smartos
+BUILDDIR = smartosbuild
else # Solaris / OmniOS
-DISTRO = $(shell head -1 /etc/release|awk \
- '{if ($$1 == "OmniOS") {print $$1} else {print "Solaris"}}')
-OSNAME = ${DISTRO}
-PKGERDIR = solaris
-BUILDDIR = solarisbuild
+DISTRO = $(shell head -1 /etc/release|awk \
+ '{if ($$1 == "OmniOS") {print $$1} else {print "Solaris"}}')
+OSNAME = ${DISTRO}
+PKGERDIR = solaris
+BUILDDIR = solarisbuild
endif
endif
-DATE = $(shell date +%Y-%m-%d)
+DATE = $(shell date +%Y-%m-%d)
# Default the package build version to 1 if not already set
-PKG_BUILD ?= 1
+PKG_BUILD ?= 1
.PHONY: ostype varcheck
## Call platform dependent makefile
ostype: varcheck setversion
$(if $(PKGERDIR),,$(error "Operating system '$(OS)' not supported by node_package"))
- $(MAKE) -f $(PKG_ID)/deps/node_package/priv/templates/$(PKGERDIR)/Makefile.bootstrap
+ $(MAKE) -f $(PKG_ID)/$(DEPS_DIR)/node_package/priv/templates/$(PKGERDIR)/Makefile.bootstrap
## Set app version
setversion: varcheck
- echo "{app_version, \"$(PKG_VERSION)\"}." >> $(PKG_ID)/deps/node_package/priv/templates/$(PKGERDIR)/vars.config
+ echo "{app_version, \"$(PKG_VERSION)\"}." >> $(PKG_ID)/$(DEPS_DIR)/node_package/priv/templates/$(PKGERDIR)/vars.config
## Check required settings before continuing
varcheck:
View
@@ -35,6 +35,8 @@ application.
(ex: app-5.4-1 <- the '1')
- =ERLANG_BIN= - (Default: `which erl`) Sets the path of the current erlang
binary
+ - =DEPS_DIR= - (Default: deps) Sets the deps directory of the project, most
+ projects uses 'deps'. Change this if something different is used.
** Package and Script Variables
@@ -78,6 +80,9 @@ The following variables describe a package and should be put in the
- =freebsd_package_category= - The subsection the package is filed under in FreeBSD
(ex: in this line, "ORIGIN: db/riak" 'db' would be the package_category)
This defaults to 'db' if not specified for lack of a better default.
+ - =debuild_extra_options= - This is added to pass extra flags to debuild
+ - =cuttlefish_conf= - If your app uses cuttlefish for configuration, this
+ is the filename you are using for configuration (ex: "riak.conf")
*** Script Variables
The following variables are used in the =env.sh= and =runner= scripts which can
@@ -93,6 +98,10 @@ your application's =vars.config=.
- =runner_user= - The username to run the application as
- =runner_wait_process= - Registered process to wait for to consider start a
success
+ - =cuttlefish_conf= - This is a rare case of a repeated variable since it is
+ used in packaging and the main runner scripts, you should have this set
+ in both the vars.config and pkg.vars.config (sadly this was the cleanest
+ solution).
*** Templating Order
There are several templating steps done in node_package:
View
@@ -41,44 +41,70 @@ if [ -z "$ULIMIT_WARN" ]; then
ULIMIT_WARN=4096
fi
-## Are we using cuttlefish (http://github.com/basho/cuttlefish)
-## for configuration
-CUTTLEFISH="{{cuttlefish}}"
-
# Registered process to wait for to consider start a success
WAIT_FOR_PROCESS={{runner_wait_process}}
-WHOAMI=$(whoami)
+WHOAMI=`whoami`
# Echo to stderr on errors
echoerr() { echo "$@" 1>&2; }
# Extract the target node name from node.args
-NAME_ARG=`egrep '^\-s?name' $RUNNER_ETC_DIR/vm.args`
+NAME_ARG=`egrep '^\-name' $RUNNER_ETC_DIR/vm.args 2> /dev/null`
if [ -z "$NAME_ARG" ]; then
- echoerr "vm.args needs to have either -name or -sname parameter."
- exit 1
+ NODENAME=`egrep '^[ \t]*nodename[ \t]*=[ \t]*' $RUNNER_ETC_DIR/{{cuttlefish_conf}} 2> /dev/null | tail -1 | cut -d = -f 2`
+ if [ -z "$NODENAME" ]; then
+ echoerr "vm.args needs to have a -name parameter."
+ echoerr " -sname is not supported."
+ exit 1
+ else
+ NAME_ARG="-name ${NODENAME# *}"
+ fi
fi
# Learn how to specify node name for connection from remote nodes
-echo "$NAME_ARG" | grep '^-sname' > /dev/null 2>&1
+NAME_PARAM="-name"
+echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
if [ "X$?" = "X0" ]; then
- NAME_PARAM="-sname"
- NAME_HOST=""
+ NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
else
- NAME_PARAM="-name"
- echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
- if [ "X$?" = "X0" ]; then
- NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
- else
- NAME_HOST=""
- fi
+ NAME_HOST=""
fi
# Extract the target cookie
-COOKIE_ARG=`grep '^\-setcookie' $RUNNER_ETC_DIR/vm.args`
+COOKIE_ARG=`grep '^\-setcookie' $RUNNER_ETC_DIR/vm.args 2> /dev/null`
if [ -z "$COOKIE_ARG" ]; then
- echoerr "vm.args needs to have a -setcookie parameter."
+ COOKIE=`egrep '^[ \t]*distributed_cookie[ \t]*=[ \t]*' $RUNNER_ETC_DIR/{{cuttlefish_conf}} 2> /dev/null | tail -1 | cut -d = -f 2`
+ if [ -z "$COOKIE" ]; then
+ echoerr "vm.args needs to have a -setcookie parameter."
+ exit 1
+ else
+ COOKIE_ARG="-setcookie $COOKIE"
+ fi
+fi
+
+# Extract the target net_ticktime
+NET_TICKTIME_ARG=`grep '^\-kernel net_ticktime' $RUNNER_ETC_DIR/vm.args 2> /dev/null`
+if [ -z "$NET_TICKTIME_ARG" ]; then
+ NET_TICKTIME=`egrep '^[ \t]*erlang.distribution.net_ticktime[ \t]*=[ \t]*' $RUNNER_ETC_DIR/{{cuttlefish_conf}} 2> /dev/null | tail -1 | cut -d = -f 2`
+ if [ -z "$NET_TICKTIME" ]; then
+ NET_TICKTIME_ARG=""
+ else
+ NET_TICKTIME_ARG="-kernel net_ticktime $NET_TICKTIME"
+ fi
+fi
+
+# Optionally specify a NUMA policy
+NUMACTL_ARG="{{numactl_arg}}"
+if [ -z "$NUMACTL_ARG" ]
+then
+ NUMACTL=""
+# Confirms `numactl` is in the path and validates $NUMACTL_ARG
+elif which numactl > /dev/null 2>&1 && numactl $NUMACTL_ARG ls /dev/null > /dev/null 2>&1
+then
+ NUMACTL="numactl $NUMACTL_ARG"
+else
+ echoerr "NUMACTL_ARG is specified in env.sh but numactl is not installed or NUMACTL_ARG is invalid."
exit 1
fi
@@ -91,9 +117,20 @@ APP_VSN=${START_ERL#* }
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"
+NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG $NET_TICKTIME_ARG"
NODETOOL_LITE="$ERTS_PATH/escript $ERTS_PATH/nodetool"
+
+## Are we using cuttlefish (http://github.com/basho/cuttlefish)
+## for configuration. This needs to come after the $ERTS_PATH
+## definition
+CUTTLEFISH="{{cuttlefish}}"
+if [ -z "$CUTTLEFISH" ]; then
+ CUTTLEFISH_COMMAND_PREFIX=""
+else
+ CUTTLEFISH_COMMAND_PREFIX="$ERTS_PATH/escript $ERTS_PATH/cuttlefish -e $RUNNER_ETC_DIR -s $RUNNER_LIB_DIR -d {{platform_data_dir}}/generated.configs -c $RUNNER_ETC_DIR/{{cuttlefish_conf}}"
+fi
+
# Ping node without stealing stdin
ping_node() {
$NODETOOL ping < /dev/null
@@ -104,7 +141,7 @@ ping_node() {
# read/write/delete .pid files during startup/shutdown
create_pid_dir() {
# Validate RUNNER_USER is set and they have permissions to write to /var/run
- # Don't continue if we've already sudo'd to RUNNER_USER
+ # Don't continue if we've already su'd to RUNNER_USER
if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
if [ -w $RUN_DIR ]; then
mkdir -p $PID_DIR
@@ -160,17 +197,58 @@ create_pid_file() {
fi
}
-# Function to su into correct user
-check_user() {
+
+# Simple way to check the correct user and fail early
+check_user_internal() {
# Validate that the user running the script is the owner of the
# RUN_DIR.
if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
- type sudo > /dev/null 2>&1
- if [ "$?" -ne 0 ]; then
- echoerr "sudo doesn't appear to be installed and your EUID isn't $RUNNER_USER" 1>&2
+ if [ "x$WHOAMI" != "xroot" ]; then
+ echo "You need to be root or use sudo to run this command"
exit 1
fi
- exec sudo -H -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $@
+ fi
+}
+
+# Function to su into correct user that is poorly named for historical
+# reasons (excuses)
+# This also serves as an entry point to most functions
+check_user() {
+ check_user_internal
+
+ # This call must be before the su call, when the user is dropped
+ # optional config will be brought in if available
+ load_default_os_config
+
+ # do not su again if we are already the runner user
+ if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
+ # Escape any double quotes that might be in the command line
+ # args. Without this, passing something like JSON on the command
+ # line will get stripped.
+ # Ex:
+ # riak-admin bucket-type create mytype '{"props": {"n_val": 4}}'
+ # would become
+ # riak-admin bucket-type create mytype {props: {n_val: 4}}
+ # after the arguments were passed into the new shell during exec su
+ #
+ # So this regex finds any '"', '{', or '}' and prepends with a '\'
+ ESCAPED_ARGS=`echo "$@" | sed -e 's/\([{}"]\)/\\\\\1/g'`
+
+ # This will drop priviledges into the runner user
+ # It exec's in a new shell and the current shell will exit
+ exec su - $RUNNER_USER -c "$RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $ESCAPED_ARGS"
+ fi
+}
+
+# Function to load default config files based on OS
+load_default_os_config() {
+ # Only run this if we already dropped to the runner user
+ if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" = "x$RUNNER_USER" ]); then
+ # Common config file on Debian-like systems
+ [ -r /etc/default/$RUNNER_SCRIPT ] && . /etc/default/$RUNNER_SCRIPT
+
+ # Common config file on RPM-like systems
+ [ -r /etc/sysconfig/$RUNNER_SCRIPT ] && . /etc/sysconfig/$RUNNER_SCRIPT
fi
}
@@ -195,17 +273,28 @@ node_up_check() {
# Function to check if the config file is valid
check_config() {
if [ -z "$CUTTLEFISH" ]; then
- CONFIG_FILE="$RUNNER_ETC_DIR/app.config"
+ # Note: we have added a parameter '-vm_args' to this. It
+ # appears redundant but it is not! the erlang vm allows us to
+ # access all arguments to the erl command EXCEPT '-args_file',
+ # so in order to get access to this file location from within
+ # the vm, we need to pass it in twice.
+ CONFIG_ARGS=" -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -vm_args $RUNNER_ETC_DIR/vm.args "
else
- cuttlefish
+ CONFIG_ARGS=`$CUTTLEFISH_COMMAND_PREFIX generate`
+ if [ "$?" -ne 0 ]; then
+ echoerr "Error generating config with cuttlefish"
+ echoerr " run \`$RUNNER_SCRIPT config generate -l debug\` for more information."
+ exit 1
+ fi
fi
- MUTE=`$NODETOOL_LITE chkconfig $CONFIG_FILE`
+ MUTE=`$NODETOOL_LITE chkconfig $CONFIG_ARGS`
if [ "$?" -ne 0 ]; then
- echoerr "Error reading $CONFIG_FILE"
+ echoerr "Error reading $CONFIG_ARGS"
exit 1
fi
echo "config is OK"
+ echo $CONFIG_ARGS
}
# Function to check if ulimit is properly set
@@ -237,13 +326,3 @@ get_pid() {
return 0
}
-
-# This guy sets $CONFIG_FILE to the absolute filename to the app.config
-# generated by cuttlefish
-cuttlefish() {
- CONFIG_FILE=`$ERTS_PATH/cuttlefish -e $RUNNER_ETC_DIR -s $RUNNER_LIB_DIR -c $RUNNER_ETC_DIR/{{cuttlefish_conf}}`
- if [ "$?" -ne 0 ]; then
- echoerr "Error generating config with cuttlefish, there should be logs"
- exit 1
- fi
-}
Oops, something went wrong.

0 comments on commit e535ac0

Please sign in to comment.