From: Michael Prokop Date: Fri, 30 Dec 2016 23:02:28 +0000 (+0100) Subject: Introduce service_wrapper to avoid direct /etc/init.d calls X-Git-Tag: v0.15.0~7 X-Git-Url: http://git.grml.org/?p=grml-autoconfig.git;a=commitdiff_plain;h=348b546fca905e5c591faeb1fb0d636918f9b0f1 Introduce service_wrapper to avoid direct /etc/init.d calls While at it drop support for any other syslog daemon than rsyslog. rsyslog is the package we ship via GRMLBASE anyway. Known issues: * /etc/init.d/loadcpufreq depends on systemd-sysv-generator (which we disable via grml-live to avoid automatic LSB script startups) * startx boot option doesn't work yet --- diff --git a/autoconfig.functions b/autoconfig.functions index a019878..bf5fa92 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -29,6 +29,22 @@ else SYSTEMD=false fi +service_wrapper() { + if [ "$#" -lt 2 ] ; then + echo "Usage: service_wrapper " >&2 + return 1 + fi + + local service="$1" + local action="$2" + + if $SYSTEMD ; then + systemctl "$action" "$service" + else + /etc/init.d/"$service" "$action" + fi +} + # zsh stuff iszsh(){ if [ -n "$ZSH_VERSION" ] ; then @@ -709,8 +725,8 @@ else fi if ! pgrep acpid >/dev/null ; then einfo "Starting acpi daemon." - $SYSTEMD && systemctl start acpid.socket - /etc/init.d/acpid start >>$DEBUG 2>&1 ; eend $? + service_wrapper acpid.socket start >>$DEBUG 2>&1 ; eend $? + service_wrapper acpid start >>$DEBUG 2>&1 ; eend $? else ewarn "acpi daemon already running." eend 0 @@ -863,7 +879,11 @@ if $VIRTUALBOX ; then return 0 fi -if [ -x /etc/init.d/loadcpufreq ] ; then +if ! [ -x /etc/init.d/loadcpufreq ] ; then + ewarn "loadcpufreq init script not available, ignoring cpu frequency scaling." + eend 0 + return 0 +else einfo "Trying to set up cpu frequency scaling:" eindent SKIP_CPU_GOVERNOR='' @@ -943,8 +963,8 @@ if checkbootparam 'ssh' ; then fi einfo "Starting secure shell server in background for root and user $localuser" - /etc/init.d/rmnologin start >>$DEBUG 2>>$DEBUG - /etc/init.d/ssh start >>$DEBUG 2>>$DEBUG & + service_wrapper rmnologin start >>$DEBUG 2>>$DEBUG + service_wrapper ssh start >>$DEBUG 2>>$DEBUG & eend $? fi @@ -1173,20 +1193,9 @@ config_syslog(){ if checkbootparam 'nosyslog'; then ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0 else - SYSLOGD='' - [ -x /etc/init.d/syslog-ng ] && SYSLOGD='syslog-ng' - [ -x /etc/init.d/rsyslog ] && SYSLOGD='rsyslog' - [ -x /etc/init.d/dsyslog ] && SYSLOGD='dsyslog' - [ -x /etc/init.d/sysklogd ] && SYSLOGD='sysklogd' - [ -x /etc/init.d/inetutils-syslogd ] && SYSLOGD='inetutils-syslogd' - - if [ -z "$SYSLOGD" ] ; then - eerror "No syslog daemon found." ; eend 1 - else - einfo "Starting $SYSLOGD in background." - /etc/init.d/$SYSLOGD start >>$DEBUG & - eend 0 - fi + einfo "Starting rsyslog in background." + service_wrapper rsyslog start >>$DEBUG & + eend 0 fi } # }}} @@ -1200,7 +1209,7 @@ config_gpm(){ eerror "No mouse found - not starting GPM." ; eend 1 else einfo "Starting gpm in background." - /etc/init.d/gpm start >>$DEBUG & + service_wrapper gpm start >>$DEBUG & # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start >>$DEBUG ) & eend 0 fi @@ -1219,10 +1228,10 @@ config_services(){ # if they contain the keyword "DO_NO_RUN_IN_BACKGROUND". if grep -q 'DO_NO_RUN_IN_BACKGROUND' "/etc/init.d/${service}" 2>>$DEBUG ; then einfo "Starting service ${service}." - /etc/init.d/${service} start >>$DEBUG + service_wrapper "${service}" start >>$DEBUG else einfo "Starting service ${service} in background." - /etc/init.d/${service} start >>$DEBUG & + service_wrapper "${service}" start >>$DEBUG & fi done eend $? @@ -1324,6 +1333,12 @@ config_stats() { # {{{ start X window system via grml-x config_x_startup(){ + + if $SYSTEMD ; then + ewarn "The startx boot option isn't yet supported via systemd, sorry." ; eend 0 + return + fi + # make sure we start X only if startx is used *before* a nostartx option # so it's possible to disable automatic X startup using nostart if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; then @@ -1726,8 +1741,7 @@ config_lvm(){ if checkbootparam 'nolvm' ; then ewarn "Skipping LVM code as requested on boot commandline." ; eend 0 else - # Debian etch provides /etc/init.d/lvm only, newer suites provide /etc/init.d/lvm2 - if ! [ -x /sbin/lvm -a -x /sbin/lvdisplay ] || ! [ -x /etc/init.d/lvm2 -o -x /etc/init.d/lvm ] ; then + if ! [ -x /sbin/lvm ] ; then eerror "LVM not available, can not execute it." ; eend 1 else if lvdisplay 2>&1 | grep -v 'No volume groups found' >/dev/null 2>&1 ; then @@ -1737,7 +1751,7 @@ config_lvm(){ eend 0 if checkbootparam 'lvm' ; then einfo "Bootoption LVM found. Searching for logical volumes:" - /etc/init.d/lvm2 start ; eend $? + service_wrapper lvm2 start ; eend $? fi eoutdent fi