From 3a186698a620ccc7f63f8079b89830e0302fe4f8 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Tue, 16 Jun 2015 18:11:22 +0000 Subject: [PATCH] Add init-scripts directory support There is a common pattern of if init_system == foo then install init script foo-service-init into /etc/init... Lets encode this pattern by allowing elements to put files into init-scripts/init-system directories and then copying the appropriate files for them. Change-Id: I541db18a0a8c5e0755a0af5732f4e15a5e5cf984 --- elements/dib-init-system/README.rst | 15 ++++++++++- .../install.d/20-install-init-scripts | 26 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 elements/dib-init-system/install.d/20-install-init-scripts diff --git a/elements/dib-init-system/README.rst b/elements/dib-init-system/README.rst index b6005d395..b2c343830 100644 --- a/elements/dib-init-system/README.rst +++ b/elements/dib-init-system/README.rst @@ -2,4 +2,17 @@ dib-init-system =============== -A simple element that provides a script to tell what the init system is. +Installs a script (dib-init-system) which outputs the type of init system in +use on the target image. Also sets an environment variable ``DIB_INIT_SYSTEM`` +to this value. + +Any files placed in a ``init-scripts/INIT_SYSTEM`` directory inside the +element will be copied into the appropriate directory if ``INIT_SYSTEM`` +is in use on the host. + +Environment Variables +--------------------- + +DIB_INIT_SYSTEM + :Description: One of upstart, systemd, or sysv depending on the init system + in use for the target image. diff --git a/elements/dib-init-system/install.d/20-install-init-scripts b/elements/dib-init-system/install.d/20-install-init-scripts new file mode 100755 index 000000000..e55f29c78 --- /dev/null +++ b/elements/dib-init-system/install.d/20-install-init-scripts @@ -0,0 +1,26 @@ +#!/bin/bash +# Note that this relies on the detail that all elements share one dir inside +# the chroot. This will copy all the files that elements have added to +# element/static into the image. Mode, symlinks etc will be respected. + +if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +scripts_dir="$(dirname $0)../init-scripts/$DIB_INIT_SYSTEM/" +if [ -d "$scripts_dir" ]; then + dest= + case $DIB_INIT_SYSTEM in + upstart) dest=/etc/init/ ;; + systemd) dest=/usr/lib/systemd/system/ ;; + sysv) dest=/etc/init.d/ ;; + esac + + if [ -z "$dest" ]; then + echo "ERROR: DIB_INIT_SYSTEM ($DIB_INIT_SYSTEM) is not an unknown type" + exit 1 + fi + rsync -lCr "$scripts_dir" $dest +fi