Some nice debian tricks discovered lately

2012-09-26 at 20:36:23 | categories: tips, linux

Lately I learned something new about my Debian and just wanted to share this here, with hope that it can be useful for someone and also as a way to remember the solutions for myself :)

Order of starting scripts

Among standard standard starting scripts in /etc/init.d/ I placed my own script for doing backup. Basically the idea was to do full backup of /etc/, installed DEB files, mysql databases and whole /home to an external HDD. The script was then just linked as in /etc/rc0.d/, and when executed it checked if some HDD is mounted as some mountpoint (/mnt/backup) and if so then the backup was performed.

It worked pretty well until Debian switched to DependencyBasedBoot. Actually it still worked quite OK, but unfortunately mysql was switched off earlier so it could not be backed up anymore. The reason for that was that previously K01mysql was executed later than, because of their names. With dependency based boot it not the case anymore, so it was necessary to specify the order explicit.

Solution was to tell that mysql must be running when the script is executed. After reading this I just added header to the script like so:

# Provides:          make_backup
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs mysql
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Makes backup if needed

As you can see Required-Stop contains now mysql, so my script gets executed before mysql which solved the problem :)

Btw. very useful advice from the wiki mentioned above is how to see a dependency graph:

aptitude install insserv graphviz
/usr/share/insserv/check-initd-order -g >
/usr/share/insserv/check-initd-order -g -k >

Really cool - check it out.

How to see deb packages installed but not auto-installed?

Lately I reinstalled one of my debian machines and wanted to make a list of installed deb packages.

Of course dpkg --get-selections can tell you that, but it won't tell you which debs are installed just to satisfy some dependencies. Try aptitude search '~i !~M' - it shows you just those which were explicitly selected for installation. This is really useful when reinstalling stuff.