How to stop all units belonging to the same target?Where is / why is there no log for normal user systemd...

Suffocation while cooking under an umbrella?

Help in drawing resonance structures in case of polybasic acids

What would influence an alien race to map their planet in a way other than the traditional map of the Earth

Difference between types of yeast

Iterating over &Vec<T> and Vec<&T>

Beyond Futuristic Technology for an Alien Warship?

Top off gas with old oil, is that bad?

A food item only made possible by time-freezing storage?

Convex hull in a discrete space

How can I indicate the first and the last reference number written in a page of the bibliography in the header of the page?

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

Does "as soon as" imply simultaneity?

Two side-by-side squares are inscribed in a semicircle. The diameter of the semicircle is 16. What is the sum of the two squares' areas?

Number of list elements less than a given integer

Why does (inf + 0j)*1 evaluate to inf + nanj?

What happens to a net with the Returning Weapon artificer infusion after it hits?

Is differentiation as a map discontinuous?

Reorder a matrix, twice

Youtube not blocked by iptables

Subverting the emotional woman and stoic man trope

Another student has been assigned the same MSc thesis as mine (and already defended)

How can this Stack Exchange site have an animated favicon?

A famous scholar sent me an unpublished draft of hers. Then she died. I think her work should be published. What should I do?

Algorithm that generates orthogonal vectors: C++ implementation



How to stop all units belonging to the same target?


Where is / why is there no log for normal user systemd services?How to create a virtual systemd service to stop/start several instances together?How systemd Type option affects starting other units?Instruct to execute an unit after completing another unit successfullysystemd: finish the execution of custom shell script before starting nginxshut down system when multiple systemd units stopHow do I apply the changes from systemctl preset-all automatically without a rebootStopping systemd unit together with another. Starting worksRestricting systemd units to specific host based on DNS alias?Systemd Unit File - WantedBy and After






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







7















I'm wondering how to stop all units that are grouped together by the same target.



My setup is as follows. I have several unit config files that read:



[Unit]
...

[Service]
...

[Install]
WantedBy=mycustom.target


When I run



# systemctl start mycustom.target


Those units that "are wanted by" mycustom.target start correctly. Now, I would also like to be able stop all units that are wanted by mycustom.target. I tried:



# systemctl stop mycustom.target


This doesn't do anything though. Is there a way to make this work without having to stop all units that are (explicitly) wanted by the same target?










share|improve this question

































    7















    I'm wondering how to stop all units that are grouped together by the same target.



    My setup is as follows. I have several unit config files that read:



    [Unit]
    ...

    [Service]
    ...

    [Install]
    WantedBy=mycustom.target


    When I run



    # systemctl start mycustom.target


    Those units that "are wanted by" mycustom.target start correctly. Now, I would also like to be able stop all units that are wanted by mycustom.target. I tried:



    # systemctl stop mycustom.target


    This doesn't do anything though. Is there a way to make this work without having to stop all units that are (explicitly) wanted by the same target?










    share|improve this question





























      7












      7








      7


      3






      I'm wondering how to stop all units that are grouped together by the same target.



      My setup is as follows. I have several unit config files that read:



      [Unit]
      ...

      [Service]
      ...

      [Install]
      WantedBy=mycustom.target


      When I run



      # systemctl start mycustom.target


      Those units that "are wanted by" mycustom.target start correctly. Now, I would also like to be able stop all units that are wanted by mycustom.target. I tried:



      # systemctl stop mycustom.target


      This doesn't do anything though. Is there a way to make this work without having to stop all units that are (explicitly) wanted by the same target?










      share|improve this question
















      I'm wondering how to stop all units that are grouped together by the same target.



      My setup is as follows. I have several unit config files that read:



      [Unit]
      ...

      [Service]
      ...

      [Install]
      WantedBy=mycustom.target


      When I run



      # systemctl start mycustom.target


      Those units that "are wanted by" mycustom.target start correctly. Now, I would also like to be able stop all units that are wanted by mycustom.target. I tried:



      # systemctl stop mycustom.target


      This doesn't do anything though. Is there a way to make this work without having to stop all units that are (explicitly) wanted by the same target?







      systemd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 26 '15 at 16:14









      Braiam

      24.8k20 gold badges82 silver badges147 bronze badges




      24.8k20 gold badges82 silver badges147 bronze badges










      asked Jun 26 '15 at 16:00









      KrisKris

      1381 silver badge6 bronze badges




      1381 silver badge6 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          8
















          Edit: the PartOf= directive, which did not exist at the time of writing this answer, is a better solution. See another answer for details.



          There are two ways: an implicit and an explicit.



          First way — StopWhenUnneeded=



          The first way is to use the StopWhenUnneeded= directive. If a unit has StopWhenUnneeded=yes, it will be automatically stopped when there becomes no active unit which Wants=/Requires= the unit in question. Hence:




          • this will only work if these units are WantedBy= only by mycustom.target;

          • you will be unable to start any of these units manually (i. e. systemctl start myunit.service will start it and immediately stop it afterwards).


          Second way — a shell pipeline



          The second way is to construct a simple shell pipeline, using systemctl show -p to extract the dependency list of mycustom.target.



          More specifically, systemctl show UNIT will show all properties of a unit in a KEY=VALUE form, and systemctl show -p PROPERTIES UNIT will do the same, limiting the set of shown properties. So:



          systemctl stop -- $(systemctl show -p Wants mycustom.target | cut -d= -f2)





          share|improve this answer



































            22
















            Use the PartOf= directive.




            Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.




            PartOf=mycustom.target






            share|improve this answer





















            • 1





              Should I combine it with StopWhenUnneeded or is it implied?

              – PSSGCSim
              Nov 1 '17 at 6:56











            • It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

              – Gary van der Merwe
              Oct 2 '18 at 13:26














            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f212438%2fhow-to-stop-all-units-belonging-to-the-same-target%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            8
















            Edit: the PartOf= directive, which did not exist at the time of writing this answer, is a better solution. See another answer for details.



            There are two ways: an implicit and an explicit.



            First way — StopWhenUnneeded=



            The first way is to use the StopWhenUnneeded= directive. If a unit has StopWhenUnneeded=yes, it will be automatically stopped when there becomes no active unit which Wants=/Requires= the unit in question. Hence:




            • this will only work if these units are WantedBy= only by mycustom.target;

            • you will be unable to start any of these units manually (i. e. systemctl start myunit.service will start it and immediately stop it afterwards).


            Second way — a shell pipeline



            The second way is to construct a simple shell pipeline, using systemctl show -p to extract the dependency list of mycustom.target.



            More specifically, systemctl show UNIT will show all properties of a unit in a KEY=VALUE form, and systemctl show -p PROPERTIES UNIT will do the same, limiting the set of shown properties. So:



            systemctl stop -- $(systemctl show -p Wants mycustom.target | cut -d= -f2)





            share|improve this answer
































              8
















              Edit: the PartOf= directive, which did not exist at the time of writing this answer, is a better solution. See another answer for details.



              There are two ways: an implicit and an explicit.



              First way — StopWhenUnneeded=



              The first way is to use the StopWhenUnneeded= directive. If a unit has StopWhenUnneeded=yes, it will be automatically stopped when there becomes no active unit which Wants=/Requires= the unit in question. Hence:




              • this will only work if these units are WantedBy= only by mycustom.target;

              • you will be unable to start any of these units manually (i. e. systemctl start myunit.service will start it and immediately stop it afterwards).


              Second way — a shell pipeline



              The second way is to construct a simple shell pipeline, using systemctl show -p to extract the dependency list of mycustom.target.



              More specifically, systemctl show UNIT will show all properties of a unit in a KEY=VALUE form, and systemctl show -p PROPERTIES UNIT will do the same, limiting the set of shown properties. So:



              systemctl stop -- $(systemctl show -p Wants mycustom.target | cut -d= -f2)





              share|improve this answer






























                8














                8










                8









                Edit: the PartOf= directive, which did not exist at the time of writing this answer, is a better solution. See another answer for details.



                There are two ways: an implicit and an explicit.



                First way — StopWhenUnneeded=



                The first way is to use the StopWhenUnneeded= directive. If a unit has StopWhenUnneeded=yes, it will be automatically stopped when there becomes no active unit which Wants=/Requires= the unit in question. Hence:




                • this will only work if these units are WantedBy= only by mycustom.target;

                • you will be unable to start any of these units manually (i. e. systemctl start myunit.service will start it and immediately stop it afterwards).


                Second way — a shell pipeline



                The second way is to construct a simple shell pipeline, using systemctl show -p to extract the dependency list of mycustom.target.



                More specifically, systemctl show UNIT will show all properties of a unit in a KEY=VALUE form, and systemctl show -p PROPERTIES UNIT will do the same, limiting the set of shown properties. So:



                systemctl stop -- $(systemctl show -p Wants mycustom.target | cut -d= -f2)





                share|improve this answer















                Edit: the PartOf= directive, which did not exist at the time of writing this answer, is a better solution. See another answer for details.



                There are two ways: an implicit and an explicit.



                First way — StopWhenUnneeded=



                The first way is to use the StopWhenUnneeded= directive. If a unit has StopWhenUnneeded=yes, it will be automatically stopped when there becomes no active unit which Wants=/Requires= the unit in question. Hence:




                • this will only work if these units are WantedBy= only by mycustom.target;

                • you will be unable to start any of these units manually (i. e. systemctl start myunit.service will start it and immediately stop it afterwards).


                Second way — a shell pipeline



                The second way is to construct a simple shell pipeline, using systemctl show -p to extract the dependency list of mycustom.target.



                More specifically, systemctl show UNIT will show all properties of a unit in a KEY=VALUE form, and systemctl show -p PROPERTIES UNIT will do the same, limiting the set of shown properties. So:



                systemctl stop -- $(systemctl show -p Wants mycustom.target | cut -d= -f2)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 32 mins ago

























                answered Jun 29 '15 at 14:09









                intelfxintelfx

                3,45816 silver badges30 bronze badges




                3,45816 silver badges30 bronze badges




























                    22
















                    Use the PartOf= directive.




                    Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.




                    PartOf=mycustom.target






                    share|improve this answer





















                    • 1





                      Should I combine it with StopWhenUnneeded or is it implied?

                      – PSSGCSim
                      Nov 1 '17 at 6:56











                    • It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                      – Gary van der Merwe
                      Oct 2 '18 at 13:26
















                    22
















                    Use the PartOf= directive.




                    Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.




                    PartOf=mycustom.target






                    share|improve this answer





















                    • 1





                      Should I combine it with StopWhenUnneeded or is it implied?

                      – PSSGCSim
                      Nov 1 '17 at 6:56











                    • It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                      – Gary van der Merwe
                      Oct 2 '18 at 13:26














                    22














                    22










                    22









                    Use the PartOf= directive.




                    Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.




                    PartOf=mycustom.target






                    share|improve this answer













                    Use the PartOf= directive.




                    Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.




                    PartOf=mycustom.target







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 29 '16 at 14:41









                    betonimigbetonimig

                    3202 silver badges4 bronze badges




                    3202 silver badges4 bronze badges











                    • 1





                      Should I combine it with StopWhenUnneeded or is it implied?

                      – PSSGCSim
                      Nov 1 '17 at 6:56











                    • It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                      – Gary van der Merwe
                      Oct 2 '18 at 13:26














                    • 1





                      Should I combine it with StopWhenUnneeded or is it implied?

                      – PSSGCSim
                      Nov 1 '17 at 6:56











                    • It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                      – Gary van der Merwe
                      Oct 2 '18 at 13:26








                    1




                    1





                    Should I combine it with StopWhenUnneeded or is it implied?

                    – PSSGCSim
                    Nov 1 '17 at 6:56





                    Should I combine it with StopWhenUnneeded or is it implied?

                    – PSSGCSim
                    Nov 1 '17 at 6:56













                    It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                    – Gary van der Merwe
                    Oct 2 '18 at 13:26





                    It seems that StopWhenUnneeded is not necessary when using PartOf. @PSSGCSim

                    – Gary van der Merwe
                    Oct 2 '18 at 13:26



















                    draft saved

                    draft discarded



















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f212438%2fhow-to-stop-all-units-belonging-to-the-same-target%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...