5
. /usr/share/debconf/confmodule
8
now=`date +%Y%m%dT%H%M`
9
logdir=/var/lib/insserv
10
logfile="$logdir/run-$now.log"
11
flagfile=/etc/init.d/.legacy-bootordering
13
# Make sure insserv is in path
16
# Based on code from dash postinst
19
div=$(dpkg-divert --list $2)
20
distrib=${4:-$2.distrib}
23
if [ -n "$div" ] && [ -z "${div%%*by $package}" ]; then
25
dpkg-divert --package $package --remove $2
28
status) # Return true if the divert is in effect
29
if [ -n "$div" ] && [ -z "${div%%*by $package}" ]; then
40
for link in $(cd $target/etc/rc$runlevel.d; ls S* || true); do
41
set `echo $link|sed "s%S\(..\)\(.*\)%\1 \2%"`
44
mv $target/etc/rc$runlevel.d/$link $target/etc/rc$runlevel.d/K$seq$service
50
if [ -z "$PROBLEMATIC" ] ; then
53
PROBLEMATIC="$PROBLEMATIC, $msg"
57
is_unsafe_to_activate() {
59
# Refuse to convert when there are obsolete init.d scripts left
60
# behind, as these tend to confuse the boot sequence.
61
echo "info: Checking if it is safe to convert to dependency based boot." 1>&2
62
for package in $(dpkg -S $(find /etc/init.d -type f -perm /+x) \
63
2>/dev/null | cut -d: -f1 | sort -u); do
64
obsolete_initscripts=$(dpkg-query -W -f='${Conffiles}\n' $package | \
65
grep 'obsolete$' | grep -o '/etc/init.d/[^ ]\+') || :
66
if [ "$obsolete_initscripts" ]; then
67
for initscript in $obsolete_initscripts; do
68
if [ -e "$initscript" ]; then
70
add_problematic "package $package left obsolete init.d script behind"
76
# Refuse to migrate if there are removed but not purged packages
77
# with init.d scripts, as their dependency information is probably
78
# outdated or missing, leading to incorrect ordering.
79
for package in $(dpkg -l $(dpkg -S /etc/init.d/* 2>/dev/null |
80
cut -d: -f1 |sort -u)|grep ^rc|awk '{print $2}') ; do
82
add_problematic "package $package removed by not purged"
85
# Refuse to migrate if insserv find problems, like loops,
86
# duplicate provides, script providing system facility or missing
88
insserv -nv > $logfile 2>&1 || true
89
errstr='There is a loop between|loop involving service|already provided!|provides system facility|missing LSB tags'
90
if egrep -q "$errstr" $logfile ; then
91
msg=$(egrep "$errstr" $logfile | sed 's/$/, /' | tr "\n" " ")
93
add_problematic "$msg"
100
# Save the current sequence numbers in
101
# /var/lib/update-rc.d/. This directory will be updated
102
# when update-rc.d is called, to make it possible to migrate away
103
# from dependency based boot sequencing. If some script is
104
# missing in /var/lib/update-rc.d/, one will have to
105
# reconfigure the package it belong to for update-rc.d to update
106
# the content in /var/lib/update-rc.d/.
107
/usr/share/sysv-rc/saveconfig -s /var/lib/update-rc.d
109
echo "info: Reordering boot system, log to $logfile" 1>&2
111
echo "info: Converting rc0.d/S* and rc6.d/S* to K*." 1>&2
114
echo "info: running insserv" 1>&2
118
# Indicate that system is no longer using the legacy ordering
126
if is_unsafe_to_activate ; then
127
# Make sure the note is seen every time
128
db_fset sysv-rc/unable-to-convert seen false
129
db_subst sysv-rc/unable-to-convert PROBLEMATIC "$PROBLEMATIC"
130
db_input critical sysv-rc/unable-to-convert || [ $? -eq 30 ]
134
# Ask if the legacy boot sequence should be converted to
137
# Priority is critical during upgrades, to give those with
138
# existing installations a good chance of seeing and rejecting
140
db_input critical sysv-rc/convert-legacy || [ $? -eq 30 ]
143
db_get sysv-rc/convert-legacy || true
144
if [ true = "$RET" ] ; then
145
if activate_insserv ; then
146
echo "success: Enabled dependency based boot system." 1>&2
148
echo "error: Something failed while migrating." 1>&2
151
echo "warning: Asked to not convert legacy boot sequence to dependency based boot sequencing." 1>&2
158
# Remove divert created by insserv during upgrades if it
159
# exist. It was dropped in insserv 1.12.0-11 converted since
160
# sysvinit 2.87dsf-3, 2009-08-19.
161
if [ -f /var/run/sysv-rc.upgrade ]; then
162
lastver=$(cat /var/run/sysv-rc.upgrade)
163
if dpkg --compare-versions "$2" lt 2.87dsf-3 ; then
164
if check_divert status /usr/sbin/update-rc.d \
165
/usr/sbin/update-rc.d-insserv ; then
166
check_divert false /usr/sbin/update-rc.d \
167
/usr/sbin/update-rc.d-insserv
168
rm /var/lib/insserv/using-insserv
173
rm /var/run/sysv-rc.upgrade
175
if [ -f $flagfile ] && [ -n "$USEINSSERV" ]; then
176
# Still using legacy ordering, try to convert
177
if try_to_convert ; then
180
echo "error: Unable to migrate to dependency based boot sequencing." 1>&2