How do I reload a group of systemd services?

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











up vote
8
down vote

favorite
2












I want to reload (not restart!) a group of services upon an event.



For example, if I update my SSL certificates, I want every service that uses them reloaded (nginx and postfix come to mind). Neither I want to remember which services on a given server use SSL certificates. It should be enough to have them grouped when they were configured.



On the other hand, I'd like to avoid changing .service files provided with the packages, because this will require manual intervention during updates.



How do I accomplish that?



There is an option to stop a group of services on request, but this would make them inaccessible for a second or two, or worse - they may stay down until fixed. I can't afford that.










share|improve this question























  • I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
    – Jacob Evans
    Apr 1 '17 at 17:40











  • @JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
    – sanmai
    Apr 2 '17 at 10:42










  • if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
    – quixotic
    Apr 2 '17 at 11:59














up vote
8
down vote

favorite
2












I want to reload (not restart!) a group of services upon an event.



For example, if I update my SSL certificates, I want every service that uses them reloaded (nginx and postfix come to mind). Neither I want to remember which services on a given server use SSL certificates. It should be enough to have them grouped when they were configured.



On the other hand, I'd like to avoid changing .service files provided with the packages, because this will require manual intervention during updates.



How do I accomplish that?



There is an option to stop a group of services on request, but this would make them inaccessible for a second or two, or worse - they may stay down until fixed. I can't afford that.










share|improve this question























  • I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
    – Jacob Evans
    Apr 1 '17 at 17:40











  • @JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
    – sanmai
    Apr 2 '17 at 10:42










  • if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
    – quixotic
    Apr 2 '17 at 11:59












up vote
8
down vote

favorite
2









up vote
8
down vote

favorite
2






2





I want to reload (not restart!) a group of services upon an event.



For example, if I update my SSL certificates, I want every service that uses them reloaded (nginx and postfix come to mind). Neither I want to remember which services on a given server use SSL certificates. It should be enough to have them grouped when they were configured.



On the other hand, I'd like to avoid changing .service files provided with the packages, because this will require manual intervention during updates.



How do I accomplish that?



There is an option to stop a group of services on request, but this would make them inaccessible for a second or two, or worse - they may stay down until fixed. I can't afford that.










share|improve this question















I want to reload (not restart!) a group of services upon an event.



For example, if I update my SSL certificates, I want every service that uses them reloaded (nginx and postfix come to mind). Neither I want to remember which services on a given server use SSL certificates. It should be enough to have them grouped when they were configured.



On the other hand, I'd like to avoid changing .service files provided with the packages, because this will require manual intervention during updates.



How do I accomplish that?



There is an option to stop a group of services on request, but this would make them inaccessible for a second or two, or worse - they may stay down until fixed. I can't afford that.







systemd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:36









Community♦

1




1










asked Jan 3 '17 at 9:01









sanmai

492515




492515











  • I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
    – Jacob Evans
    Apr 1 '17 at 17:40











  • @JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
    – sanmai
    Apr 2 '17 at 10:42










  • if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
    – quixotic
    Apr 2 '17 at 11:59
















  • I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
    – Jacob Evans
    Apr 1 '17 at 17:40











  • @JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
    – sanmai
    Apr 2 '17 at 10:42










  • if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
    – quixotic
    Apr 2 '17 at 11:59















I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
– Jacob Evans
Apr 1 '17 at 17:40





I'm not sure how you deploy certs, but here is also a pre-hook and post-hook for most automagic renewals /opt/letsencrypt/letsencrypt-auto renew --pre-hook "service nginx stop; service postfix stop; service squid stop" --post-hook "service nginx start; service postfix start; service squid start" also: certmonger has postsave and presave commands
– Jacob Evans
Apr 1 '17 at 17:40













@JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
– sanmai
Apr 2 '17 at 10:42




@JacobEvans That's what I use! Earlier there was a problem in a config file parser for certbot: it didn't permit semicolons. Therefore you had to use a command line argument, or do it in one go. Right now all this is unnecessarily.
– sanmai
Apr 2 '17 at 10:42












if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
– quixotic
Apr 2 '17 at 11:59




if you make your .service file edits as overrides you can avoid the updating problem. sudo systemctl edit foo.service will store your changes in /etc/systemd/system/foo.service.d/override.conf rather than alter the installed foo.service file.
– quixotic
Apr 2 '17 at 11:59










1 Answer
1






active

oldest

votes

















up vote
16
down vote



accepted
+50










Create /etc/systemd/system/ssl-reload.target with the following contents.



[Unit]
Description=Services which need reloaded with SSL certs are updated.
PropagatesReloadTo=nginx postfix


Then create another file: /etc/systemd/system/ssl-reload.path



[Unit]
Description=Restart services which use SSL when the cert directory changes

[Path]
PathChanged=/path/to/your/ssl/certs/dir

[Install]
WantedBy=multi-user.target


Then:



systemctl enable ssl-reload.path
systemctl start ssl-reload.path


With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.



if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.






share|improve this answer






















    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%2f334471%2fhow-do-i-reload-a-group-of-systemd-services%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
    16
    down vote



    accepted
    +50










    Create /etc/systemd/system/ssl-reload.target with the following contents.



    [Unit]
    Description=Services which need reloaded with SSL certs are updated.
    PropagatesReloadTo=nginx postfix


    Then create another file: /etc/systemd/system/ssl-reload.path



    [Unit]
    Description=Restart services which use SSL when the cert directory changes

    [Path]
    PathChanged=/path/to/your/ssl/certs/dir

    [Install]
    WantedBy=multi-user.target


    Then:



    systemctl enable ssl-reload.path
    systemctl start ssl-reload.path


    With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.



    if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.






    share|improve this answer


























      up vote
      16
      down vote



      accepted
      +50










      Create /etc/systemd/system/ssl-reload.target with the following contents.



      [Unit]
      Description=Services which need reloaded with SSL certs are updated.
      PropagatesReloadTo=nginx postfix


      Then create another file: /etc/systemd/system/ssl-reload.path



      [Unit]
      Description=Restart services which use SSL when the cert directory changes

      [Path]
      PathChanged=/path/to/your/ssl/certs/dir

      [Install]
      WantedBy=multi-user.target


      Then:



      systemctl enable ssl-reload.path
      systemctl start ssl-reload.path


      With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.



      if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.






      share|improve this answer
























        up vote
        16
        down vote



        accepted
        +50







        up vote
        16
        down vote



        accepted
        +50




        +50




        Create /etc/systemd/system/ssl-reload.target with the following contents.



        [Unit]
        Description=Services which need reloaded with SSL certs are updated.
        PropagatesReloadTo=nginx postfix


        Then create another file: /etc/systemd/system/ssl-reload.path



        [Unit]
        Description=Restart services which use SSL when the cert directory changes

        [Path]
        PathChanged=/path/to/your/ssl/certs/dir

        [Install]
        WantedBy=multi-user.target


        Then:



        systemctl enable ssl-reload.path
        systemctl start ssl-reload.path


        With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.



        if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.






        share|improve this answer














        Create /etc/systemd/system/ssl-reload.target with the following contents.



        [Unit]
        Description=Services which need reloaded with SSL certs are updated.
        PropagatesReloadTo=nginx postfix


        Then create another file: /etc/systemd/system/ssl-reload.path



        [Unit]
        Description=Restart services which use SSL when the cert directory changes

        [Path]
        PathChanged=/path/to/your/ssl/certs/dir

        [Install]
        WantedBy=multi-user.target


        Then:



        systemctl enable ssl-reload.path
        systemctl start ssl-reload.path


        With that said, after changing something in your SSL directory, the desired services should be reloaded automatically.



        if you don't want the automatic behavior, then don't use the .path file, and just issue systemctl reload ssl-reload.target manually after you change SSL files.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 27 at 17:14









        Unda

        1034




        1034










        answered Jan 3 '17 at 21:12









        Mark Stosberg

        3,6561023




        3,6561023



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f334471%2fhow-do-i-reload-a-group-of-systemd-services%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