Why `systemctl stop service` can't envoke the service?

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











up vote
1
down vote

favorite












vim /home/mytest.sh
rm -f /home/mytest/*


I want to write a service to execute the remove action.

My expections:
sudo systemctl stop mytest can delete files in /home/mytest
sudo systemctl start mytest do nothing.



Edit my service file.



sudo vim /etc/systemd/system/mytest.service
[Unit]
Description=delete file

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/mytest.sh

[Install]
WantedBy=multi-user.target


Enable it.



sudo systemctl enable mytest


Now i found a strange action for mytest service.



sudo systemctl start mytest can delete files in /home/mytest
sudo systemctl stop mytest do nothing.



Why?
Pleas give a explanation in detail.







share|improve this question























    up vote
    1
    down vote

    favorite












    vim /home/mytest.sh
    rm -f /home/mytest/*


    I want to write a service to execute the remove action.

    My expections:
    sudo systemctl stop mytest can delete files in /home/mytest
    sudo systemctl start mytest do nothing.



    Edit my service file.



    sudo vim /etc/systemd/system/mytest.service
    [Unit]
    Description=delete file

    [Service]
    Type=oneshot
    ExecStart=/bin/true
    ExecStop=/bin/bash /home/mytest.sh

    [Install]
    WantedBy=multi-user.target


    Enable it.



    sudo systemctl enable mytest


    Now i found a strange action for mytest service.



    sudo systemctl start mytest can delete files in /home/mytest
    sudo systemctl stop mytest do nothing.



    Why?
    Pleas give a explanation in detail.







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      vim /home/mytest.sh
      rm -f /home/mytest/*


      I want to write a service to execute the remove action.

      My expections:
      sudo systemctl stop mytest can delete files in /home/mytest
      sudo systemctl start mytest do nothing.



      Edit my service file.



      sudo vim /etc/systemd/system/mytest.service
      [Unit]
      Description=delete file

      [Service]
      Type=oneshot
      ExecStart=/bin/true
      ExecStop=/bin/bash /home/mytest.sh

      [Install]
      WantedBy=multi-user.target


      Enable it.



      sudo systemctl enable mytest


      Now i found a strange action for mytest service.



      sudo systemctl start mytest can delete files in /home/mytest
      sudo systemctl stop mytest do nothing.



      Why?
      Pleas give a explanation in detail.







      share|improve this question











      vim /home/mytest.sh
      rm -f /home/mytest/*


      I want to write a service to execute the remove action.

      My expections:
      sudo systemctl stop mytest can delete files in /home/mytest
      sudo systemctl start mytest do nothing.



      Edit my service file.



      sudo vim /etc/systemd/system/mytest.service
      [Unit]
      Description=delete file

      [Service]
      Type=oneshot
      ExecStart=/bin/true
      ExecStop=/bin/bash /home/mytest.sh

      [Install]
      WantedBy=multi-user.target


      Enable it.



      sudo systemctl enable mytest


      Now i found a strange action for mytest service.



      sudo systemctl start mytest can delete files in /home/mytest
      sudo systemctl stop mytest do nothing.



      Why?
      Pleas give a explanation in detail.









      share|improve this question










      share|improve this question




      share|improve this question









      asked Apr 29 at 13:28









      it_is_a_literature

      20532249




      20532249




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand what’s going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as you’ve declared it never becomes active, so its stop action will be run once its start action completes.



          To achieve what you’re after, you need a oneshot service which nevertheless becomes active:



          [Unit]
          Description=delete file

          [Service]
          Type=oneshot
          RemainAfterExit=yes
          ExecStop=/bin/bash /home/mytest.sh

          [Install]
          WantedBy=multi-user.target





          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%2f440728%2fwhy-systemctl-stop-service-cant-envoke-the-service%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
            2
            down vote



            accepted










            This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand what’s going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as you’ve declared it never becomes active, so its stop action will be run once its start action completes.



            To achieve what you’re after, you need a oneshot service which nevertheless becomes active:



            [Unit]
            Description=delete file

            [Service]
            Type=oneshot
            RemainAfterExit=yes
            ExecStop=/bin/bash /home/mytest.sh

            [Install]
            WantedBy=multi-user.target





            share|improve this answer

























              up vote
              2
              down vote



              accepted










              This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand what’s going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as you’ve declared it never becomes active, so its stop action will be run once its start action completes.



              To achieve what you’re after, you need a oneshot service which nevertheless becomes active:



              [Unit]
              Description=delete file

              [Service]
              Type=oneshot
              RemainAfterExit=yes
              ExecStop=/bin/bash /home/mytest.sh

              [Install]
              WantedBy=multi-user.target





              share|improve this answer























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand what’s going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as you’ve declared it never becomes active, so its stop action will be run once its start action completes.



                To achieve what you’re after, you need a oneshot service which nevertheless becomes active:



                [Unit]
                Description=delete file

                [Service]
                Type=oneshot
                RemainAfterExit=yes
                ExecStop=/bin/bash /home/mytest.sh

                [Install]
                WantedBy=multi-user.target





                share|improve this answer













                This is explained in detail in the systemd service documentation, but you pretty much need to read all of it to understand what’s going on. The most pertinent part in this case is example 3; from that, the reader can gather that a oneshot service as you’ve declared it never becomes active, so its stop action will be run once its start action completes.



                To achieve what you’re after, you need a oneshot service which nevertheless becomes active:



                [Unit]
                Description=delete file

                [Service]
                Type=oneshot
                RemainAfterExit=yes
                ExecStop=/bin/bash /home/mytest.sh

                [Install]
                WantedBy=multi-user.target






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Apr 29 at 13:58









                Stephen Kitt

                140k22302363




                140k22302363






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440728%2fwhy-systemctl-stop-service-cant-envoke-the-service%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)