pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk/init Add "init" framework for management of init sc...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/f2316ef0c16e
branches:  trunk
changeset: 363092:f2316ef0c16e
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Thu Jun 01 02:08:04 2017 +0000

description:
Add "init" framework for management of init scripts for packages.

${INIT_SYSTEM} is used to select the type of init system in use on
the system, and currently can be either "rc.d" for the NetBSD rc.d
system, or "smf" for the Solaris Service Management Facility
system.

pkgsrc/mk/init/smf.mk is pkgsrc/mk/smf.mk with some very minor
modifications to fit into the "init" framework.

diffstat:

 mk/init/bsd.init-vars.mk                 |   44 +++++++++
 mk/init/bsd.init.mk                      |   34 +++++++
 mk/init/rc.d.mk                          |  139 +++++++++++++++++++++++++++++
 mk/init/smf.mk                           |  145 +++++++++++++++++++++++++++++++
 mk/init/tests/Kyuafile                   |   38 ++++++++
 mk/init/tests/rc.d/Kyuafile              |   46 +++++++++
 mk/init/tests/rc.d/generate_test         |   76 ++++++++++++++++
 mk/init/tests/rc.d/init_scripts_test     |   75 ++++++++++++++++
 mk/init/tests/rc.d/install_test          |   61 +++++++++++++
 mk/init/tests/rc.d/make_dirs_test        |   67 ++++++++++++++
 mk/init/tests/rc.d/test.mk               |   61 +++++++++++++
 mk/init/tests/rc.d/test_common.sh        |   68 ++++++++++++++
 mk/init/tests/smf/Kyuafile               |   46 +++++++++
 mk/init/tests/smf/manifest_generate_test |   76 ++++++++++++++++
 mk/init/tests/smf/manifest_install_test  |   61 +++++++++++++
 mk/init/tests/smf/methods_generate_test  |   76 ++++++++++++++++
 mk/init/tests/smf/methods_install_test   |   61 +++++++++++++
 mk/init/tests/smf/test.mk                |   66 ++++++++++++++
 mk/init/tests/smf/test_common.sh         |  105 ++++++++++++++++++++++
 19 files changed, 1345 insertions(+), 0 deletions(-)

diffs (truncated from 1421 to 300 lines):

diff -r 8441f8d7e5ec -r f2316ef0c16e mk/init/bsd.init-vars.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/init/bsd.init-vars.mk  Thu Jun 01 02:08:04 2017 +0000
@@ -0,0 +1,44 @@
+# $NetBSD: bsd.init-vars.mk,v 1.1 2017/06/01 02:08:04 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+# This Makefile fragment is included by bsd.prefs.mk and defines some
+# variables which must be defined earlier than where bsd.init.mk is
+# included.
+
+# System-settable variables:
+#
+# INIT_SYSTEM
+#      Type of system used to spawn processes as the last stage of
+#      the boot process.
+#
+#      Possible: rc.d, smf
+#      Default: rc.d
+#
+_SYS_VARS.init+=       INIT_SYSTEM
+_BUILD_DEFS+=          INIT_SYSTEM
+INIT_SYSTEM?=          rc.d
diff -r 8441f8d7e5ec -r f2316ef0c16e mk/init/bsd.init.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/init/bsd.init.mk       Thu Jun 01 02:08:04 2017 +0000
@@ -0,0 +1,34 @@
+# $NetBSD: bsd.init.mk,v 1.1 2017/06/01 02:08:04 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# This Makefile fragment is included by bsd.pkg.mk and pulls in the
+# correct target and variable overrides for the selected init script
+# system.
+
+.sinclude "${INIT_SYSTEM}.mk"
diff -r 8441f8d7e5ec -r f2316ef0c16e mk/init/rc.d.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/init/rc.d.mk   Thu Jun 01 02:08:04 2017 +0000
@@ -0,0 +1,139 @@
+# $NetBSD: rc.d.mk,v 1.1 2017/06/01 02:08:04 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Infrastructure support for the rc.d script system (pkgtools/rc.subr).
+#
+# Package-settable variables:
+#
+# RCD_SCRIPTS
+#      List of the basenames of the rc.d scripts.  The example rc.d
+#      script must be found in ${PREFIX}/share/examples/rc.d, and
+#      the script will be copied into ${RCD_SCRIPTS_DIR} with
+#      ${RCD_SCRIPTS_MODE} permissions.
+#
+# RCD_SCRIPTS_DIR
+#      The location of the copied rc.d scripts.
+#
+#      Possible: any path
+#      Default: /etc/rc.d
+#
+# RCD_SCRIPTS_EXAMPLEDIR
+#      The location of the example rc.d scripts.  This location must
+#      be a relative path to ${PREFIX}.
+#
+#      Possible: any path
+#      Default: share/examples/rc.d
+#
+# RCD_SCRIPTS_MODE
+#      The file mode of the copied rc.d scripts.
+#
+#      Possible: any file mode
+#      Default: 0755
+#
+# RCD_SCRIPTS_SHELL
+#      The shell used to run the rc.d scripts.
+#
+#      Possible: any shell path
+#      Default: ${SH}
+#
+# RCD_SCRIPT_SRC.<script>
+#      The source file for the rc.d script with basename <script>
+#      before installation; the source file is put through variable
+#      substitution to generate the target rc.d script.  If the
+#      source file is not present, then no rc.d script is generated.
+#
+#      Possible: any path
+#      Default: ${FILESDIR}/<script>.sh
+#
+_PKG_VARS.init+=       RCD_SCRIPTS RCD_SCRIPTS_MODE RCD_SCRIPTS_SHELL
+_PKG_VARS.init+=       RCD_SCRIPTS_DIR RCD_SCRIPTS_EXAMPLEDIRI
+_PKG_VARS.init+=       ${RCD_SCRIPTS:@s@RCD_SCRIPT_SRC.${s}@}
+
+RCD_SCRIPTS_DIR?=              /etc/rc.d
+RCD_SCRIPTS_EXAMPLEDIR?=       share/examples/rc.d
+RCD_SCRIPTS_MODE?=             0755
+RCD_SCRIPTS_SHELL?=            ${SH}
+
+FILES_SUBST+=          RCD_SCRIPTS_SHELL=${RCD_SCRIPTS_SHELL:Q}
+MESSAGE_SUBST+=                RCD_SCRIPTS_DIR=${RCD_SCRIPTS_DIR:Q}
+MESSAGE_SUBST+=                RCD_SCRIPTS_EXAMPLEDIR=${RCD_SCRIPTS_EXAMPLEDIR:Q}
+
+.PHONY: generate-rcd-scripts
+generate-rcd-scripts:  # do nothing
+
+# Hook into installation process via "post-install" target.
+.PHONY: install-rcd-scripts
+post-install: install-rcd-scripts
+install-rcd-scripts:   # do nothing
+
+# Add to MAKE_DIRS to ensure ${RCD_SCRIPTS_DIR} is created automatically.
+_MAKE_RCD_SCRIPTS_DIR= # empty
+
+.for _script_ in ${RCD_SCRIPTS}
+RCD_SCRIPT_SRC.${_script_}?=   ${FILESDIR}/${_script_}.sh
+_RCD_SCRIPT_WRK.${_script_}?=  ${WRKDIR}/.rc.d/${_script_}
+_RCD_SCRIPT_FILE.${_script_}?= ${RCD_SCRIPTS_EXAMPLEDIR}/${_script_}
+
+.  if !empty(RCD_SCRIPT_SRC.${_script_})
+generate-rcd-scripts: ${_RCD_SCRIPT_WRK.${_script_}}
+${_RCD_SCRIPT_WRK.${_script_}}: ${RCD_SCRIPT_SRC.${_script_}}
+       @${STEP_MSG} "Creating "${.TARGET:Q}
+       ${RUN}${MKDIR} ${.TARGET:H:Q}
+       ${RUN}${CAT} ${.ALLSRC:Q} | ${SED} ${FILES_SUBST_SED} > ${.TARGET:Q}
+       ${RUN}${CHMOD} +x ${.TARGET:Q}
+
+.PHONY: install-rcd-${_script_}
+install-rcd-scripts: install-rcd-${_script_}
+install-rcd-${_script_}: ${_RCD_SCRIPT_WRK.${_script_}}
+       ${RUN}${MKDIR} ${DESTDIR:Q}${PREFIX:Q}/${_RCD_SCRIPT_FILE.${_script_}:H:Q}
+       ${RUN}${INSTALL_SCRIPT} ${_RCD_SCRIPT_WRK.${_script_}} \
+               ${DESTDIR:Q}${PREFIX:Q}/${_RCD_SCRIPT_FILE.${_script_}:Q}
+.  endif
+
+# Hook into plist module to automatically add rc.d scripts into the
+# packing list.
+#
+GENERATE_PLIST+=       ${ECHO} ${_RCD_SCRIPT_FILE.${_script_}:Q};
+PRINT_PLIST_AWK+=      /^${_RCD_SCRIPT_FILE.${_script_}:S|/|\\/|g}/ { next; }
+
+# Hook into the pkgtasks module to copy rc.d scripts into place in
+# the package tasks.
+#
+_INIT_SCRIPTS+=                ${_RCD_SCRIPT_FILE.${_script_}} \
+                       ${RCD_SCRIPTS_DIR}/${_script_}
+_INIT_SCRIPTS_MODE=    ${RCD_SCRIPTS_MODE}
+
+# Only set this value if ${RCD_SCRIPTS} was non-empty.
+_MAKE_RCD_SCRIPTS_DIR= ${RCD_SCRIPTS_DIR}
+.endfor
+
+# Hook into the pkgtasks module to create ${RCD_SCRIPTS_DIR} in the
+# package tasks if there are rc.d scripts to copy into place.
+#
+MAKE_DIRS+=    ${_MAKE_RCD_SCRIPTS_DIR}
diff -r 8441f8d7e5ec -r f2316ef0c16e mk/init/smf.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/init/smf.mk    Thu Jun 01 02:08:04 2017 +0000
@@ -0,0 +1,145 @@
+# $NetBSD: smf.mk,v 1.1 2017/06/01 02:08:04 jlam 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



Home | Main Index | Thread Index | Old Index