As you're probably aware, by default when you install a package on a Debian or Ubuntu based system, if the package contains a service, that service will generally be enabled and started automatically when you install the package.
This is a problem for me.
I've found myself needing to manage templates for building LXC containers. There are several containers, each corresponding to a Debian or Ubuntu release. (There are also Red Hat-based containers, but they aren't relevant here.)
/var/lib/libvirt/filesystems/debian6_template
/var/lib/libvirt/filesystems/debian7_template
/var/lib/libvirt/filesystems/ubuntu1004_template
/var/lib/libvirt/filesystems/ubuntu1204_template
Occasionally I will find that the templates have a missing package or need some other change, so I will chroot into them to install the package. Unfortunately when I do that, I wind up with several copies of the package's service running!
By way of example, I found the templates didn't have a syslog daemon, so I installed one:
for template in /var/lib/libvirt/filesystems/{debian,ubuntu}*_template; do
chroot $template apt-get install rsyslog
done
And promptly wound up with four copies of rsyslog running. Not to mention two copies of exim4. Oops!
I read somewhere (though I can't find it again now) that it's not supposed to start services when running in a chroot, but that clearly isn't happening here.
One potentially viable nasty hack calls for temporarily replacing the various commands which actually start services, such as start-stop-daemon
and initctl
, though this is a lot more work than I really wanted to do. If I have no other choice, though...
The ideal solution here would be for Debian-based systems to stop doing this crap, but failing that, perhaps an obscure or undocumented command line option for apt-get
?
In case it wasn't clear, I really want to keep anything related to managing the templates outside the templates, if possible.