diff options
-rw-r--r-- | mk/bsd.pkg.mk | 5 | ||||
-rw-r--r-- | mk/defaults/mk.conf | 4 | ||||
-rw-r--r-- | mk/install/install-smf | 40 | ||||
-rw-r--r-- | mk/platform/SunOS.mk | 7 | ||||
-rw-r--r-- | mk/plist/plist-smf.awk | 8 | ||||
-rw-r--r-- | mk/smf.mk | 142 |
6 files changed, 202 insertions, 4 deletions
diff --git a/mk/bsd.pkg.mk b/mk/bsd.pkg.mk index 8cf0e2e42d9..92f78e7b68d 100644 --- a/mk/bsd.pkg.mk +++ b/mk/bsd.pkg.mk @@ -1,4 +1,4 @@ -# $NetBSD: bsd.pkg.mk,v 1.1996 2014/03/11 13:45:07 jperkin Exp $ +# $NetBSD: bsd.pkg.mk,v 1.1997 2014/03/11 14:07:04 jperkin Exp $ # # This file is in the public domain. # @@ -318,6 +318,9 @@ OVERRIDE_DIRDEPTH?= 2 # Support alternative init systems. # INIT_SYSTEM?= rc.d +.if ${INIT_SYSTEM} == "smf" +. include "smf.mk" +.endif _BUILD_DEFS+= INIT_SYSTEM # Define SMART_MESSAGES in /etc/mk.conf for messages giving the tree diff --git a/mk/defaults/mk.conf b/mk/defaults/mk.conf index 6b66d3acb13..7af219ccd50 100644 --- a/mk/defaults/mk.conf +++ b/mk/defaults/mk.conf @@ -1,4 +1,4 @@ -# $NetBSD: mk.conf,v 1.237 2014/03/11 13:45:07 jperkin Exp $ +# $NetBSD: mk.conf,v 1.238 2014/03/11 14:07:04 jperkin Exp $ # # This file provides default values for variables that may be overridden @@ -397,7 +397,7 @@ PKG_SYSCONFBASE?= ${PREFIX}/etc #INIT_SYSTEM= # This determines the type of init system to be used. -# Possible: any of: rc.d +# Possible: any of: rc.d, smf # Default: Platform-dependent, otherwise rc.d RCD_SCRIPTS_DIR?= /etc/rc.d diff --git a/mk/install/install-smf b/mk/install/install-smf new file mode 100644 index 00000000000..30aa994b2c2 --- /dev/null +++ b/mk/install/install-smf @@ -0,0 +1,40 @@ +# $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 diff --git a/mk/platform/SunOS.mk b/mk/platform/SunOS.mk index 7f2f67eda83..46d6a070143 100644 --- a/mk/platform/SunOS.mk +++ b/mk/platform/SunOS.mk @@ -1,4 +1,4 @@ -# $NetBSD: SunOS.mk,v 1.57 2013/09/12 11:01:47 jperkin Exp $ +# $NetBSD: SunOS.mk,v 1.58 2014/03/11 14:07:04 jperkin Exp $ # # Variable definitions for the SunOS/Solaris operating system. @@ -38,6 +38,11 @@ MOTIF_TYPE_DEFAULT?= dt # default 2.0 compatible libs type MOTIF_TYPE_DEFAULT?= motif .endif +# Use SMF by default if available. +.if ${OS_VERSION} >= 5.10 +INIT_SYSTEM?= smf +.endif + # Comes with a builtin implementation based on mit-krb5 KRB5_DEFAULT?= mit-krb5 diff --git a/mk/plist/plist-smf.awk b/mk/plist/plist-smf.awk new file mode 100644 index 00000000000..944b27ca320 --- /dev/null +++ b/mk/plist/plist-smf.awk @@ -0,0 +1,8 @@ +# $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; +} diff --git a/mk/smf.mk b/mk/smf.mk new file mode 100644 index 00000000000..d2f62bb23a7 --- /dev/null +++ b/mk/smf.mk @@ -0,0 +1,142 @@ +# $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 |