From 14f3ee403aef85c8a31a1fef616aafba9f52cacf Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 23 Mar 2016 16:34:57 +0100 Subject: [PATCH 1/4] fix fo __start_on_boot for ALL systemd distros --- cdist/conf/explorer/init | 24 ++++ .../conf/type/__start_on_boot/explorer/state | 78 ++++++----- .../conf/type/__start_on_boot/gencode-remote | 131 ++++++++++-------- 3 files changed, 135 insertions(+), 98 deletions(-) create mode 100755 cdist/conf/explorer/init mode change 100755 => 100644 cdist/conf/type/__start_on_boot/explorer/state mode change 100755 => 100644 cdist/conf/type/__start_on_boot/gencode-remote diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init new file mode 100755 index 00000000..3777b431 --- /dev/null +++ b/cdist/conf/explorer/init @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 2016 Daniel Heule (hda at sfs.biz) +# +# 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 . +# +# +# Check whether the given name will be started on boot or not +# + +ps -o comm= --pid 1 diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state old mode 100755 new mode 100644 index 1906033c..1cad6602 --- a/cdist/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -24,47 +24,51 @@ os=$("$__explorer/os") runlevel=$("$__explorer/runlevel") +init=$("$__explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" name="$__object_id" -case "$os" in - archlinux) - state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ - && echo present \ - || echo absent) - ;; +if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo, new RHEL and SLES versions + state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ + && echo present \ + || echo absent) - debian|openwrt) - state="present" - [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" - ;; - ubuntu) - state="absent" - [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" - [ -f "/etc/init/${name}.conf" ] && state="present" - ;; +else + case "$os" in + debian|openwrt) + state="present" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" + ;; + ubuntu) + state="absent" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" + [ -f "/etc/init/${name}.conf" ] && state="present" + ;; - amazon|centos|fedora|owl|redhat) - state=$(chkconfig --level "$runlevel" "$name" || echo absent) - [ "$state" ] || state="present" - ;; - suse) - # check for target if set, usable for boot. services in runlevel B - if [ "$target_runlevel" != 'default' ]; then - runlevel="$target_runlevel" - fi - # suses chkconfig has the same name, but works different ... - state=$(chkconfig --check "$name" "$runlevel" || echo absent) - [ "$state" ] || state="present" - ;; - gentoo) - state="present" - [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" - ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; -esac + amazon|centos|fedora|owl|redhat) + state=$(chkconfig --level "$runlevel" "$name" || echo absent) + [ "$state" ] || state="present" + ;; + suse) + # check for target if set, usable for boot. services in runlevel B + if [ "$target_runlevel" != 'default' ]; then + runlevel="$target_runlevel" + fi + # suses chkconfig has the same name, but works different ... + state=$(chkconfig --check "$name" "$runlevel" || echo absent) + [ "$state" ] || state="present" + ;; + gentoo) + state="present" + [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" + ;; + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac +fi echo $state diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote old mode 100755 new mode 100644 index 611e59fe..c8488e3a --- a/cdist/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh # # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2013 Daniel Heule (hda at sfs.biz) +# 2016 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -22,6 +22,7 @@ state_should="$(cat "$__object/parameter/state")" state_is=$(cat "$__object/explorer/state") +init=$(cat "$__global/explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" # Short circuit if nothing is to be done @@ -33,78 +34,86 @@ name="$__object_id" case "$state_should" in present) - case "$os" in - archlinux) - echo "systemctl enable \"$name\"" - ;; - debian) - case "$os_version" in - [1-7]*) - echo "update-rc.d \"$name\" defaults >/dev/null" - ;; - 8*) - echo "systemctl enable \"$name\"" - ;; - *) - echo "Unsupported version $os_version of $os" >&2 - exit 1 - ;; - esac - ;; + if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q enable \"$name\"" + else + case "$os" in + debian) + case "$os_version" in + [1-7]*) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; + 8*) + echo "systemctl enable \"$name\"" + ;; + *) + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; + esac + ;; - gentoo) - echo rc-update add \"$name\" \"$target_runlevel\" - ;; + gentoo) + echo rc-update add \"$name\" \"$target_runlevel\" + ;; - amazon|centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" on - ;; + amazon|centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" on + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; - openwrt) - # 'enable' can be successful and still return a non-zero exit - # code, deal with it by checking for success ourselves in that - # case (the || ... part). - echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" - ;; + openwrt) + # 'enable' can be successful and still return a non-zero exit + # code, deal with it by checking for success ourselves in that + # case (the || ... part). + echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" + ;; - ubuntu) - echo "update-rc.d \"$name\" defaults >/dev/null" - ;; + ubuntu) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; absent) - case "$os" in - archlinux) - echo "systemctl disable \"$name\"" - ;; - debian|ubuntu) - echo update-rc.d -f \"$name\" remove - ;; + if [ "$init" == 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q disable \"$name\"" - gentoo) - echo rc-update del \"$name\" \"$target_runlevel\" - ;; + else + case "$os" in + debian|ubuntu) + echo update-rc.d -f \"$name\" remove + ;; - centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" off - ;; + gentoo) + echo rc-update del \"$name\" \"$target_runlevel\" + ;; - openwrt) - echo "\"/etc/init.d/$name\" disable" - ;; + centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" off + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac - + openwrt) + echo "\"/etc/init.d/$name\" disable" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; *) From 2c49e04c9847fe55ec4b64fe815ce0fe36e79766 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 24 Mar 2016 11:22:09 +0100 Subject: [PATCH 2/4] Updated the exlorer for more systems changed the ps syntax, so it should work on freebsd to added a case so it could easy implemented for other os to --- cdist/conf/explorer/init | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index 3777b431..a9cdd0d3 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -18,7 +18,19 @@ # along with cdist. If not, see . # # -# Check whether the given name will be started on boot or not +# Returns the process name of pid 1 ( normaly the init system ) +# for example at linux this value is "init" or "systemd" in most cases # -ps -o comm= --pid 1 +uname_s="$(uname -s)" + +case "$uname_s" in + Linux|FreeBSD) + ps -o comm= -p 1 || true + exit 0 + ;; + *) + echo "init exlorer needs to be implemented for $os" >&2 + exit 1 + ;; +esac From 9c6d7dbd892c30c11ed8c03f74a24d688d47cad4 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 24 Mar 2016 11:29:13 +0100 Subject: [PATCH 3/4] modified the unknown case ... --- cdist/conf/explorer/init | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index a9cdd0d3..fd54d0c0 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -27,10 +27,8 @@ uname_s="$(uname -s)" case "$uname_s" in Linux|FreeBSD) ps -o comm= -p 1 || true - exit 0 ;; *) - echo "init exlorer needs to be implemented for $os" >&2 - exit 1 + echo "unknown" ;; esac From f7de217129de14e3857fd19eaa1cc1402312966a Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 25 Mar 2016 16:39:48 +0100 Subject: [PATCH 4/4] modified the unknown case to empty... --- cdist/conf/explorer/init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init index fd54d0c0..2693a0d3 100755 --- a/cdist/conf/explorer/init +++ b/cdist/conf/explorer/init @@ -29,6 +29,7 @@ case "$uname_s" in ps -o comm= -p 1 || true ;; *) - echo "unknown" + # return a empty string as unknown value + echo "" ;; esac