6

On Debian, if the package you're installing has systemd services, they will be automatically enabled and started at post-install. I have found a way to disable the latter, but not the former (yet).

It seems like the post-install scripts use deb-systemd-helper to do this, which means disabling it shouldn't be impossible.

Edit: This is what I ended up doing.

/etc/systemd/system-preset/00-disable-all.preset:

disable *
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Salt
  • 95
  • 6

1 Answers1

3

It looks like "you can just create a symlink to mask ssh.service, before installing the package". E.g. ln -s /dev/null /etc/systemd/system/ssh.service.

I suppose this requires that you know the name of all services created by the package.

I am aware of one minor disadvantage for this approach. If you have a masked service which is also marked as "enabled", then systemd will log a warning during startup.

Note that a systemd "mask" will prevent the service from being started by any method, including manually running systemctl start ssh. So depending on what you want to do, you might want to remove the mask after you've installed the package.


If the package is ssh, it has a specific hack you can use instead! Bad news: this implies that a specific hack is needed in the package because all the other approaches have disadvantages. But you can have a look at the approaches I considered if you like :-). Configuring my sshd securely (with automation)

sourcejedi
  • 50,249
  • 2
    I'm looking for a way that works for every package that does this, and the masking one is one of the solutions that I'd like to avoid. – Salt Nov 25 '18 at 21:37
  • @Hwi417 I think you might have to resort to a dpkg-divert hack. I really want a feature similar to this, but I couldn't find it either. – sourcejedi Nov 25 '18 at 21:42
  • There is always the possibility of avoiding systemd altogether ;) – Rui F Ribeiro Nov 25 '18 at 22:02
  • @RuiFRibeiro and doing what, exactly? I think so far I've assumed systemd for simplicity, but I don't see how avoiding it helps. – sourcejedi Nov 26 '18 at 08:55
  • @RuiFRibeiro seems this question has been closed because it apparently has an answer on another question which uses systemd-specific features :-P. – sourcejedi Nov 26 '18 at 10:35
  • @sourcejedi I have seen it, it seems appropriate. I use Debian Stretch without any traces of systemd at all. (Devuan does not qualify) – Rui F Ribeiro Nov 26 '18 at 10:42
  • @RuiFRibeiro perhaps I am being too cryptic. I mean to ask, if you avoid systemd and instead use sysvinit (or however you prefer to manage your system!), how do you override the Debian default policy of both starting and enabling services when a package is installed? I've just learnt how to do so under systemd - but I don't know how to do so if I avoid systemd! – sourcejedi Nov 26 '18 at 10:45
  • @StephenKitt it must indeed be lacking documentation, because from all the documentation I've read my understanding was that policy-rc.d only applies to starting services, and did not affect the automatic enabling of services. As in the text of this question, for example. – sourcejedi Nov 26 '18 at 10:50
  • 1
    @sourcejedi It just hit me now you want to prevent enabling and not starting. hmmmm Dummy me. – Rui F Ribeiro Nov 26 '18 at 10:55