Merge pull request #421 from dheule/bugfix_for_systemd
fix for __start_on_boot for ALL systemd distros
This commit is contained in:
		
				commit
				
					
						83d8851ba6
					
				
			
		
					 3 changed files with 146 additions and 98 deletions
				
			
		
							
								
								
									
										35
									
								
								cdist/conf/explorer/init
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								cdist/conf/explorer/init
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
#!/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/>.
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
# Returns the process name of pid 1 ( normaly the init system )
 | 
			
		||||
# for example at linux this value is "init" or "systemd" in most cases
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
uname_s="$(uname -s)"
 | 
			
		||||
 | 
			
		||||
case "$uname_s" in
 | 
			
		||||
    Linux|FreeBSD)
 | 
			
		||||
        ps -o comm= -p 1 || true
 | 
			
		||||
    ;;
 | 
			
		||||
    *)
 | 
			
		||||
        # return a empty string as unknown value
 | 
			
		||||
        echo ""
 | 
			
		||||
    ;;
 | 
			
		||||
esac
 | 
			
		||||
							
								
								
									
										10
									
								
								cdist/conf/type/__start_on_boot/explorer/state
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										10
									
								
								cdist/conf/type/__start_on_boot/explorer/state
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							| 
						 | 
				
			
			@ -24,16 +24,19 @@
 | 
			
		|||
 | 
			
		||||
os=$("$__explorer/os")
 | 
			
		||||
runlevel=$("$__explorer/runlevel")
 | 
			
		||||
init=$("$__explorer/init")
 | 
			
		||||
target_runlevel="$(cat "$__object/parameter/target_runlevel")"
 | 
			
		||||
name="$__object_id"
 | 
			
		||||
 | 
			
		||||
case "$os" in
 | 
			
		||||
    archlinux)
 | 
			
		||||
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)
 | 
			
		||||
    ;;
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
    case "$os" in
 | 
			
		||||
        debian|openwrt)
 | 
			
		||||
            state="present"
 | 
			
		||||
            [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
 | 
			
		||||
| 
						 | 
				
			
			@ -66,5 +69,6 @@ case "$os" in
 | 
			
		|||
           exit 1
 | 
			
		||||
        ;;
 | 
			
		||||
    esac
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo $state
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										25
									
								
								cdist/conf/type/__start_on_boot/gencode-remote
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										25
									
								
								cdist/conf/type/__start_on_boot/gencode-remote
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							| 
						 | 
				
			
			@ -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,10 +34,12 @@ name="$__object_id"
 | 
			
		|||
 | 
			
		||||
case "$state_should" in
 | 
			
		||||
    present)
 | 
			
		||||
        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
 | 
			
		||||
            archlinux)
 | 
			
		||||
                echo "systemctl enable \"$name\""
 | 
			
		||||
            ;;
 | 
			
		||||
                debian)
 | 
			
		||||
                    case "$os_version" in
 | 
			
		||||
                        [1-7]*)
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +61,8 @@ case "$state_should" in
 | 
			
		|||
 | 
			
		||||
                amazon|centos|fedora|owl|redhat|suse)
 | 
			
		||||
                    echo chkconfig \"$name\" on
 | 
			
		||||
                            echo "Unsupported version $os_version of $os" >&2
 | 
			
		||||
                            exit 1
 | 
			
		||||
                ;;
 | 
			
		||||
 | 
			
		||||
                openwrt)
 | 
			
		||||
| 
						 | 
				
			
			@ -76,13 +81,17 @@ case "$state_should" in
 | 
			
		|||
                   exit 1
 | 
			
		||||
                ;;
 | 
			
		||||
            esac
 | 
			
		||||
        fi
 | 
			
		||||
    ;;
 | 
			
		||||
 | 
			
		||||
    absent)
 | 
			
		||||
        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\""
 | 
			
		||||
 | 
			
		||||
        else
 | 
			
		||||
            case "$os" in
 | 
			
		||||
            archlinux)
 | 
			
		||||
                echo "systemctl disable \"$name\""
 | 
			
		||||
            ;;
 | 
			
		||||
                debian|ubuntu)
 | 
			
		||||
                    echo update-rc.d -f \"$name\" remove
 | 
			
		||||
                ;;
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +113,7 @@ case "$state_should" in
 | 
			
		|||
                   exit 1
 | 
			
		||||
                ;;
 | 
			
		||||
            esac
 | 
			
		||||
 
 | 
			
		||||
        fi
 | 
			
		||||
    ;;
 | 
			
		||||
 | 
			
		||||
    *)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue