18.08.10

Reinstall Debian init.d scripts into default runlevels

The following zsh snippet allows you to re-install any missing startup/init.d links.

This can be useful/required when e.g. installing an upstart based distribution (like Ubuntu Lucid) has removed some of those, and you want them back after downgrading to Hardy or switching to Debian testing (like I just did).
(apt-get install --reinstall won't bring back those links; you would have to purge (apt-get purge) and reinstall the package instead, removing any other configuration of the package though)

It basically looks for any init scripts that are not present in /etc/rc?.d/S* and then looks at the packages' postinstallation script for an update-rc.d command.

It will not install anything, but only output them (and allows you to pipe it into "sh" for execution).

Worked fine on my "messed up" system, but has rather odd results on my Maverick desktop.

Code:

for i in /etc/init.d/* ; do
    a=( /etc/rc?.d/S*$i:t(N) );
    ((${#a})) && continue;
    package=$(dpkg -S $i 2>/dev/null |cut -d: -f1);
    [[ -z $package ]] && continue;
    echo "# $i: $package";
    grep "update-rc\.d $i:t" /var/lib/dpkg/info/$package.postinst;
done

(in case you need to extract the init script altogether, the following might help for starters:
dpkg-deb --extract /var/cache/apt/archives/$PACKAGE.deb /tmp/foo.)

2 comments

Comment from: gypsymauro [Visitor]
gypsymauroyou can use
update-rc.d missingscriptname defaults

ciao
Mauro
2010-08-19 @ 19:12
Comment from: Daniel [Member] Email
No, "defaults" with update-rc.d does not use the package defaults, but install it in a given set of runlevels with sequence number 20.
From the man page:
If defaults is used then update-rc.d will make links to start the service
in runlevels 2345 and to stop the service in runlevels 016. By
default all the links will have sequence number 20, but this should be
overridden if there are dependencies.
2010-08-20 @ 13:11

Leave a comment


Your email address will not be revealed on this site.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
You can just use your OpenID to provide your name, e-mail and url.
Seitenleiste