Run a command before & after ubuntu apt upgrade & unattended-upgrades

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












On an Ubuntu 16.04.3 LTS server I run some process monitors, but I also run apt manually as well as unattended-upgrades for security updates.



This sometimes causes the monitors to report and act on programs that were stopped by apt during apt upgrade.



Is there a way to run a command when unattended-upgrades/apt starts the upgrades (to stop the monitors) and again when unattended-upgrades/apt finishes (to restart the monitors)?



I found APT::Update::Pre-Invoke and APT::Update::Post-Invoke hooks but the apt update step is not the problem, and apt itself does not seem to have any pre/post upgrade hooks.







share|improve this question


























    up vote
    3
    down vote

    favorite












    On an Ubuntu 16.04.3 LTS server I run some process monitors, but I also run apt manually as well as unattended-upgrades for security updates.



    This sometimes causes the monitors to report and act on programs that were stopped by apt during apt upgrade.



    Is there a way to run a command when unattended-upgrades/apt starts the upgrades (to stop the monitors) and again when unattended-upgrades/apt finishes (to restart the monitors)?



    I found APT::Update::Pre-Invoke and APT::Update::Post-Invoke hooks but the apt update step is not the problem, and apt itself does not seem to have any pre/post upgrade hooks.







    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      On an Ubuntu 16.04.3 LTS server I run some process monitors, but I also run apt manually as well as unattended-upgrades for security updates.



      This sometimes causes the monitors to report and act on programs that were stopped by apt during apt upgrade.



      Is there a way to run a command when unattended-upgrades/apt starts the upgrades (to stop the monitors) and again when unattended-upgrades/apt finishes (to restart the monitors)?



      I found APT::Update::Pre-Invoke and APT::Update::Post-Invoke hooks but the apt update step is not the problem, and apt itself does not seem to have any pre/post upgrade hooks.







      share|improve this question














      On an Ubuntu 16.04.3 LTS server I run some process monitors, but I also run apt manually as well as unattended-upgrades for security updates.



      This sometimes causes the monitors to report and act on programs that were stopped by apt during apt upgrade.



      Is there a way to run a command when unattended-upgrades/apt starts the upgrades (to stop the monitors) and again when unattended-upgrades/apt finishes (to restart the monitors)?



      I found APT::Update::Pre-Invoke and APT::Update::Post-Invoke hooks but the apt update step is not the problem, and apt itself does not seem to have any pre/post upgrade hooks.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 30 '17 at 18:07









      GAD3R

      22.7k154895




      22.7k154895










      asked Oct 28 '17 at 20:49









      simpleuser

      17512




      17512




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          There are three hooks you can use for this:




          • DPkg::Pre-Invoke is run once, before all the package manipulation sequences in one apt invocation;


          • DPkg::Pre-Install-Pkgs is also run once, before the package manipulation sequences, after the Pre-Invoke hook, and with a list of all the packages which will be installed;


          • DPkg::Post-Invoke is run once, after the package manipulation sequences.

          The documentation isn’t all that clear (do read man apt.conf though), but reading the source code supports the above. Specifying hooks also confirms this (for example, this is how apt-listbugs works).






          share|improve this answer






















          • Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
            – simpleuser
            Nov 1 '17 at 23:52










          • Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
            – Stephen Kitt
            Nov 2 '17 at 8:22










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401126%2frun-a-command-before-after-ubuntu-apt-upgrade-unattended-upgrades%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          There are three hooks you can use for this:




          • DPkg::Pre-Invoke is run once, before all the package manipulation sequences in one apt invocation;


          • DPkg::Pre-Install-Pkgs is also run once, before the package manipulation sequences, after the Pre-Invoke hook, and with a list of all the packages which will be installed;


          • DPkg::Post-Invoke is run once, after the package manipulation sequences.

          The documentation isn’t all that clear (do read man apt.conf though), but reading the source code supports the above. Specifying hooks also confirms this (for example, this is how apt-listbugs works).






          share|improve this answer






















          • Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
            – simpleuser
            Nov 1 '17 at 23:52










          • Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
            – Stephen Kitt
            Nov 2 '17 at 8:22














          up vote
          4
          down vote



          accepted










          There are three hooks you can use for this:




          • DPkg::Pre-Invoke is run once, before all the package manipulation sequences in one apt invocation;


          • DPkg::Pre-Install-Pkgs is also run once, before the package manipulation sequences, after the Pre-Invoke hook, and with a list of all the packages which will be installed;


          • DPkg::Post-Invoke is run once, after the package manipulation sequences.

          The documentation isn’t all that clear (do read man apt.conf though), but reading the source code supports the above. Specifying hooks also confirms this (for example, this is how apt-listbugs works).






          share|improve this answer






















          • Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
            – simpleuser
            Nov 1 '17 at 23:52










          • Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
            – Stephen Kitt
            Nov 2 '17 at 8:22












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          There are three hooks you can use for this:




          • DPkg::Pre-Invoke is run once, before all the package manipulation sequences in one apt invocation;


          • DPkg::Pre-Install-Pkgs is also run once, before the package manipulation sequences, after the Pre-Invoke hook, and with a list of all the packages which will be installed;


          • DPkg::Post-Invoke is run once, after the package manipulation sequences.

          The documentation isn’t all that clear (do read man apt.conf though), but reading the source code supports the above. Specifying hooks also confirms this (for example, this is how apt-listbugs works).






          share|improve this answer














          There are three hooks you can use for this:




          • DPkg::Pre-Invoke is run once, before all the package manipulation sequences in one apt invocation;


          • DPkg::Pre-Install-Pkgs is also run once, before the package manipulation sequences, after the Pre-Invoke hook, and with a list of all the packages which will be installed;


          • DPkg::Post-Invoke is run once, after the package manipulation sequences.

          The documentation isn’t all that clear (do read man apt.conf though), but reading the source code supports the above. Specifying hooks also confirms this (for example, this is how apt-listbugs works).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 2 '17 at 8:24

























          answered Oct 28 '17 at 21:03









          Stephen Kitt

          144k22312377




          144k22312377











          • Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
            – simpleuser
            Nov 1 '17 at 23:52










          • Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
            – Stephen Kitt
            Nov 2 '17 at 8:22
















          • Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
            – simpleuser
            Nov 1 '17 at 23:52










          • Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
            – Stephen Kitt
            Nov 2 '17 at 8:22















          Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
          – simpleuser
          Nov 1 '17 at 23:52




          Works just like I wanted: DPkg::Pre-Invoke is run once before the start of all package manipulation sequences for that 'apt upgrade' run, and DPkg::Post-Invoke is run once when they are all completed. Just wanted to clarify that they don't get run before each (any) package.
          – simpleuser
          Nov 1 '17 at 23:52












          Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
          – Stephen Kitt
          Nov 2 '17 at 8:22




          Indeed, that’s what I was trying to explain above, but my answer wasn’t clear enough (and that’s what’s not clear in the documentation either).
          – Stephen Kitt
          Nov 2 '17 at 8:22

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401126%2frun-a-command-before-after-ubuntu-apt-upgrade-unattended-upgrades%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay