0

How can I stop nginx before APT upgrades run in Ubuntu?

We run unattended upgrades on the server and in case there is any upgrade that will interfere with nginx I would like to stop the nginx service before doing upgrades. (E.g. an upgrade of nginx itself or something that could affect the network connectivity.)

After the upgrade has run I want nginx to launch again automatically.

This is one of multiple servers in a pool sitting behind a load balancer, so the user-facing service will not be affected by nginx being down. The web server is nginx 1.14.2 and the OS is Ubuntu 16.04.6 LTS.

  • 1
    If nginx is being upgraded, apt will stop and start it, itself. You probably don't need to do anything at all. Nobody else does. – Michael Hampton Apr 9 at 15:29
2

Adapting https://wiki.debian.org/ReadonlyRoot#Make_apt-get_remount_.2F_if_needed probably would work.

I'd give this variant a try:

DPkg {
    Pre-Invoke { "systemctl stop nginx"; };
    Post-Invoke { "systemctl start nginx"; };
};

Put this into a file and place it in /etc/apt.conf.d.

It will not check if the upgrade 'interferes' with your nginx intstallation, it stops it always.

-1

You can stop Nginx using

systemctl stop nginx

And you can start it using

systemctl start nginx
  • since the question involves "unattended upgrades", I doubt that a manual procedure such as this one is what is wanted here. – asdmin Apr 9 at 14:51
  • he is asking if it is possible to stop nginx before upgrading – Diego Velez Apr 9 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.