SHA256
1
0
forked from pool/systemd
systemd/systemd-sysv-convert

178 lines
4.1 KiB
Plaintext
Raw Normal View History

#!/bin/bash
if [ "$UID" != "0" ]; then
echo Need to be root.
exit 1
fi
declare -A results_runlevel
declare -A results_priority
usage() {
cat << EOF
usage: systemd-sysv-convert [-h] [--save] [--show] [--apply]
SERVICE [SERVICE ...]
EOF
}
help() {
usage
cat << EOF
Save and Restore SysV Service Runlevel Information
positional arguments:
SERVICE Service names
optional arguments:
-h, --help show this help message and exit
--save Save SysV runlevel information for one or more services
--show Show saved SysV runlevel information for one or more services
--apply Apply saved SysV runlevel information for one or more services
to systemd counterparts
EOF
}
find_service() {
local service
local runlevel
declare -i priority
service=$1
runlevel=$2
priority=-1
for l in $(ls /etc/rc.d/rc$runlevel.d/) ; do
initscript=$(basename $l)
if [ ${initscript:0:1} != "S" -o ${initscript:3} != "$service" ]; then
continue
fi
if [ ${initscript:1:2} -ge 0 -a ${initscript:1:2} -le 99 -a ${initscript:1:2} -ge $priority ]; then
if [ ${initscript:1:1} == 0 ]; then
priority=${initscript:2:1}
else
priority=${initscript:1:2}
fi
fi
done
if [ $priority -ge 0 ]; then
return $priority
else
return 255
fi
}
lookup_database() {
local services
local service
local service_file
local runlevel
local priority
local -i k
declare -a parsed
services=$@
k=0
results_runlevel=()
results_priority=()
while read line ; do
k+=1
parsed=($line)
service=${parsed[0]}
runlevel=${parsed[1]}
priority=${parsed[2]}
if [ $runlevel -lt 2 -o $runlevel -gt 5 ]; then
echo "Runlevel out of bounds in database line $k. Ignoring" >/dev/stderr
continue
fi
if [ $priority -lt 0 -o $priority -gt 99 ]; then
echo "Priority out of bounds in database line $k. Ignoring" >/dev/stderr
continue
fi
declare -i found
found=0
for s in $services ; do
if [ $s == $service ]; then
found=1
continue
fi
done
if [ $found -eq 0 ]; then
continue
fi
results_runlevel[$service]+=" $runlevel"
results_priority[$service]+=" $priority"
done < /var/lib/systemd/sysv-convert/database
}
Accepting request 440243 from Base:System - specfile: conflict systemd-bash-completion and systemd-mini-bash-completion Otherwise the build system detects that systemd-bash-completion and its mini variant are conflicting at files level even though those packages can't be installed on the same system. - specfile: clean up nss-* plugins descriptions and drop nss-myhostname-config script for now. Currently /etc/nsswitch.conf is supposed to be edited by the sysadmin to enable the modules. However for some reasons only nss-myhostname is removed from the conf file when the corresponding package is uninstalled. This is inconsistent so let's remove it. Actually I'm wondering if we shouldn't make those NSS plugins part of the main package and get rid of all those sub-packages... - specfile: remove old comments and unneeded sed command - specfile: no need to create systemd-update-utmp-runlevel.service symlinks anymore The symlinks in /usr/lib/systemd/system/&lt;target&gt;.target.wants/systemd-update-utmp-runlevel.service are created in Makefile.am since commit d5d8429a12c4b1. 'reboot' and 'poweroff' targets initially had the symlinks but there's not point since the latter conflicts shutdown.target whereas the 2 targets pull it in. See: https://github.com/systemd/systemd/pull/4429 - specfile: remove the following warnings: [ 256s] warning: File listed twice: /usr/lib/systemd/system/dbus.target.wants [ 256s] warning: File listed twice: /usr/lib/systemd/system/default.target.wants (forwarded request 440233 from fbui) OBS-URL: https://build.opensuse.org/request/show/440243 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=242
2016-11-22 18:55:40 +01:00
declare -i fail=0
case "$1" in
-h|--help)
help
exit 0
;;
--save)
shift
for service in $@ ; do
if [ ! -r "/etc/init.d/$service" ]; then
echo "SysV service $service does not exist" >/dev/stderr
Accepting request 440243 from Base:System - specfile: conflict systemd-bash-completion and systemd-mini-bash-completion Otherwise the build system detects that systemd-bash-completion and its mini variant are conflicting at files level even though those packages can't be installed on the same system. - specfile: clean up nss-* plugins descriptions and drop nss-myhostname-config script for now. Currently /etc/nsswitch.conf is supposed to be edited by the sysadmin to enable the modules. However for some reasons only nss-myhostname is removed from the conf file when the corresponding package is uninstalled. This is inconsistent so let's remove it. Actually I'm wondering if we shouldn't make those NSS plugins part of the main package and get rid of all those sub-packages... - specfile: remove old comments and unneeded sed command - specfile: no need to create systemd-update-utmp-runlevel.service symlinks anymore The symlinks in /usr/lib/systemd/system/&lt;target&gt;.target.wants/systemd-update-utmp-runlevel.service are created in Makefile.am since commit d5d8429a12c4b1. 'reboot' and 'poweroff' targets initially had the symlinks but there's not point since the latter conflicts shutdown.target whereas the 2 targets pull it in. See: https://github.com/systemd/systemd/pull/4429 - specfile: remove the following warnings: [ 256s] warning: File listed twice: /usr/lib/systemd/system/dbus.target.wants [ 256s] warning: File listed twice: /usr/lib/systemd/system/default.target.wants (forwarded request 440233 from fbui) OBS-URL: https://build.opensuse.org/request/show/440243 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=242
2016-11-22 18:55:40 +01:00
let fail++
continue
fi
for runlevel in 2 3 4 5; do
find_service $service $runlevel
priority=$?
if [ $priority -lt 255 ]; then
Accepting request 431464 from Base:System - Import a better fix from upstream for bsc#1001765 - Added: 0001-pid1-more-informative-error-message-for-ignored-noti.patch 0001-pid1-process-zero-length-notification-messages-again.patch - Updated (no code changes, only patch metadata) 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Re add back "udev: don't require nsserv and fillup" Did this in the wrong project... it was a complicated day today ;) - Added 2 patches to fix bsc#1001765 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Revert "udev: don't require nsserv and fillup" It's been judged too late for being part of SLE12 final release. Nevertheless it's part of Factory and will be reintroduced after the final release is out (ie through an update). - systemd-sysv-convert: make sure that /var/lib/systemd/sysv-convert/database is always initialized (bsc#982211) If "--save" command was used and the sysv init script wasn't enabled at all the database file wasn't created at all. This makes the subsequent call to "--apply" fail even though this should not considered as an error. - Added patches to fix journal with FSS protection enabled (bsc#1000435) 0001-journal-fix-HMAC-calculation-when-appending-a-data-o.patch 0001-journal-set-STATE_ARCHIVED-as-part-of-offlining-2740.patch OBS-URL: https://build.opensuse.org/request/show/431464 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=241
2016-10-01 23:46:24 +02:00
echo "$service $runlevel $priority"
fi
Accepting request 431464 from Base:System - Import a better fix from upstream for bsc#1001765 - Added: 0001-pid1-more-informative-error-message-for-ignored-noti.patch 0001-pid1-process-zero-length-notification-messages-again.patch - Updated (no code changes, only patch metadata) 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Re add back "udev: don't require nsserv and fillup" Did this in the wrong project... it was a complicated day today ;) - Added 2 patches to fix bsc#1001765 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Revert "udev: don't require nsserv and fillup" It's been judged too late for being part of SLE12 final release. Nevertheless it's part of Factory and will be reintroduced after the final release is out (ie through an update). - systemd-sysv-convert: make sure that /var/lib/systemd/sysv-convert/database is always initialized (bsc#982211) If "--save" command was used and the sysv init script wasn't enabled at all the database file wasn't created at all. This makes the subsequent call to "--apply" fail even though this should not considered as an error. - Added patches to fix journal with FSS protection enabled (bsc#1000435) 0001-journal-fix-HMAC-calculation-when-appending-a-data-o.patch 0001-journal-set-STATE_ARCHIVED-as-part-of-offlining-2740.patch OBS-URL: https://build.opensuse.org/request/show/431464 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=241
2016-10-01 23:46:24 +02:00
done >>/var/lib/systemd/sysv-convert/database
done
;;
--show)
shift
services=$@
lookup_database $services
for service in $services; do
if [ -z "${results_runlevel[$service]}" ]; then
echo No information found about service $service found. >/dev/stderr
Accepting request 440243 from Base:System - specfile: conflict systemd-bash-completion and systemd-mini-bash-completion Otherwise the build system detects that systemd-bash-completion and its mini variant are conflicting at files level even though those packages can't be installed on the same system. - specfile: clean up nss-* plugins descriptions and drop nss-myhostname-config script for now. Currently /etc/nsswitch.conf is supposed to be edited by the sysadmin to enable the modules. However for some reasons only nss-myhostname is removed from the conf file when the corresponding package is uninstalled. This is inconsistent so let's remove it. Actually I'm wondering if we shouldn't make those NSS plugins part of the main package and get rid of all those sub-packages... - specfile: remove old comments and unneeded sed command - specfile: no need to create systemd-update-utmp-runlevel.service symlinks anymore The symlinks in /usr/lib/systemd/system/&lt;target&gt;.target.wants/systemd-update-utmp-runlevel.service are created in Makefile.am since commit d5d8429a12c4b1. 'reboot' and 'poweroff' targets initially had the symlinks but there's not point since the latter conflicts shutdown.target whereas the 2 targets pull it in. See: https://github.com/systemd/systemd/pull/4429 - specfile: remove the following warnings: [ 256s] warning: File listed twice: /usr/lib/systemd/system/dbus.target.wants [ 256s] warning: File listed twice: /usr/lib/systemd/system/default.target.wants (forwarded request 440233 from fbui) OBS-URL: https://build.opensuse.org/request/show/440243 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=242
2016-11-22 18:55:40 +01:00
let fail++
continue
fi
declare -i count
count=0
priority=(${results_priority[$service]})
for runlevel in ${results_runlevel[$service]}; do
echo SysV service $service enabled in runlevel $runlevel at priority ${priority[$count]}
count+=1
done
done
;;
--apply)
shift
services=$@
for service in $services; do
if [ ! -f "/lib/systemd/system/$service.service" -a ! -f "/usr/lib/systemd/system/$service.service" ]; then
echo systemd service $service.service does not exist. >/dev/stderr
exit 1
fi
done
lookup_database $services
for service in $services; do
[ -f "/lib/systemd/system/$service.service" ] && service_file="/lib/systemd/system/$service.service"
[ -f "/usr/lib/systemd/system/$service.service" ] && service_file="/usr/lib/systemd/system/$service.service"
Accepting request 431464 from Base:System - Import a better fix from upstream for bsc#1001765 - Added: 0001-pid1-more-informative-error-message-for-ignored-noti.patch 0001-pid1-process-zero-length-notification-messages-again.patch - Updated (no code changes, only patch metadata) 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Re add back "udev: don't require nsserv and fillup" Did this in the wrong project... it was a complicated day today ;) - Added 2 patches to fix bsc#1001765 0001-If-the-notification-message-length-is-0-ignore-the-m.patch 0001-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch - Revert "udev: don't require nsserv and fillup" It's been judged too late for being part of SLE12 final release. Nevertheless it's part of Factory and will be reintroduced after the final release is out (ie through an update). - systemd-sysv-convert: make sure that /var/lib/systemd/sysv-convert/database is always initialized (bsc#982211) If "--save" command was used and the sysv init script wasn't enabled at all the database file wasn't created at all. This makes the subsequent call to "--apply" fail even though this should not considered as an error. - Added patches to fix journal with FSS protection enabled (bsc#1000435) 0001-journal-fix-HMAC-calculation-when-appending-a-data-o.patch 0001-journal-set-STATE_ARCHIVED-as-part-of-offlining-2740.patch OBS-URL: https://build.opensuse.org/request/show/431464 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=241
2016-10-01 23:46:24 +02:00
# If $service is not present in the database,
# then it simply means that the sysv init
# service was not enabled at all.
for runlevel in ${results_runlevel[$service]}; do
echo ln -sf $service_file /etc/systemd/system/runlevel$runlevel.target.wants/$service.service >/dev/stderr
mkdir -p "/etc/systemd/system/runlevel$runlevel.target.wants"
/bin/ln -sf $service_file /etc/systemd/system/runlevel$runlevel.target.wants/$service.service
done
done
;;
*) usage
Accepting request 440243 from Base:System - specfile: conflict systemd-bash-completion and systemd-mini-bash-completion Otherwise the build system detects that systemd-bash-completion and its mini variant are conflicting at files level even though those packages can't be installed on the same system. - specfile: clean up nss-* plugins descriptions and drop nss-myhostname-config script for now. Currently /etc/nsswitch.conf is supposed to be edited by the sysadmin to enable the modules. However for some reasons only nss-myhostname is removed from the conf file when the corresponding package is uninstalled. This is inconsistent so let's remove it. Actually I'm wondering if we shouldn't make those NSS plugins part of the main package and get rid of all those sub-packages... - specfile: remove old comments and unneeded sed command - specfile: no need to create systemd-update-utmp-runlevel.service symlinks anymore The symlinks in /usr/lib/systemd/system/&lt;target&gt;.target.wants/systemd-update-utmp-runlevel.service are created in Makefile.am since commit d5d8429a12c4b1. 'reboot' and 'poweroff' targets initially had the symlinks but there's not point since the latter conflicts shutdown.target whereas the 2 targets pull it in. See: https://github.com/systemd/systemd/pull/4429 - specfile: remove the following warnings: [ 256s] warning: File listed twice: /usr/lib/systemd/system/dbus.target.wants [ 256s] warning: File listed twice: /usr/lib/systemd/system/default.target.wants (forwarded request 440233 from fbui) OBS-URL: https://build.opensuse.org/request/show/440243 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=242
2016-11-22 18:55:40 +01:00
let fail=2
;;
esac
Accepting request 440243 from Base:System - specfile: conflict systemd-bash-completion and systemd-mini-bash-completion Otherwise the build system detects that systemd-bash-completion and its mini variant are conflicting at files level even though those packages can't be installed on the same system. - specfile: clean up nss-* plugins descriptions and drop nss-myhostname-config script for now. Currently /etc/nsswitch.conf is supposed to be edited by the sysadmin to enable the modules. However for some reasons only nss-myhostname is removed from the conf file when the corresponding package is uninstalled. This is inconsistent so let's remove it. Actually I'm wondering if we shouldn't make those NSS plugins part of the main package and get rid of all those sub-packages... - specfile: remove old comments and unneeded sed command - specfile: no need to create systemd-update-utmp-runlevel.service symlinks anymore The symlinks in /usr/lib/systemd/system/&lt;target&gt;.target.wants/systemd-update-utmp-runlevel.service are created in Makefile.am since commit d5d8429a12c4b1. 'reboot' and 'poweroff' targets initially had the symlinks but there's not point since the latter conflicts shutdown.target whereas the 2 targets pull it in. See: https://github.com/systemd/systemd/pull/4429 - specfile: remove the following warnings: [ 256s] warning: File listed twice: /usr/lib/systemd/system/dbus.target.wants [ 256s] warning: File listed twice: /usr/lib/systemd/system/default.target.wants (forwarded request 440233 from fbui) OBS-URL: https://build.opensuse.org/request/show/440243 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=242
2016-11-22 18:55:40 +01:00
exit $fail