2

I like to set up Debian or Ubuntu as servers and have to install many applications before configuring them. Sometimes, I install an application just so that I have the option to use it at a later date if needed.

I don't want these apps to automatically be enabled and started. This creates problems, especially if their settings hasn't been changed and there are conflicts with other apps.

For example, I installed the following software: apt install nginx apache2 lighttpd.

And when I reboot, Nginx is listening on port 80, mis-configured and insecure, and I have to disable it.

enter image description here

I disable it and reboot, see now who took over the port:

enter image description here

If I disable lighttpd, Apache2 will take its place.

This doesn't make sense, I feel like I'm fighting with the applications I install... Any way to make it stop? Any way to disable this behavior of enabling and starting services upon installation?

EDIT

Found a solution for preventing auto start:

echo exit 101 > /usr/sbin/policy-rc.d chmod +x /usr/sbin/policy-rc.d 

Found a solution for preventing auto enable:

https://unix.stackexchange.com/a/723679/547917

But this is ridiculous there's nothing simpler, some kind of swtch using apt --no-enable --no-start, for example.

1
  • Hard to believe there is no way to prevent services from being started upon installation, incredible! Commented Nov 5, 2022 at 15:22

3 Answers 3

1

You can ensure that newly-installed services — at least, those configured using systemd units, which is most now — are disabled by default by setting up a systemd preset:

sudo mkdir -p /etc/systemd/system-preset echo 'disable *' | sudo tee /etc/systemd/system-preset/99-default-disable.preset 

See man systemd.preset for details.

1
  • Sadly that didn't work, when I installed dnsmasq afterwards, it tried to start it and there was a big red message because port 53 is already taken by another service. Commented Nov 4, 2022 at 18:45
1

If you are creating your own package and do not want the service to automatically start, you can install a preset file. There are many locations, I chose the following for my package because the folder already exists with the default systemd file:

/etc/systemd/system-preset/ 

I named my file after my package with 50- at the start and .preset as the extension:

50-<package-name>.preset 

And inside the file, I added one line:

disable <service-name>.service 

Usually, <service-name> is the same as <package-name>, but not always.

Now, in the debian/<package-name>.install file, I have one more line:

/usr/share/<package-name>/50-<package-name>.preset /etc/systemd/system-preset/ 

Somewhere in one of my CMakeLists.txt file, I install that .preset file in the /usr/share/<package-name>/ directory because you cannot directly install files under /etc/.... Something like this:

project(service-config) INSTALL( FILES 50-<package-name>.preset DESTINATION share/<package-name> ) 

Now the service status says:

...; vendor preset: disabled) 

In other words, start with a disabled service. In my case, the service requires the installation of a key before it has a chance to work so I wanted it disabled by default.

0

We added the following lines in the debian/rules file of our own services:

override_dh_installsystemd: dh_installsystemd --name yourservicename --no-start 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.