SHA256
1
0
forked from pool/systemd

- Now that chkconfig/insserv are history, let's implement the strict

minimum in systemd-sysv-install to enable/disable SysV init scripts
  (bsc#1186595 bsc#1186359)
  Indeed there's no much point in dropping SysV support completely
  until upstream will do especially since 3rd party applications such
  as vmware still rely on it, see bsc#1186359).

OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd?expand=0&rev=1161
This commit is contained in:
Franck Bui 2021-06-04 07:40:09 +00:00 committed by Git OBS Bridge
parent 809be49d24
commit d8f523db13
3 changed files with 154 additions and 25 deletions

View File

@ -1,3 +1,14 @@
-------------------------------------------------------------------
Fri Jun 4 07:32:16 UTC 2021 - Franck Bui <fbui@suse.com>
- Now that chkconfig/insserv are history, let's implement the strict
minimum in systemd-sysv-install to enable/disable SysV init scripts
(bsc#1186595 bsc#1186359)
Indeed there's no much point in dropping SysV support completely
until upstream will do especially since 3rd party applications such
as vmware still rely on it, see bsc#1186359).
------------------------------------------------------------------- -------------------------------------------------------------------
Tue May 25 16:30:40 UTC 2021 - Franck Bui <fbui@suse.com> Tue May 25 16:30:40 UTC 2021 - Franck Bui <fbui@suse.com>

View File

@ -1,41 +1,148 @@
#!/bin/sh #!/bin/bash
# This script is called by "systemctl enable/disable" when the given unit is a # This script is called by "systemctl enable/disable" when the given unit is a
# SysV init.d script. It needs to call the distribution's mechanism for # SysV init.d script. It needs to call the distribution's mechanism for
# enabling/disabling those, such as chkconfig, update-rc.d, or similar. This # enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
# can optionally take a --root argument for enabling a SysV init script # can optionally take a --root argument for enabling a SysV init script
# in a chroot or similar. # in a chroot or similar.
#
# chkconfig(8) and insserv(8) are no more available hence let's do the
# bare minimum and create/remote the symlinks for the well known
# runlevels and nothing more. Note that we don't take care of
# enabling/disabling the service dependencies as the sysv-generator
# will take care of them for us (openSUSE specific).
#
set -e set -e
usage() { usage() {
echo "Usage: $0 [--root=path] enable|disable|is-enabled <sysv script name>" >&2 echo >&2 "Usage: $0 [--quiet] [--root=path] enable|disable|is-enabled <sysv script name>"
exit 1 exit 1
} }
info() {
$quiet || echo "$*"
}
die() {
echo >&2 "error: $*, aborting."
exit 1
}
declare -A lsb_header
check_runlevels() {
for l in $*; do
# Sanity check
case $l in
0|1|2|3|4|5|6) continue ;;
*) return 1
esac
done
}
load_initscript() {
local found_lsb_start_marker=false
local found_lsb_end_marker=false
[ -r $1 ] || die "initscript /etc/init.d/$1 can't be read"
lsb_header=()
while read line; do
# skip anything that is not a comment
[[ "$line" =~ ^# ]] || continue
if ! $found_lsb_start_marker; then
[ "$line" == "### BEGIN INIT INFO" ] &&
found_lsb_start_marker=true
continue
fi
line=$(echo ${line:1})
case "$line" in
Default-Start:*)
levels=$(echo ${line:14})
check_runlevels $levels ||
die "Invalid runlevels specified in $line"
lsb_header[Default-Start]=$levels
;;
"## END INIT INFO")
found_lsb_end_marker=true
break ;;
esac
done <$1
$found_lsb_end_marker ||
die "malformated LSB header in $1: missing LSB end marker"
}
enable_initscript() {
load_initscript $1
for l in ${lsb_header[Default-Start]}; do
symlink="$(pwd)/rc${l}.d/S50$1"
info "ln -sf ../$1 $symlink"
ln -sf ../$1 "$symlink"
done
}
disable_initscript() {
for symlink in rc*.d/[SK]*; do
[ -L $symlink ] && [ $(readlink $symlink) = "../$1" ] && {
info "rm $(pwd)/$symlink"
rm $symlink
}
done
}
is_initscript_enabled() {
for symlink in rc*.d/S*; do
[ -L $symlink ] && [ $(readlink $symlink) = "../$1" ] &&
return 0
done
return 1
}
root=
quiet=false
# parse options # parse options
eval set -- "$(getopt -o r: --long root: -- "$@")" eval set -- "$(getopt --name $(basename $0) -o hqr: --long help,quiet,root: -- "$@")"
while true; do while true; do
case "$1" in case "$1" in
-r|--root) -h|--help)
ROOT="$2" usage ;;
shift 2 ;; -r|--root)
--) shift ; break ;; shift
*) usage ;; root=$1 ;;
esac -q|--quiet)
quiet=true ;;
--)
shift
break ;;
*)
usage ;;
esac
shift
done done
NAME="$2" [ $# -eq 2 ] || usage
[ -n "$NAME" ] || usage action=$1
name=$2
case "$1" in sysvinit_path=$(realpath -q -e $root/etc/init.d) ||
enable) die "$root/etc/init.d: no such file or directory"
chkconfig $ROOT --no-systemctl -s "$NAME" on
;; cd $sysvinit_path
disable)
chkconfig $ROOT --no-systemctl -s "$NAME" off case "$action" in
;; enable) enable_initscript $name ;;
is-enabled) disable) disable_initscript $name ;;
chkconfig $ROOT --no-systemctl -c "$NAME" is-enabled) is_initscript_enabled $name ;;
;; *) usage
*)
usage ;;
esac esac

View File

@ -1,3 +1,14 @@
-------------------------------------------------------------------
Fri Jun 4 07:32:16 UTC 2021 - Franck Bui <fbui@suse.com>
- Now that chkconfig/insserv are history, let's implement the strict
minimum in systemd-sysv-install to enable/disable SysV init scripts
(bsc#1186595 bsc#1186359)
Indeed there's no much point in dropping SysV support completely
until upstream will do especially since 3rd party applications such
as vmware still rely on it, see bsc#1186359).
------------------------------------------------------------------- -------------------------------------------------------------------
Tue May 25 16:30:40 UTC 2021 - Franck Bui <fbui@suse.com> Tue May 25 16:30:40 UTC 2021 - Franck Bui <fbui@suse.com>