Tue Mar 11 14:07:04 2014 UTC ()
Introduce infrastructure support for SMF.

SMF is the Service Management Facility, the default init system in
Solaris and derivatives since version 10.  This adds "smf" to the list
of supported INIT_SYSTEM types, and makes it the default init system on
platforms where it is available.

Packages can introduce SMF support by providing a manifest file, by
default located in ${FILESDIR}/smf/manifest.xml but manifests under
${WRKSRC} can be used too if the package source includes one.

SMF method scripts are supported too if required, using SMF_METHODS in a
similar manner to RCD_SCRIPTS.

Many parts of the SMF infrastructure are configurable, see mk/smf.mk for
the full details.


(jperkin)
diff -r1.1996 -r1.1997 pkgsrc/mk/bsd.pkg.mk
diff -r0 -r1.1 pkgsrc/mk/smf.mk
diff -r1.237 -r1.238 pkgsrc/mk/defaults/mk.conf
diff -r0 -r1.1 pkgsrc/mk/install/install-smf
diff -r1.57 -r1.58 pkgsrc/mk/platform/SunOS.mk
diff -r0 -r1.1 pkgsrc/mk/plist/plist-smf.awk

cvs diff -r1.1996 -r1.1997 pkgsrc/mk/bsd.pkg.mk (expand / switch to unified diff)

--- pkgsrc/mk/bsd.pkg.mk 2014/03/11 13:45:07 1.1996
+++ pkgsrc/mk/bsd.pkg.mk 2014/03/11 14:07:04 1.1997
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: bsd.pkg.mk,v 1.1996 2014/03/11 13:45:07 jperkin Exp $ 1# $NetBSD: bsd.pkg.mk,v 1.1997 2014/03/11 14:07:04 jperkin Exp $
2# 2#
3# This file is in the public domain. 3# This file is in the public domain.
4# 4#
5# Please see the pkgsrc/doc/guide manual for details on the 5# Please see the pkgsrc/doc/guide manual for details on the
6# variables used in this make file template. 6# variables used in this make file template.
7# 7#
8# Default sequence for "all" is: 8# Default sequence for "all" is:
9# 9#
10# bootstrap-depends 10# bootstrap-depends
11# fetch 11# fetch
12# checksum 12# checksum
13# depends 13# depends
14# tools 14# tools
@@ -308,26 +308,29 @@ _PKGSRC_BUILD_TARGETS= build @@ -308,26 +308,29 @@ _PKGSRC_BUILD_TARGETS= build
308# ${WRKSRC} up to which we find the files that need to be 308# ${WRKSRC} up to which we find the files that need to be
309# overridden. By default, we search two levels down, i.e., 309# overridden. By default, we search two levels down, i.e.,
310# */*/file. 310# */*/file.
311# 311#
312OVERRIDE_DIRDEPTH?= 2 312OVERRIDE_DIRDEPTH?= 2
313 313
314# Handle alternatives 314# Handle alternatives
315# 315#
316.include "alternatives.mk" 316.include "alternatives.mk"
317 317
318# Support alternative init systems. 318# Support alternative init systems.
319# 319#
320INIT_SYSTEM?= rc.d 320INIT_SYSTEM?= rc.d
 321.if ${INIT_SYSTEM} == "smf"
 322. include "smf.mk"
 323.endif
321_BUILD_DEFS+= INIT_SYSTEM 324_BUILD_DEFS+= INIT_SYSTEM
322 325
323# Define SMART_MESSAGES in /etc/mk.conf for messages giving the tree 326# Define SMART_MESSAGES in /etc/mk.conf for messages giving the tree
324# of dependencies for building, and the current target. 327# of dependencies for building, and the current target.
325_PKGSRC_IN?= ===${SMART_MESSAGES:D> ${.TARGET} [${PKGNAME}${_PKGSRC_DEPS}] ===} 328_PKGSRC_IN?= ===${SMART_MESSAGES:D> ${.TARGET} [${PKGNAME}${_PKGSRC_DEPS}] ===}
326 329
327# Used to print all the '===>' style prompts - override this to turn them off. 330# Used to print all the '===>' style prompts - override this to turn them off.
328ECHO_MSG?= ${ECHO} 331ECHO_MSG?= ${ECHO}
329PHASE_MSG?= ${ECHO_MSG} ${_PKGSRC_IN:Q}\> 332PHASE_MSG?= ${ECHO_MSG} ${_PKGSRC_IN:Q}\>
330STEP_MSG?= ${ECHO_MSG} "=>" 333STEP_MSG?= ${ECHO_MSG} "=>"
331INFO_MSG?= ${ECHO_MSG} "INFO:" 334INFO_MSG?= ${ECHO_MSG} "INFO:"
332WARNING_MSG?= ${ECHO_MSG} 1>&2 "WARNING:" 335WARNING_MSG?= ${ECHO_MSG} 1>&2 "WARNING:"
333ERROR_MSG?= ${ECHO_MSG} 1>&2 "ERROR:" 336ERROR_MSG?= ${ECHO_MSG} 1>&2 "ERROR:"

File Added: pkgsrc/mk/smf.mk
# $NetBSD: smf.mk,v 1.1 2014/03/11 14:07:04 jperkin Exp $
#
# Infrastructure support for the Service Management Facility (SMF).  This
# file will be sourced and used if INIT_SYSTEM is set to "smf".
#
# User-settable variables:
#
# SMF_PREFIX
#	This is the global FMRI prefix that will be used in SMF.  The
#	default is "pkgsrc", so the general URI will be of the form
#	"svc:/pkgsrc/<package>:<instance>".
#
# Package-settable variables:
#
# SMF_SRCDIR
#	The source directory containing manifest and method files.  This
#	defaults to ${FILESDIR}/smf and can be set to a location under
#	${WRKSRC} if necessary (i.e. the source includes SMF files).
#
# SMF_NAME
#	This sets the service name part of the FMRI, and defaults to the
#	lower-case string of PKGBASE.
#
# SMF_MANIFEST
#	The name of the XML file under SMF_SRCDIR which is to be used as
#	this package's manifest.  The default name is "manifest.xml"
#
# SMF_INSTANCES
#	The list of instances this manifest provides.  Manifests support
#	multiple instances, the default is a single "default" instance.
#
# SMF_METHODS
#	A list of SMF method scripts available under SMF_SRCDIR with
#	".sh" extensions to be generated and installed.
#
# SMF_METHOD_SRC.<method>
#	Allows you to override the source file name for a particular
#	method, if it does not follow the standard <method>.sh naming.
#
# SMF_METHOD_SHELL
#	The default shell to use in method scripts.
#

.if !defined(SMF_MK)
SMF_MK=				# defined

# Directory to hold the SMF manifest/method files
PKG_SMF_DIR?=			lib/svc
PKG_SMF_MANIFEST_DIR?=		${PKG_SMF_DIR}/manifest
PKG_SMF_METHOD_DIR?=		${PKG_SMF_DIR}/method

# Prefix of SMF services FMRI
SMF_PREFIX?=			pkgsrc

# Variables that can be overriden by the user on a package by package basis
SMF_NAME?=			${PKGBASE:tl}
SMF_INSTANCES?=			default
SMF_MANIFEST?=			manifest.xml
SMF_METHODS?=			# empty
SMF_METHOD_SHELL?=		/sbin/sh
SMF_SRCDIR?=			${FILESDIR}/smf

# Dynamically remove rc.d entries, primarily for pkgsrc-{joyent,wip}
PLIST_AWK+=			-f ${PKGSRCDIR}/mk/plist/plist-smf.awk

# A manifest file is a pre-requisite for anything to happen.  We cannot test
# for existance if the manifest is under WRKDIR as the source has not yet been
# unpacked, so we assume it will exist later when required.
.  if exists(${SMF_SRCDIR}/${SMF_MANIFEST}) || !empty(SMF_SRCDIR:M${WRKDIR}*)

SMF_MANIFEST_SRC?=		${SMF_SRCDIR}/${SMF_MANIFEST}
SMF_MANIFEST_WRK?=		${WRKDIR}/.smf_${SMF_MANIFEST}
SMF_MANIFEST_FILE?=		${PKG_SMF_MANIFEST_DIR}/${SMF_NAME}.xml

FILES_SUBST+=			PKGMANDIR=${PKGMANDIR:Q}
FILES_SUBST+=			SMF_PREFIX=${SMF_PREFIX:Q}
FILES_SUBST+=			SMF_NAME=${SMF_NAME:Q}
FILES_SUBST+=			SMF_INSTANCES=${SMF_INSTANCES:Q}
FILES_SUBST+=			SMF_MANIFEST=${SMF_MANIFEST:Q}
FILES_SUBST+=			SMF_MANIFEST_FILE=${SMF_MANIFEST_FILE:Q}
FILES_SUBST+=			SMF_METHOD_SHELL=${SMF_METHOD_SHELL:Q}

INSTALLATION_DIRS+=		${PKG_SMF_MANIFEST_DIR}
MULTIARCH_SKIP_DIRS.lib+=	${PKG_SMF_DIR}

.PHONY: generate-smf-manifest
generate-smf-manifest: ${SMF_MANIFEST_WRK}
${SMF_MANIFEST_WRK}: ${SMF_MANIFEST_SRC}
	@${STEP_MSG} "Creating ${.TARGET}"
	${RUN}${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} > ${.TARGET}

.PHONY: install-smf-manifest
post-install: install-smf-manifest
install-smf-manifest: ${SMF_MANIFEST_WRK}
	${INSTALL_DATA} ${SMF_MANIFEST_WRK} ${DESTDIR}${PREFIX}/${SMF_MANIFEST_FILE}

GENERATE_PLIST+=		${ECHO} "${SMF_MANIFEST_FILE}";
PRINT_PLIST_AWK+=		/^${SMF_MANIFEST_FILE:S|/|\\/|g}/ { next; }

# Target to add the INSTALL script to auto-import SMF manifest using svccfg
${WRKDIR}/.smfinstall: ${PKGSRCDIR}/mk/install/install-smf
	@${CP} ${PKGSRCDIR}/mk/install/install-smf ${WRKDIR}/.smfinstall

INSTALL_TEMPLATES+=		${WRKDIR}/.smfinstall

# Install optional SMF methods
#
.PHONY: generate-smf-methods
generate-smf-methods:	# do nothing

.PHONY: install-smf-methods
post-install: install-smf-methods
install-smf-methods:	# do nothing

.    for _method_ in ${SMF_METHODS}
SMF_METHOD_SRC.${_method_}?=	${SMF_SRCDIR}/${_method_}.sh
SMF_METHOD_WRK.${_method_}?=	${WRKDIR}/.smf_${_method_}
SMF_METHOD_FILE.${_method_}?=	${PKG_SMF_METHOD_DIR}/${_method_}

FILES_SUBST+=	SMF_METHOD_FILE.${_method_}=${SMF_METHOD_FILE.${_method_}}

.      if !empty(SMF_METHOD_SRC.${_method_})
generate-smf-methods: ${SMF_METHOD_WRK.${_method_}}
${SMF_METHOD_WRK.${_method_}}: ${SMF_METHOD_SRC.${_method_}}
	@${STEP_MSG} "Creating ${.TARGET}"
	${RUN}${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} > ${.TARGET}
	${RUN}${CHMOD} +x ${.TARGET}

install-smf-methods: install-smf-${_method_}
install-smf-${_method_}: ${SMF_METHOD_WRK.${_method_}}
	${RUN} \
	if [ -f ${SMF_METHOD_WRK.${_method_}} ]; then \
		${MKDIR} ${DESTDIR}${PREFIX}/${PKG_SMF_METHOD_DIR}; \
		${INSTALL_SCRIPT} ${SMF_METHOD_WRK.${_method_}} \
			${DESTDIR}${PREFIX}/${SMF_METHOD_FILE.${_method_}}; \
	fi
.      endif
GENERATE_PLIST+=	${ECHO} ${SMF_METHOD_FILE.${_method_}};
PRINT_PLIST_AWK+=	/^${SMF_METHOD_FILE.${_method_}:S|/|\\/|g}/ { next; }
.    endfor
.  endif
.endif

cvs diff -r1.237 -r1.238 pkgsrc/mk/defaults/mk.conf (expand / switch to unified diff)

--- pkgsrc/mk/defaults/mk.conf 2014/03/11 13:45:07 1.237
+++ pkgsrc/mk/defaults/mk.conf 2014/03/11 14:07:04 1.238
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mk.conf,v 1.237 2014/03/11 13:45:07 jperkin Exp $ 1# $NetBSD: mk.conf,v 1.238 2014/03/11 14:07:04 jperkin Exp $
2# 2#
3 3
4# This file provides default values for variables that may be overridden 4# This file provides default values for variables that may be overridden
5# in the MAKECONF file, which is /etc/mk.conf by default. 5# in the MAKECONF file, which is /etc/mk.conf by default.
6# 6#
7# Note: This file is included after the MAKECONF file, so you cannot query 7# Note: This file is included after the MAKECONF file, so you cannot query
8# these default values in the MAKECONF using the ".if" and ".for" 8# these default values in the MAKECONF using the ".if" and ".for"
9# preprocessing directives. 9# preprocessing directives.
10 10
11# ************************************************************************ 11# ************************************************************************
12# NOTE TO PEOPLE EDITING THIS FILE - USE LEADING SPACES, NOT LEADING TABS. 12# NOTE TO PEOPLE EDITING THIS FILE - USE LEADING SPACES, NOT LEADING TABS.
13# ************************************************************************ 13# ************************************************************************
14 14
@@ -387,27 +387,27 @@ PKG_RESUME_TRANSFERS?= NO @@ -387,27 +387,27 @@ PKG_RESUME_TRANSFERS?= NO
387# Used in pkgsrc to resume transfers, if enabled the whole file won't be 387# Used in pkgsrc to resume transfers, if enabled the whole file won't be
388# downloaded from scratch again. 388# downloaded from scratch again.
389# Possible: yes or no. 389# Possible: yes or no.
390# Default: no. 390# Default: no.
391 391
392PKG_SYSCONFBASE?= ${PREFIX}/etc 392PKG_SYSCONFBASE?= ${PREFIX}/etc
393# This is the main config directory under which all package configuration 393# This is the main config directory under which all package configuration
394# files should be found. 394# files should be found.
395# Possible: any path you like 395# Possible: any path you like
396# Default: ${PREFIX}/etc 396# Default: ${PREFIX}/etc
397 397
398#INIT_SYSTEM= 398#INIT_SYSTEM=
399# This determines the type of init system to be used. 399# This determines the type of init system to be used.
400# Possible: any of: rc.d 400# Possible: any of: rc.d, smf
401# Default: Platform-dependent, otherwise rc.d 401# Default: Platform-dependent, otherwise rc.d
402 402
403RCD_SCRIPTS_DIR?= /etc/rc.d 403RCD_SCRIPTS_DIR?= /etc/rc.d
404# This is the system rc.d script directory in which all rc.d scripts 404# This is the system rc.d script directory in which all rc.d scripts
405# expected to be executed at boot-time should be found. Package views 405# expected to be executed at boot-time should be found. Package views
406# users may want to set this to "${PKG_SYSCONFBASEDIR}/rc.d". 406# users may want to set this to "${PKG_SYSCONFBASEDIR}/rc.d".
407# Possible: any path you like 407# Possible: any path you like
408# Default: /etc/rc.d 408# Default: /etc/rc.d
409 409
410PACKAGES?= ${PKGSRCDIR}/packages 410PACKAGES?= ${PKGSRCDIR}/packages
411# Stores generated packages 411# Stores generated packages
412# Possible: any path you like 412# Possible: any path you like
413# Default: /usr/pkgsrc/packages 413# Default: /usr/pkgsrc/packages

File Added: pkgsrc/mk/install/install-smf
# $NetBSD: install-smf,v 1.1 2014/03/11 14:07:04 jperkin Exp $
#
# Print post-install messages instructing the user how to handle the
# newly-installed SMF services.
#

case ${STAGE} in
POST-INSTALL)
	cat <<EOF
============================================================================
This package has SMF support.  You may use svcadm(1M) to 'enable', 'disable'
or 'restart' services.  To enable the instance(s) for this package, run:

EOF
	for svc in @SMF_INSTANCES@; do
		cat <<EOF
	/usr/sbin/svcadm enable svc:/@SMF_PREFIX@/@SMF_NAME@:${svc}
EOF
	done
	cat <<EOF

Use svcs(1) to check on service status.  See smf(5) for more information.
EOF
	if [ -z "${PKG_SKIP_SMF}" ]; then
		/usr/sbin/svccfg import ${PKG_PREFIX}/@SMF_MANIFEST_FILE@
	else
		cat <<EOF

The PKG_SKIP_SMF variable was set, automatic import of SMF manifests was
skipped.  You must import the SMF manifest first with:

	/usr/sbin/svccfg import ${PKG_PREFIX}/@SMF_MANIFEST_FILE@

EOF
	fi
	cat <<EOF
============================================================================
EOF
	;;
esac

cvs diff -r1.57 -r1.58 pkgsrc/mk/platform/SunOS.mk (expand / switch to unified diff)

--- pkgsrc/mk/platform/SunOS.mk 2013/09/12 11:01:47 1.57
+++ pkgsrc/mk/platform/SunOS.mk 2014/03/11 14:07:04 1.58
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: SunOS.mk,v 1.57 2013/09/12 11:01:47 jperkin Exp $ 1# $NetBSD: SunOS.mk,v 1.58 2014/03/11 14:07:04 jperkin Exp $
2# 2#
3# Variable definitions for the SunOS/Solaris operating system. 3# Variable definitions for the SunOS/Solaris operating system.
4 4
5ECHO_N?= ${ECHO} -n 5ECHO_N?= ${ECHO} -n
6IMAKE_MAKE?= ${MAKE} # program which gets invoked by imake 6IMAKE_MAKE?= ${MAKE} # program which gets invoked by imake
7PKGLOCALEDIR?= lib 7PKGLOCALEDIR?= lib
8PS?= /bin/ps 8PS?= /bin/ps
9# XXX: default from defaults/mk.conf. Verify/correct for this platform 9# XXX: default from defaults/mk.conf. Verify/correct for this platform
10# and remove this comment. 10# and remove this comment.
11SU?= /usr/bin/su 11SU?= /usr/bin/su
12TYPE?= /usr/bin/type 12TYPE?= /usr/bin/type
13 13
14CATMAN_SECTION_SUFFIX?= yes 14CATMAN_SECTION_SUFFIX?= yes
@@ -28,26 +28,31 @@ ULIMIT_CMD_memorysize?= ulimit -v `${SET @@ -28,26 +28,31 @@ ULIMIT_CMD_memorysize?= ulimit -v `${SET
28USERADD?= /usr/sbin/useradd 28USERADD?= /usr/sbin/useradd
29 29
30.if exists(/usr/openwin/include/X11/X.h) 30.if exists(/usr/openwin/include/X11/X.h)
31X11_TYPE?= native 31X11_TYPE?= native
32.else 32.else
33X11_TYPE?= modular 33X11_TYPE?= modular
34.endif 34.endif
35.if ${X11_TYPE} == native 35.if ${X11_TYPE} == native
36MOTIF_TYPE_DEFAULT?= dt # default 2.0 compatible libs type 36MOTIF_TYPE_DEFAULT?= dt # default 2.0 compatible libs type
37.else 37.else
38MOTIF_TYPE_DEFAULT?= motif 38MOTIF_TYPE_DEFAULT?= motif
39.endif 39.endif
40 40
 41# Use SMF by default if available.
 42.if ${OS_VERSION} >= 5.10
 43INIT_SYSTEM?= smf
 44.endif
 45
41# Comes with a builtin implementation based on mit-krb5 46# Comes with a builtin implementation based on mit-krb5
42KRB5_DEFAULT?= mit-krb5 47KRB5_DEFAULT?= mit-krb5
43 48
44# Builtin defaults which make sense for this platform. 49# Builtin defaults which make sense for this platform.
45_OPSYS_PREFER.libexecinfo?= native 50_OPSYS_PREFER.libexecinfo?= native
46_OPSYS_PREFER.mit-krb5?= native 51_OPSYS_PREFER.mit-krb5?= native
47_OPSYS_PREFER.openssl?= pkgsrc 52_OPSYS_PREFER.openssl?= pkgsrc
48_OPSYS_PREFER.solaris-pam?= native 53_OPSYS_PREFER.solaris-pam?= native
49 54
50_OPSYS_EMULDIR.solaris= # empty 55_OPSYS_EMULDIR.solaris= # empty
51_OPSYS_EMULDIR.solaris32= # empty 56_OPSYS_EMULDIR.solaris32= # empty
52_OPSYS_EMULDIR.sunos= # empty 57_OPSYS_EMULDIR.sunos= # empty
53 58

File Added: pkgsrc/mk/plist/plist-smf.awk
# $NetBSD: plist-smf.awk,v 1.1 2014/03/11 14:07:04 jperkin Exp $
#
# Handle legacy entries, e.g. in pkgsrc-wip.
#

/^share\/examples\/rc\.d/ {
	next;
}