Skip to content

Commit c46cf2f

Browse files
Vagabondjaredmorrow
authored andcommitted
Update node package so it is flexible enough to be used for riak
This commit reorganizes and refactors node_package so that it can be used for Riak. It also, adds FreeBSD package support.
1 parent 3aacdb3 commit c46cf2f

28 files changed

Lines changed: 1475 additions & 148 deletions

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
export
55

66
OS = $(shell uname -s)
7-
ERLANG_BIN ?= $(shell dirname $(shell which erl))
7+
ERLANG_BIN ?= $(shell dirname $(shell which erl))
88

99
##
1010
## Support RPM and Debian based linux systems
1111
##
1212
ifeq ($(OS),Linux)
13-
ARCH = $(shell uname -m)
14-
ISRPM = $(shell cat /etc/redhat-release 2> /dev/null)
13+
ARCH = $(shell uname -m)
14+
ISRPM = $(shell cat /etc/redhat-release 2> /dev/null)
1515
ISDEB = $(shell cat /etc/debian_version 2> /dev/null)
1616
ifneq ($(ISRPM),)
17-
OSNAME = RedHat
17+
OSNAME= RedHat
1818
PKGERDIR = rpm
19-
BUILDDIR = rpmbuild
19+
BUILDDIR = rpmbuild
2020
else
2121
ifneq ($(ISDEB),)
22-
OSNAME = Debian
22+
OSNAME = Debian
2323
PKGERDIR = deb
24-
BUILDDIR = debuild
24+
BUILDDIR = debuild
2525
endif # deb
2626
endif # rpm
2727
endif # linux
@@ -33,10 +33,14 @@ PKGERDIR = osx
3333
BUILDDIR = osxbuild
3434
endif
3535

36-
DATE = $(shell date +%Y-%m-%d)
36+
ifeq ($(OS),FreeBSD)
37+
OSNAME = FreeBSD
38+
ARCH = $(shell uname -m)
39+
PKGERDIR = fbsd
40+
BUILDDIR = fbsdbuild
41+
endif
3742

38-
# Set the version that shows for `<app> version`
39-
VERSIONSTRING = $(PKG_NAME) ($(PKG_VERSION) $(DATE)) $(OSNAME) $(ARCH)
43+
DATE = $(shell date +%Y-%m-%d)
4044

4145
# Default the package build version to 1 if not already set
4246
PKG_BUILD ?= 1
@@ -46,7 +50,7 @@ PKG_BUILD ?= 1
4650
## Check required settings before continuing
4751
ostype: varcheck
4852
$(if $(PKGERDIR),,$(error "Operating system '$(OS)' not supported by node_package"))
49-
make -f $(PKG_ID)/deps/node_package/priv/templates/$(PKGERDIR)/Makefile.bootstrap
53+
$(MAKE) -f $(PKG_ID)/deps/node_package/priv/templates/$(PKGERDIR)/Makefile.bootstrap
5054

5155
varcheck:
5256
$(if $(PKG_VERSION),,$(error "Variable PKG_VERSION must be set and exported, see basho/node_package readme"))

README.org

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
* node_package
22
** Overview
33

4-
node_package is a set of RPM/Debian/Solaris templates and scripts, suitable for packaging embedded Erlang nodes.
4+
`node_package` is a set of RPM/Debian/Solaris templates and scripts, suitable for
5+
packaging embedded Erlang nodes.
56

67
*** Supported Operating Systems
78

@@ -22,38 +23,55 @@ Planned supported operating systems
2223

2324
The following variables need to be exported for node_package to work correctly.
2425

25-
- =PKG_NAME= - The name of your application (ex: riak)
2626
- =PKG_VERSION= - The version of your application (ex: 1.2.0)
27-
- =PKG_ID= - The full name of the package, typically =PKG_NAME-PKG_VERSION= (ex: riak-1.2.0)
27+
- =PKG_ID= - The full name of the package, typically ={{package_name}}-PKG_VERSION=
28+
(ex: riak-1.2.0)
2829

2930
**** Defaulted Variables
3031

31-
The following variables will have a default, but can be overriden in your application.
32+
The following variables will have a default, but can be overriden in your
33+
application.
3234

33-
- =PKG_BUILD= - (Default: 1) Sets the "release" version of the build (ex: app-5.4-1 <- the '1')
34-
- =ERLANG_BIN= - (Default: `which erl`) Sets the path of the current erlang binary
35+
- =PKG_BUILD= - (Default: 1) Sets the "release" version of the build
36+
(ex: app-5.4-1 <- the '1')
37+
- =ERLANG_BIN= - (Default: `which erl`) Sets the path of the current erlang
38+
binary
3539

3640
** Variables
3741

3842
The following variables describe a package
3943

4044
*** Required Variables
4145
- =package_name= - The name of the package
46+
- =package_install_name= - The name used in the install directories
47+
eg: /usr/lib/{{package_install_name}}. Usually the same as package_name.
4248
- =package_shortdesc= - A short (< one line) description of the package
43-
- =package_install_name= - The name of the binary installed (can be different than the `package_name`)
4449
- =package_install_user= - The user to create and run the daemon from
4550
- =package_install_group= - The group to create and add the above user to
4651
- =copyright= - The copyright holder (ex: 2011 Basho Technologies, Inc)
4752
- =license_type= - The short desciption of what license the app is under
48-
- =vendor_name= - The name of the person or company who is releasing this package
49-
- =vendor_url= - The website of the person or company who is releasing this package
53+
- =vendor_name= - The name of the person or company who is releasing this
54+
package
55+
- =vendor_url= - The website of the person or company who is releasing this
56+
package
5057
- =vendor_contact_name= - The name of the maintainer (ex: Basho Packaging)
51-
- =vendor_contact_email= - The email address of the maintainer (ex: riak@basho.com)
52-
- =solaris_pkgname= - Package names for Solaris follow a naming convention of MAINTapp (ex: BASHOriak)
58+
- =vendor_contact_email= - The email address of the maintainer (ex: packages@basho.com)
59+
- =solaris_pkgname= - Package names for Solaris follow a naming convention of
60+
MAINTapp (ex: BASHOriak)
61+
- =runner_wait_process= - The erlang process to wait for to determine if your
62+
app started or not. (ex: `riak_core_node_watcher` in riak's case)
63+
5364

5465
*** Optional Variables
55-
- =license_full_text= - If the full text of a license needs to be included, use this variable
56-
- =deb_depends= - Dependencies you require on deb sytems. This should be a comma separated list.
66+
- =license_full_text= - If the full text of a license needs to be included, use
67+
this variable
68+
- =deb_depends= - Dependencies you require on deb sytems. This should be a
69+
comma separated list.
5770
- =package_desc= - A long description of the package
58-
- =solaris_depends= - (not supported yet) Dependencies specific to the solaris package
71+
- =solaris_depends= - (not supported yet) Dependencies specific to the solaris
72+
package
5973
- =package_install_user_desc= - The description of the user created for the app
74+
- =runner_ulimit_warn= - The runner script will warn if `ulimit -n` is less than
75+
this value. This defaults to 4096 in all packages.
76+
- =platform_patch_dir= - Directory to include in erlang's load path to allow for
77+
patches to be hotloaded. (ex: {platform_lib_dir}/basho-patches)

priv/base/env.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ RUNNER_SCRIPT=${0##*/}
2121
RUNNER_BASE_DIR={{runner_base_dir}}
2222
RUNNER_ETC_DIR={{runner_etc_dir}}
2323
RUNNER_LOG_DIR={{runner_log_dir}}
24+
RUNNER_PATCH_DIR={{platform_patch_dir}}
2425
PIPE_DIR={{pipe_dir}}
2526
RUNNER_USER={{runner_user}}
2627
APP_VERSION={{app_version}}
2728

2829
# Threshold where users will be warned of low ulimit file settings
29-
ULIMIT_WARN=4096
30+
ULIMIT_WARN={{runner_ulimit_warn}}
31+
32+
# Registered process to wait for to consider start a success
33+
WAIT_FOR_PROCESS={{runner_wait_process}}
3034

3135
WHOAMI=$(whoami)
3236

@@ -126,10 +130,38 @@ check_config() {
126130
# Function to check if ulimit is properly set
127131
check_ulimit() {
128132

129-
ULIMIT_F=`ulimit -n`
130-
if [ "$ULIMIT_F" -lt $ULIMIT_WARN ]; then
131-
echo "!!!!"
132-
echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; ${ULIMIT_WARN} is the recommended minimum."
133-
echo "!!!!"
133+
# don't fail if this is unset
134+
if [ ! -z "$ULIMIT_WARN" ]; then
135+
ULIMIT_F=`ulimit -n`
136+
if [ "$ULIMIT_F" -lt $ULIMIT_WARN ]; then
137+
echo "!!!!"
138+
echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; ${ULIMIT_WARN} is the recommended minimum."
139+
echo "!!!!"
140+
fi
141+
fi
142+
}
143+
144+
# Set the PID global variable, return 1 on error
145+
get_pid() {
146+
PID=`$NODETOOL getpid < /dev/null`
147+
ES=$?
148+
if [ "$ES" -ne 0 ]; then
149+
echo "Node is not running!"
150+
return 1
151+
fi
152+
153+
# don't allow empty or init pid's
154+
if [ -z $PID ] || [ "$PID" -le 1 ]; then
155+
return 1
134156
fi
157+
158+
return 0
159+
}
160+
161+
subcommand() {
162+
main_usage
163+
}
164+
165+
subcommand_usage() {
166+
return 0
135167
}

priv/base/nodetool

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ main(Args) ->
5454
end,
5555

5656
case RestArgs of
57+
["getpid"] ->
58+
io:format("~p\n", [list_to_integer(rpc:call(TargetNode, os, getpid, []))]);
5759
["ping"] ->
5860
%% If we got this far, the node already responsed to a ping, so just dump
5961
%% a "pong"

priv/base/runner

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ if [ "$ES" -ne 0 ]; then
1414
exit $ES
1515
fi
1616

17+
# Keep track of where script was invoked
18+
ORIGINAL_DIR=$(pwd)
19+
1720
# Make sure CWD is set to runner run dir
1821
cd $RUNNER_BASE_DIR
1922

23+
# Identify the script name
24+
SCRIPT=`basename $0`
25+
26+
usage() {
27+
echo "Usage: $SCRIPT {start | stop| restart | reboot | ping | console | attach | "
28+
echo " ertspath | chkconfig | escript | version | getpid |"
29+
echo " top [-interval N] [-sort reductions|memory|msg_q] [-lines N] }"
30+
}
31+
32+
2033
# Check the first argument for instructions
2134
case "$1" in
2235
start)
@@ -45,6 +58,33 @@ case "$1" in
4558
mkdir -p $PIPE_DIR
4659
$ERTS_PATH/run_erl -daemon $PIPE_DIR/ $RUNNER_LOG_DIR \
4760
"exec $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT console" 2>&1
61+
62+
if [ ! -z "$WAIT_FOR_PROCESS" ]; then
63+
# Wait for the node to come up. We can't just ping it because
64+
# distributed erlang comes up for a second before the node crashes
65+
# (eg. in the case of an unwriteable disk). Once the node comes
66+
# up we check for the $WAIT_FOR_PROCESS} process. If that's running
67+
# then we assume things are good enough. This will at least let
68+
# the user know when the node is crashing right after startup.
69+
WAIT=${WAIT_FOR_ERLANG:-15}
70+
while [ $WAIT -gt 0 ]; do
71+
WAIT=`expr $WAIT - 1`
72+
sleep 1
73+
RES=`ping_node`
74+
if [ "$?" -ne 0 ]; then
75+
continue
76+
fi
77+
PROCESS=`$NODETOOL rpcterms erlang whereis "'${WAIT_FOR_PROCESS}'."`
78+
if [ "$PROCESS" != "undefined" ]; then
79+
exit 0
80+
fi
81+
done
82+
echo "${SCRIPT} failed to start within ${WAIT_FOR_ERLANG:-15} seconds,"
83+
echo "see the output of '${SCRIPT} console' for more information."
84+
echo "If you want to wait longer, set the environment variable"
85+
echo "WAIT_FOR_ERLANG to the number of seconds to wait."
86+
exit 1
87+
fi
4888
;;
4989

5090
stop)
@@ -153,7 +193,7 @@ case "$1" in
153193
PROGNAME=`echo $0 | sed 's/.*\///'`
154194
CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$RUNNER_SCRIPT \
155195
-embedded -config $RUNNER_ETC_DIR/app.config \
156-
-pa $RUNNER_LIB_DIR/basho-patches \
196+
-pa $RUNNER_PATCH_DIR \
157197
-args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
158198
export EMU
159199
export ROOTDIR
@@ -181,7 +221,7 @@ case "$1" in
181221
MYPID=$$
182222
NODE_NAME=${NAME_ARG#* }
183223
$ERTS_PATH/erl -noshell -noinput \
184-
-pa $RUNNER_LIB_DIR/basho-patches \
224+
-pa $RUNNER_PATCH_DIR \
185225
-hidden $NAME_PARAM np_etop$MYPID$NAME_HOST $COOKIE_ARG \
186226
-s etop -s erlang halt -output text \
187227
-node $NODE_NAME \
@@ -200,12 +240,17 @@ case "$1" in
200240
version)
201241
echo $APP_VERSION
202242
;;
203-
243+
getpid)
244+
# Get the PID from nodetool
245+
get_pid
246+
ES=$?
247+
if [ "$ES" -ne 0 ] || [ -z $PID ]; then
248+
exit $ES
249+
fi
250+
echo $PID
251+
;;
204252
*)
205-
echo "Usage: $SCRIPT {start | stop| restart| reboot| ping| console| attach| "
206-
echo " ertspath| chkconfig| escript| version | "
207-
echo " top [-interval N] [-sort reductions|memory|msg_q] [-lines N] }"
208-
exit 1
253+
usage
209254
;;
210255
esac
211256

priv/templates/deb/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
default:
3+
ln -sf $(PKG_ID).tar.gz ../{{package_name}}_$(PKG_VERSION).orig.tar.gz
34
export DEBFULLNAME="{{vendor_contact_name}}"; \
45
export DEBEMAIL="{{vendor_contact_email}}"; \
56
dch --create --package {{package_name}} -v "$(PKG_VERSION)-$(PKG_BUILD)" \

priv/templates/deb/Makefile.bootstrap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
export
66

77
bootstrap:
8-
ln -s $(PKG_ID).tar.gz $(PKG_NAME)_$(PKG_VERSION).orig.tar.gz
98
mkdir -p $(PKG_ID)/debian
109
cd $(PKG_ID)/debian && $(REBAR) -v create \
11-
package_name=$(PKG_NAME) \
1210
template_dir=../deps/node_package/priv/templates \
1311
template_vars=../pkg.vars.config template=deb
1412
make -C $(PKG_ID) -f debian/Makefile

priv/templates/deb/deb.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
{vendor_contact_email, "vendor_contact_email"},
1313
{copyright, "copyright"},
1414
{license_type, "license_type"},
15-
{license_full_text, ""}
15+
{license_full_text, ""},
16+
{bin_or_sbin, "bin"},
17+
{runner_ulimit_warn, "4096"}
1618
]
1719
}.
1820
{template, "Makefile", "Makefile"}.
@@ -25,4 +27,3 @@
2527
{template, "rules", "rules"}.
2628
{template, "vars.config", "vars.config"}.
2729
{template, "init.script", "init.script"}.
28-

0 commit comments

Comments
 (0)