Skip to content

Commit 6ea15f1

Browse files
committed
Merge pull request #60 from basho/jem-smartos-patches
Add support for SmartOS 13.1
2 parents 29d7c64 + ab70641 commit 6ea15f1

File tree

5 files changed

+156
-24
lines changed

5 files changed

+156
-24
lines changed

priv/templates/smartos/+INSTALL

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh
22

3+
# Variable that will get replaced by the Makefile dirs_create target
4+
CREATE_DIRS="%DIRS_CREATE%"
5+
36
if [ "$2" = "PRE-INSTALL" ]; then
47
if ! getent group "{{package_install_group}}" 2>/dev/null 1>&2; then
58
groupadd {{package_install_group}}
@@ -10,13 +13,17 @@ if [ "$2" = "PRE-INSTALL" ]; then
1013
fi
1114

1215
# Create var directories outside of +CONTENTS
13-
mkdir -p {{platform_data_dir}}
14-
chown -R {{package_install_user}}:{{package_install_group}} {{platform_data_dir}}
15-
chmod 700 {{platform_data_dir}}
16-
mkdir -p {{platform_log_dir}}
17-
chmod 700 {{platform_log_dir}}
18-
chown -R {{package_install_user}}:{{package_install_group}} {{platform_log_dir}}
19-
16+
# Read directories from the CREATE_DIRS variable
17+
for i in $CREATE_DIRS; do
18+
if [ -d $i ]; then
19+
echo "Skipping directory creation of $i, directory already exists"
20+
else
21+
echo "Creating directory $i owned by {{package_install_user}}"
22+
mkdir -p $i
23+
chown -R {{package_install_user}}:{{package_install_group}} $i
24+
chmod 700 $i
25+
fi
26+
done
2027

2128
# Backup config files if they already exist
2229
if [ -f {{platform_etc_dir}}/vm.args ]; then
@@ -61,5 +68,3 @@ if [ "$2" = "POST-INSTALL" ]; then
6168
chmod 755 /opt/local/share/smf/{{package_install_name}}-epmd/{{package_install_name}}-epmd
6269
svccfg import /opt/local/share/smf/{{package_install_name}}/manifest.xml
6370
fi
64-
65-
exit 0

priv/templates/smartos/Makefile

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,69 @@ BUILDDIR = $(shell pwd)
44
PACKAGE_NAME_CLEAN = $(shell echo "{{package_name}}" | sed -e 's/-/_/g')
55
BUILD_STAGE_DIR = $(BUILDDIR)/$(PACKAGE_NAME_CLEAN)
66

7+
## Version Information
8+
## ## pkgsrc version mapping to SmartOS version
9+
## SmartOS pkgsrc
10+
## 1.6 2011Q4
11+
## 1.8 2012Q2
12+
## 13.1 2013Q1
13+
## ## Erlang Deps by version
14+
## SmartOS openssl ncurses
15+
## 1.6 0.9.8knb1 5.4nb1
16+
## 1.8 0.9.8knb1 5.4nb1
17+
## 13.1 1.0.1c 5.4nb1
18+
## ## Additional Deps for runner
19+
## sudo (same for all versions)
20+
##
21+
## ## SMF Manifest Mapping
22+
## SmartOS Manifest File
23+
## 1.6 manifest.xml
24+
## 1.8 manifest18.xml
25+
## 13.1 manifest18.xml
26+
27+
PKGSRC_VERSION = $(shell head -1 /etc/pkgsrc_version 2>/dev/null | cut -d' ' -f2)
28+
29+
ifeq ($(PKGSRC_VERSION),2011Q4) # SmartOS 1.6
30+
NCURSES_DEP = ncurses-5*
31+
OPENSSL_DEP = openssl-0.9.8*
32+
GCC_DEP = gcc-runtime-4.6.2
33+
SMF_MANIFEST = manifest.xml
34+
endif
35+
ifeq ($(PKGSRC_VERSION),2012Q2) # SmartOS 1.8
36+
NCURSES_DEP = ncurses-5*
37+
OPENSSL_DEP = openssl-0.9.8*
38+
GCC_DEP = gcc47-runtime>=4.7.0
39+
SMF_MANIFEST = manifest18.xml
40+
endif
41+
ifeq ($(PKGSRC_VERSION),2013Q1) # SmartOS 13.1
42+
NCURSES_DEP = ncurses-5*
43+
OPENSSL_DEP = openssl-1.0.1*
44+
GCC_DEP = gcc47-libs>=4.7.0
45+
SMF_MANIFEST = manifest131.xml
46+
endif
747

8-
# SmartOS changed pkgsrc versions which majorly changed
9-
# the layout of the filesystem. SmartOS 1.6 uses a
10-
# different SMF manifest file than newer versions
11-
SMF_MANIFEST = $(shell head -1 /etc/pkgsrc_version | \
12-
grep -c 2011Q4 2> /dev/null | awk \
13-
'{if ($$1 == "1") {print "manifest.xml"} else {print "manifest18.xml"}}')
1448

1549
# Where we install things (based on vars.config)
1650
# /opt/local based dirs
51+
# /var based dirs are handled in the +INSTALL file and dirs_file target
1752
PMAN_DIR := $(BUILD_STAGE_DIR)/man
1853
PBIN_DIR := $(BUILD_STAGE_DIR)/{{bin_or_sbin}}
1954
PETC_DIR := $(BUILD_STAGE_DIR)/etc/{{package_install_name}}
2055
PLIB_DIR := $(BUILD_STAGE_DIR)/lib/{{package_install_name}}
2156
PSMF_DIR := $(BUILD_STAGE_DIR)/share/smf/{{package_install_name}}
2257
ESMF_DIR := $(BUILD_STAGE_DIR)/share/smf/{{package_install_name}}-epmd
58+
PDATA_DIR := $(BUILD_STAGE_DIR)/{{platform_data_dir}}
59+
60+
# For scanning later, grab the first dirname
61+
# '/var/db/server' becomes 'var'
62+
PDATA_ROOT_DIR = $(shell echo "{{platform_data_dir}}" | cut -d'/' -f 2)
63+
64+
2365

2466
# Recursive assignment of ERTS version
2567
# We will know this after building the rel
2668
ERTS_PATH = $(shell ls $(BUILDDIR)/rel/{{package_install_name}} | egrep -o "erts-.*")
2769

28-
# /var based dirs are handled in the +INSTALL file
29-
3070
TARNAME := $(PACKAGE_NAME_CLEAN)-$(PKG_VERSION)-$(OSNAME)-$(ARCH).tar
3171
PKGNAME := $(PACKAGE_NAME_CLEAN)-$(PKG_VERSION)-$(OSNAME)-$(ARCH).tgz
3272

@@ -36,7 +76,7 @@ PKGNAME := $(PACKAGE_NAME_CLEAN)-$(PKG_VERSION)-$(OSNAME)-$(ARCH).tgz
3676
# particular order to not anger pkg_add.
3777
# This is done by piping the file listings into tar
3878
# in the same manner we did with the +CONTENTS file
39-
build: packing_list_files
79+
build: packing_list_files dirs_file
4080
@echo "Building package $(PKGNAME)"
4181
mkdir -p packages
4282
cd $(BUILD_STAGE_DIR) && \
@@ -58,6 +98,7 @@ build: packing_list_files
5898
shasum -a 256 $${tarfile} > $${tarfile}.sha \
5999
; done
60100

101+
61102
# Where most of the magic (horror?) happens
62103
# Create a packing list according to pkg_create(1)
63104
# Write initial settings to a local plist then copy
@@ -68,19 +109,23 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
68109
echo "@name $(PACKAGE_NAME_CLEAN)-$(PKG_VERSION)" >> plist
69110
echo "@pkgcfl $(PACKAGE_NAME_CLEAN)-*" >> plist
70111
echo "@pkgdep sudo-[0-9]*" >> plist
71-
echo "@pkgdep openssl-0.9.8*" >> plist
112+
echo "@pkgdep $(OPENSSL_DEP)" >> plist
113+
echo "@pkgdep $(NCURSES_DEP)" >> plist
114+
echo "@pkgdep $(GCC_DEP)" >> plist
72115

73116
@echo "Copying staging package listing to +CONTENTS"
74117
mv plist $(BUILD_STAGE_DIR)/+CONTENTS
75118

76119
@echo "Packaging /opt/local files"
77120
cd $(BUILD_STAGE_DIR) && \
121+
echo "@comment Packing manpage files" >> +CONTENTS && \
78122
echo "@cwd /opt/local" >> +CONTENTS && \
79123
echo "@owner root" >> +CONTENTS && \
80124
echo "@group root" >> +CONTENTS && \
81125
find man -type f >> +CONTENTS
82126

83127
cd $(BUILD_STAGE_DIR) && \
128+
echo "@comment Packing /opt/local/etc files" >> +CONTENTS && \
84129
echo "@cwd /opt/local" >> +CONTENTS && \
85130
echo "@owner root" >> +CONTENTS && \
86131
echo "@group {{package_install_user}}" >> +CONTENTS && \
@@ -90,17 +135,22 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
90135
echo "@exec chmod -R g+r+X {{platform_etc_dir}}" >> +CONTENTS
91136

92137
cd $(BUILD_STAGE_DIR) && \
138+
echo "@comment Packing lib files" >> +CONTENTS && \
93139
echo "@cwd /opt/local" >> +CONTENTS && \
94140
echo "@owner {{package_install_user}}" >> +CONTENTS && \
95141
echo "@group {{package_install_group}}" >> +CONTENTS
142+
96143
cd $(BUILD_STAGE_DIR) && \
97144
find lib -type f >> +CONTENTS && \
98145
echo "@exec chown -R {{package_install_user}}:{{package_install_group}} {{platform_base_dir}}" >> +CONTENTS
146+
99147
cd $(BUILD_STAGE_DIR) && \
148+
echo "@comment Packing /usr/local {{bin_or_sbin}} files" >> +CONTENTS && \
100149
echo "@owner {{package_install_user}}" >> +CONTENTS && \
101150
echo "@group {{package_install_group}}" >> +CONTENTS && \
102151
echo "@mode 0755" >> +CONTENTS && \
103152
find {{bin_or_sbin}} -type f >> +CONTENTS
153+
104154
cd $(BUILD_STAGE_DIR) && \
105155
echo "@owner {{package_install_user}}" >> +CONTENTS && \
106156
echo "@group {{package_install_group}}" >> +CONTENTS && \
@@ -110,11 +160,33 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
110160
echo "@display +DISPLAY" >> +CONTENTS
111161

112162

163+
# Creates a variable to be read by the +INSTALL script to
164+
# create directories not supported by the +CONTENTS file
165+
# such as log and data directories.
166+
# platform_log_dir and platform_data_dir are always added
167+
# This is black magic appending the directories to the
168+
# to a variable inside of the makefile target
169+
# and then using sed to insert that list into
170+
# the +INSTALL script.
171+
# I feel dirty now.
172+
dirs_file: $(BUILD_STAGE_DIR)
173+
@echo "Adding data and log directories to directory list"
174+
$(eval DIRS_INSTALL = {{platform_data_dir}})
175+
$(eval DIRS_INSTALL += {{platform_log_dir}})
176+
@echo "Scanning var directory for any additional install paths"
177+
$(eval DIRS_INSTALL += $(shell cd $(BUILD_STAGE_DIR) && find $(PDATA_ROOT_DIR) -type d -exec printf "/%s " {} \;))
178+
cd $(BUILD_STAGE_DIR) && \
179+
cp +INSTALL +INSTALL.tmp && \
180+
sed -e 's|%DIRS_CREATE%|${DIRS_INSTALL}|' < \
181+
+INSTALL.tmp > +INSTALL && \
182+
rm +INSTALL.tmp
183+
184+
113185
# These are static files that should not have to change often
114186
templates: $(BUILD_STAGE_DIR)
115187
@echo "Copying metadata files to package"
116188
cp $(PKGERDIR)/+DESC $(PKGERDIR)/+COMMENT $(PKGERDIR)/+DEINSTALL \
117-
$(PKGERDIR)/+INSTALL $(PKGERDIR)/+BUILD_INFO \
189+
$(PKGERDIR)/+INSTALL $(PKGERDIR)/+BUILD_INFO \
118190
$(PKGERDIR)/+DISPLAY $(BUILD_STAGE_DIR)
119191
mkdir -p $(PSMF_DIR)
120192
cp $(PKGERDIR)/$(SMF_MANIFEST) $(PSMF_DIR)/manifest.xml
@@ -131,6 +203,8 @@ templates: $(BUILD_STAGE_DIR)
131203
# The data and log directories need to go into /var, but the
132204
# smartos pkg_add doesn't allow this to be in the +CONTENTS
133205
# file so the directories are created in the +INSTALL script
206+
# We copy the data and log directories if they exist to make
207+
# scanning them easier later
134208
$(BUILD_STAGE_DIR): buildrel
135209
@echo "Copying rel directory to staging directory"
136210
mkdir -p $@
@@ -143,19 +217,30 @@ $(BUILD_STAGE_DIR): buildrel
143217
cp -R $(BUILDDIR)/rel/{{package_install_name}}/lib $(PLIB_DIR)
144218
cp -R $(BUILDDIR)/rel/{{package_install_name}}/erts-* $(PLIB_DIR)
145219
cp -R $(BUILDDIR)/rel/{{package_install_name}}/releases $(PLIB_DIR)
146-
echo "Copying man pages to staging directory"
220+
@echo "Copying man pages to staging directory"
147221
mkdir -p $(PMAN_DIR)
148222
if [ -d $(BUILDDIR)/doc/man/man1 ]; then \
149-
cp -R $(BUILDDIR)/doc/man/man1 $(PMAN_DIR); fi
223+
cp -R $(BUILDDIR)/doc/man/man1 $(PMAN_DIR); fi
224+
@echo "Copying data and log directories to staging directory"
225+
if [ -d $(BUILDDIR)/rel/{{package_install_name}}/data ]; then \
226+
mkdir -p $(PDATA_DIR) && \
227+
cp -R $(BUILDDIR)/rel/{{package_install_name}}/data/* $(PDATA_DIR); fi
150228

151229

230+
# If we can read the PKGSRC_VERSION we should fail
231+
# If NCURSES_DEP wasn't set, we know it was an unknown PKGSRC version
232+
smartos_check:
233+
@echo "Checking SmartOS Version"
234+
$(if $(PKGSRC_VERSION),,$(error "Cannot find pkgsrc version from /etc/pkgsrc_version, cannot continue"))
235+
$(if $(NCURSES_DEP),,$(error "Unsupported SmartOS version, please add to github.com/basho/node_package"))
236+
@echo "Building for pkgsrc version $(PKGSRC_VERSION)"
152237

153238
# Build the release we need to package
154239
# * Patch rel/files/riak with our version
155240
# * Ensure all binaries are executable
156241
# * copy the vars.config over for build config
157242
# TODO, solve the .patch issue we have in riak
158-
buildrel: $(BUILDDIR)
243+
buildrel: $(BUILDDIR) smartos_check
159244
OVERLAY_VARS="overlay_vars=../smartos/vars.config" $(MAKE) deps rel
160245
chmod 0755 $(BUILDDIR)/rel/{{package_install_name}}/bin/* $(BUILDDIR)/rel/{{package_install_name}}/erts-*/bin/*
161246

priv/templates/smartos/manifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<propval name="duration" type="astring" value="contract" />
3232
<propval name="ignore_error" type="astring" value="core,signal" />
3333
</property_group>
34-
<stability value="Evolving" />
34+
<stability value="Stable" />
3535
<template>
3636
<common_name>
3737
<loctext xml:lang="C">{{package_shortdesc}}</loctext>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
3+
<service_bundle type="manifest" name="{{package_install_name}}">
4+
<service name="application/{{package_install_name}}" type="service" version="1">
5+
<create_default_instance enabled="false" />
6+
<single_instance />
7+
<dependency name="network" grouping="require_all" restart_on="error" type="service">
8+
<service_fmri value="svc:/milestone/network:default" />
9+
</dependency>
10+
<dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
11+
<service_fmri value="svc:/system/filesystem/local" />
12+
</dependency>
13+
<dependency name="{{package_install_name}}-epmd" grouping="require_all" restart_on="error" type="service">
14+
<service_fmri value="svc:/network/{{package_install_name}}-epmd:default" />
15+
</dependency>
16+
<method_context working_directory="/tmp" project="{{package_install_name}}">
17+
<method_credential user="{{package_install_user}}" group="{{package_install_group}}" />
18+
<method_environment>
19+
<envvar name="HOME" value="{{platform_base_dir}}" />
20+
<envvar name="LOGNAME" value="{{package_install_user}}" />
21+
<envvar name="PATH" value="/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin" />
22+
<envvar name="LD_PRELOAD_32" value="/lib/libumem.so.1" />
23+
<envvar name="LD_PRELOAD_64" value="/lib/amd64/libumem.so.1:/opt/local/gcc47/lib/amd64/libgcc_s.so.1"/>
24+
<envvar name="UMEM_OPTIONS" value="allocator=best" />
25+
</method_environment>
26+
</method_context>
27+
<exec_method type="method" name="start" exec="{{platform_bin_dir}}/{{package_install_name}} start" timeout_seconds="60" />
28+
<exec_method type="method" name="stop" exec="{{platform_bin_dir}}/{{package_install_name}} stop" timeout_seconds="60" />
29+
<exec_method type="method" name="restart" exec="{{platform_bin_dir}}/{{package_install_name}} restart" timeout_seconds="60" />
30+
<property_group name="startd" type="framework">
31+
<propval name="duration" type="astring" value="contract" />
32+
<propval name="ignore_error" type="astring" value="core,signal" />
33+
</property_group>
34+
<stability value="Stable" />
35+
<template>
36+
<common_name>
37+
<loctext xml:lang="C">{{package_shortdesc}}</loctext>
38+
</common_name>
39+
</template>
40+
</service>
41+
</service_bundle>

priv/templates/smartos/smartos.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
{template, "epmd-manifest.xml", "epmd-manifest.xml"}.
3030
{template, "manifest.xml", "manifest.xml"}.
3131
{template, "manifest18.xml", "manifest18.xml"}.
32+
{template, "manifest131.xml", "manifest131.xml"}.
3233
{template, "epmd", "epmd"}.

0 commit comments

Comments
 (0)