From 5d256b21b1e844026426f4ab22207952ecf35b7f Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Sun, 2 Oct 2011 22:33:56 +0200 Subject: [PATCH 1/6] Initial init_script type --- conf/type/__init_script/gencode-remote | 30 ++++++++++++++++++++++ conf/type/__init_script/parameter/optional | 1 + conf/type/__init_script/parameter/required | 1 + 3 files changed, 32 insertions(+) create mode 100644 conf/type/__init_script/gencode-remote create mode 100644 conf/type/__init_script/parameter/optional create mode 100644 conf/type/__init_script/parameter/required diff --git a/conf/type/__init_script/gencode-remote b/conf/type/__init_script/gencode-remote new file mode 100644 index 00000000..d9e56970 --- /dev/null +++ b/conf/type/__init_script/gencode-remote @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2010-2011 Daniel Roth (dani-cdist@d-roth.li) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +if [ -f "$__object/parameter/service" ]; then + service=$(cat "$__object/parameter/service") +else + service="/$__object_id" +fi + +mode=$(cat "$__object/parameter/mode") + +echo "/etc/init.d/${service} ${mode}" diff --git a/conf/type/__init_script/parameter/optional b/conf/type/__init_script/parameter/optional new file mode 100644 index 00000000..24e10984 --- /dev/null +++ b/conf/type/__init_script/parameter/optional @@ -0,0 +1 @@ +service diff --git a/conf/type/__init_script/parameter/required b/conf/type/__init_script/parameter/required new file mode 100644 index 00000000..17ab372f --- /dev/null +++ b/conf/type/__init_script/parameter/required @@ -0,0 +1 @@ +mode From 5f1afb08f6387111a754fef0bbdc1e7abe093257 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 3 Oct 2011 17:33:19 +0200 Subject: [PATCH 2/6] man page --- conf/type/__init_script/man.text | 49 ++++++++++++++++++++++ conf/type/__init_script/parameter/optional | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 conf/type/__init_script/man.text diff --git a/conf/type/__init_script/man.text b/conf/type/__init_script/man.text new file mode 100644 index 00000000..34065260 --- /dev/null +++ b/conf/type/__init_script/man.text @@ -0,0 +1,49 @@ +cdist-type__init_script(7) +============================== +Daniel Roth + + +NAME +---- +cdist-type__init_script - Use the init scripts + + +DESCRIPTION +----------- +This type can be used to control your init scripts. + + +REQUIRED PARAMETERS +------------------- +mode:: + Specifies what shall be done with the init script (usually one of 'start'|'stop'|'restart'|'reload' or 'force-reload') + + +OPTIONAL PARAMETERS +------------------- +script:: + If supplied, use this as the init-script. + Otherwise the object_id is used. The script will be pretended with '/etc/init.d/' + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Reloads the configuration for lighttpd +__init_script lighttpd --mode force-reload + +# Reloads the configuration for lighttpd +__init_script lighty --script lighttpd --mode force-reload +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 Daniel Roth. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__init_script/parameter/optional b/conf/type/__init_script/parameter/optional index 24e10984..84f7e31d 100644 --- a/conf/type/__init_script/parameter/optional +++ b/conf/type/__init_script/parameter/optional @@ -1 +1 @@ -service +script From 342cbca533a5da451555769d55cd83b7cb0959c1 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 3 Oct 2011 18:00:07 +0200 Subject: [PATCH 3/6] additional parameter base_dir --- conf/type/__init_script/gencode-remote | 16 ++++++++++++---- conf/type/__init_script/man.text | 4 +++- conf/type/__init_script/parameter/optional | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/conf/type/__init_script/gencode-remote b/conf/type/__init_script/gencode-remote index d9e56970..9b493cfc 100644 --- a/conf/type/__init_script/gencode-remote +++ b/conf/type/__init_script/gencode-remote @@ -19,12 +19,20 @@ # # -if [ -f "$__object/parameter/service" ]; then - service=$(cat "$__object/parameter/service") +if [ -f "$__object/parameter/script" ]; then + script=$(cat "$__object/parameter/script") else - service="/$__object_id" + script="/$__object_id" fi +if [ -f "$__object/parameter/base_dir" ]; then + base_dir=$(cat "$__object/parameter/base_dir") +else + base_dir="/etc/init.d" +fi + + + mode=$(cat "$__object/parameter/mode") -echo "/etc/init.d/${service} ${mode}" +echo "${base_dir}/${script} ${mode}" diff --git a/conf/type/__init_script/man.text b/conf/type/__init_script/man.text index 34065260..898943a5 100644 --- a/conf/type/__init_script/man.text +++ b/conf/type/__init_script/man.text @@ -23,8 +23,10 @@ OPTIONAL PARAMETERS ------------------- script:: If supplied, use this as the init-script. - Otherwise the object_id is used. The script will be pretended with '/etc/init.d/' + Otherwise the object_id is used. +base_dir:: + If supplied, this type uses this directory instead of '/etc/init.d'. The parameter will not need an ending slash. EXAMPLES -------- diff --git a/conf/type/__init_script/parameter/optional b/conf/type/__init_script/parameter/optional index 84f7e31d..5551a8f2 100644 --- a/conf/type/__init_script/parameter/optional +++ b/conf/type/__init_script/parameter/optional @@ -1 +1,2 @@ script +base_dir From 2147480fcd418c21b3a539e622d9ad46641f6a6f Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 3 Oct 2011 18:35:45 +0200 Subject: [PATCH 4/6] base_dir is /etc/rc.d for archlinux /etc/init.d otherwise --- conf/type/__init_script/gencode-remote | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/conf/type/__init_script/gencode-remote b/conf/type/__init_script/gencode-remote index 9b493cfc..ff823cad 100644 --- a/conf/type/__init_script/gencode-remote +++ b/conf/type/__init_script/gencode-remote @@ -28,11 +28,13 @@ fi if [ -f "$__object/parameter/base_dir" ]; then base_dir=$(cat "$__object/parameter/base_dir") else - base_dir="/etc/init.d" + os="$(cat "$__global/explorer/os")" + case "$os" in + archlinux) base_dir="/etc/rc.d" ;; + *) base_dir="/etc/init.d" + esac fi - - mode=$(cat "$__object/parameter/mode") echo "${base_dir}/${script} ${mode}" From 40d5b9cb05f93a8fc770fd595aadc8d9cd0ce40c Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 3 Oct 2011 21:39:07 +0200 Subject: [PATCH 5/6] bsd init location --- conf/type/__init_script/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__init_script/gencode-remote b/conf/type/__init_script/gencode-remote index ff823cad..d212feb7 100644 --- a/conf/type/__init_script/gencode-remote +++ b/conf/type/__init_script/gencode-remote @@ -30,7 +30,7 @@ if [ -f "$__object/parameter/base_dir" ]; then else os="$(cat "$__global/explorer/os")" case "$os" in - archlinux) base_dir="/etc/rc.d" ;; + archlinux|netbsd|macosx|freebsd|openbsd) base_dir="/etc/rc.d" ;; *) base_dir="/etc/init.d" esac fi From 9dfd6a27ad2b0e771e03d633a20248b2c7a0e102 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 5 Oct 2011 09:15:20 +0200 Subject: [PATCH 6/6] fixed broken man page --- conf/type/__init_script/man.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__init_script/man.text b/conf/type/__init_script/man.text index 898943a5..c33ff7b7 100644 --- a/conf/type/__init_script/man.text +++ b/conf/type/__init_script/man.text @@ -1,5 +1,5 @@ cdist-type__init_script(7) -============================== +========================== Daniel Roth