pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk Introduce infrastructure support for SMF.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/79603fc7a5fc
branches:  trunk
changeset: 631630:79603fc7a5fc
user:      jperkin <jperkin%pkgsrc.org@localhost>
date:      Tue Mar 11 14:07:04 2014 +0000

description:
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.

diffstat:

 mk/bsd.pkg.mk          |    5 +-
 mk/defaults/mk.conf    |    4 +-
 mk/install/install-smf |   40 +++++++++++++
 mk/platform/SunOS.mk   |    7 ++-
 mk/plist/plist-smf.awk |    8 ++
 mk/smf.mk              |  142 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 202 insertions(+), 4 deletions(-)

diffs (260 lines):

diff -r 6b8214e20aaa -r 79603fc7a5fc mk/bsd.pkg.mk
--- a/mk/bsd.pkg.mk     Tue Mar 11 14:04:57 2014 +0000
+++ b/mk/bsd.pkg.mk     Tue Mar 11 14:07:04 2014 +0000
@@ -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 @@
 # 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 -r 6b8214e20aaa -r 79603fc7a5fc mk/defaults/mk.conf
--- a/mk/defaults/mk.conf       Tue Mar 11 14:04:57 2014 +0000
+++ b/mk/defaults/mk.conf       Tue Mar 11 14:07:04 2014 +0000
@@ -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 @@
 
 #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 -r 6b8214e20aaa -r 79603fc7a5fc mk/install/install-smf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/install/install-smf    Tue Mar 11 14:07:04 2014 +0000
@@ -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 -r 6b8214e20aaa -r 79603fc7a5fc mk/platform/SunOS.mk
--- a/mk/platform/SunOS.mk      Tue Mar 11 14:04:57 2014 +0000
+++ b/mk/platform/SunOS.mk      Tue Mar 11 14:07:04 2014 +0000
@@ -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?=   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 -r 6b8214e20aaa -r 79603fc7a5fc mk/plist/plist-smf.awk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/plist/plist-smf.awk    Tue Mar 11 14:07:04 2014 +0000
@@ -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 -r 6b8214e20aaa -r 79603fc7a5fc mk/smf.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/smf.mk Tue Mar 11 14:07:04 2014 +0000
@@ -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



Home | Main Index | Thread Index | Old Index