systemd/systemd-sysv-install
Dominique Leuenberger 441419a1e6 Accepting request 902866 from Base:System
- Import commit e9a23d9e064c2e7ac21a1b984d116bcf15327e63
  8dd19c6ee3 sd-device: allow to read sysattr which contains embedded NUL
  d52409e5fe pid1: only add a Wants= type dependency on /tmp when PrivateTmp=yes (bsc#1181970

- Import commit fcdb8dce591db2f5fc3c1e3eeb7abe9a2090b401
  aa2d840a3b compat-rules: fix warning: "label ‘out’ defined but not used" in path_id_compat.c
- Restore 61-persistent-storage-compat.rules that was mistakenly
  dropped during the merge of v248.

- Create /run/lock/subsys again (bsc#1187292)
  The creation of this directory was mistakenly dropped when
  'filesystem' package took the initialization of the generic paths
  over.
  Paths under /run/lock are still managed by systemd for lack of
  better place.

- Drop systemd's dependency on udev (jsc#PM-2677)
  In some environments (i.e. containers) udev is usually not necessary
  but pulls in unnecessary packages.

- 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).

- Allow the sysusers config files shipped by systemd rpms to be
  overriden during system installation (bsc#1171962)
- While at it, add a comment to explain why we don't use

OBS-URL: https://build.opensuse.org/request/show/902866
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=330
2021-07-01 05:05:27 +00:00

149 lines
2.9 KiB
Bash

#!/bin/bash
# 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
# enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
# can optionally take a --root argument for enabling a SysV init script
# 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
usage() {
echo >&2 "Usage: $0 [--quiet] [--root=path] enable|disable|is-enabled <sysv script name>"
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
eval set -- "$(getopt --name $(basename $0) -o hqr: --long help,quiet,root: -- "$@")"
while true; do
case "$1" in
-h|--help)
usage ;;
-r|--root)
shift
root=$1 ;;
-q|--quiet)
quiet=true ;;
--)
shift
break ;;
*)
usage ;;
esac
shift
done
[ $# -eq 2 ] || usage
action=$1
name=$2
sysvinit_path=$(realpath -q -e $root/etc/init.d) ||
die "$root/etc/init.d: no such file or directory"
cd $sysvinit_path
case "$action" in
enable) enable_initscript $name ;;
disable) disable_initscript $name ;;
is-enabled) is_initscript_enabled $name ;;
*) usage
esac