fix fo __start_on_boot for ALL systemd distros

This commit is contained in:
Daniel Heule 2016-03-23 16:34:57 +01:00
parent 32557cfa2c
commit 14f3ee403a
3 changed files with 135 additions and 98 deletions

24
cdist/conf/explorer/init Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# Check whether the given name will be started on boot or not
#
ps -o comm= --pid 1

78
cdist/conf/type/__start_on_boot/explorer/state Executable file → Normal file
View file

@ -24,47 +24,51 @@
os=$("$__explorer/os") os=$("$__explorer/os")
runlevel=$("$__explorer/runlevel") runlevel=$("$__explorer/runlevel")
init=$("$__explorer/init")
target_runlevel="$(cat "$__object/parameter/target_runlevel")" target_runlevel="$(cat "$__object/parameter/target_runlevel")"
name="$__object_id" name="$__object_id"
case "$os" in if [ "$init" == 'systemd' ]; then
archlinux) # this handles ALL linux distros with systemd
state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ # e.g. archlinux, gentoo, new RHEL and SLES versions
&& echo present \ state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \
|| echo absent) && echo present \
;; || echo absent)
debian|openwrt) else
state="present" case "$os" in
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" debian|openwrt)
;; state="present"
ubuntu) [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
state="absent" ;;
[ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" ubuntu)
[ -f "/etc/init/${name}.conf" ] && state="present" state="absent"
;; [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present"
[ -f "/etc/init/${name}.conf" ] && state="present"
;;
amazon|centos|fedora|owl|redhat) amazon|centos|fedora|owl|redhat)
state=$(chkconfig --level "$runlevel" "$name" || echo absent) state=$(chkconfig --level "$runlevel" "$name" || echo absent)
[ "$state" ] || state="present" [ "$state" ] || state="present"
;; ;;
suse) suse)
# check for target if set, usable for boot. services in runlevel B # check for target if set, usable for boot. services in runlevel B
if [ "$target_runlevel" != 'default' ]; then if [ "$target_runlevel" != 'default' ]; then
runlevel="$target_runlevel" runlevel="$target_runlevel"
fi fi
# suses chkconfig has the same name, but works different ... # suses chkconfig has the same name, but works different ...
state=$(chkconfig --check "$name" "$runlevel" || echo absent) state=$(chkconfig --check "$name" "$runlevel" || echo absent)
[ "$state" ] || state="present" [ "$state" ] || state="present"
;; ;;
gentoo) gentoo)
state="present" state="present"
[ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent"
;; ;;
*) *)
echo "Unsupported os: $os" >&2 echo "Unsupported os: $os" >&2
exit 1 exit 1
;; ;;
esac esac
fi
echo $state echo $state

129
cdist/conf/type/__start_on_boot/gencode-remote Executable file → Normal file
View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) # 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. # This file is part of cdist.
# #
@ -22,6 +22,7 @@
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state")"
state_is=$(cat "$__object/explorer/state") state_is=$(cat "$__object/explorer/state")
init=$(cat "$__global/explorer/init")
target_runlevel="$(cat "$__object/parameter/target_runlevel")" target_runlevel="$(cat "$__object/parameter/target_runlevel")"
# Short circuit if nothing is to be done # Short circuit if nothing is to be done
@ -33,78 +34,86 @@ name="$__object_id"
case "$state_should" in case "$state_should" in
present) present)
case "$os" in if [ "$init" == 'systemd' ]; then
archlinux) # this handles ALL linux distros with systemd
echo "systemctl enable \"$name\"" # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions
;; echo "systemctl -q enable \"$name\""
debian) else
case "$os_version" in case "$os" in
[1-7]*) debian)
echo "update-rc.d \"$name\" defaults >/dev/null" case "$os_version" in
;; [1-7]*)
8*) echo "update-rc.d \"$name\" defaults >/dev/null"
echo "systemctl enable \"$name\"" ;;
;; 8*)
*) echo "systemctl enable \"$name\""
echo "Unsupported version $os_version of $os" >&2 ;;
exit 1 *)
;; echo "Unsupported version $os_version of $os" >&2
esac exit 1
;; ;;
esac
;;
gentoo) gentoo)
echo rc-update add \"$name\" \"$target_runlevel\" echo rc-update add \"$name\" \"$target_runlevel\"
;; ;;
amazon|centos|fedora|owl|redhat|suse) amazon|centos|fedora|owl|redhat|suse)
echo chkconfig \"$name\" on echo chkconfig \"$name\" on
;; echo "Unsupported version $os_version of $os" >&2
exit 1
;;
openwrt) openwrt)
# 'enable' can be successful and still return a non-zero exit # 'enable' can be successful and still return a non-zero exit
# code, deal with it by checking for success ourselves in that # code, deal with it by checking for success ourselves in that
# case (the || ... part). # case (the || ... part).
echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]"
;; ;;
ubuntu) ubuntu)
echo "update-rc.d \"$name\" defaults >/dev/null" echo "update-rc.d \"$name\" defaults >/dev/null"
;; ;;
*) *)
echo "Unsupported os: $os" >&2 echo "Unsupported os: $os" >&2
exit 1 exit 1
;; ;;
esac esac
fi
;; ;;
absent) absent)
case "$os" in if [ "$init" == 'systemd' ]; then
archlinux) # this handles ALL linux distros with systemd
echo "systemctl disable \"$name\"" # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions
;; echo "systemctl -q disable \"$name\""
debian|ubuntu)
echo update-rc.d -f \"$name\" remove
;;
gentoo) else
echo rc-update del \"$name\" \"$target_runlevel\" case "$os" in
;; debian|ubuntu)
echo update-rc.d -f \"$name\" remove
;;
centos|fedora|owl|redhat|suse) gentoo)
echo chkconfig \"$name\" off echo rc-update del \"$name\" \"$target_runlevel\"
;; ;;
openwrt) centos|fedora|owl|redhat|suse)
echo "\"/etc/init.d/$name\" disable" echo chkconfig \"$name\" off
;; ;;
*) openwrt)
echo "Unsupported os: $os" >&2 echo "\"/etc/init.d/$name\" disable"
exit 1 ;;
;;
esac
*)
echo "Unsupported os: $os" >&2
exit 1
;;
esac
fi
;; ;;
*) *)