systemd: how to enable a service automatically from the first boot?

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











up vote
0
down vote

favorite












I am using systemd to handle some tasks and I have a service file which works fine once enabled with systemctl.



Now, I would like to enable it automatically from the first boot.



I know that putting a replacement file into /etc/systemd/system/ replaces the behavior of the file with the same name into /lib/systemd/system/.



There is a way to enable a service file automatically just to putting it in some directory ?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am using systemd to handle some tasks and I have a service file which works fine once enabled with systemctl.



    Now, I would like to enable it automatically from the first boot.



    I know that putting a replacement file into /etc/systemd/system/ replaces the behavior of the file with the same name into /lib/systemd/system/.



    There is a way to enable a service file automatically just to putting it in some directory ?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using systemd to handle some tasks and I have a service file which works fine once enabled with systemctl.



      Now, I would like to enable it automatically from the first boot.



      I know that putting a replacement file into /etc/systemd/system/ replaces the behavior of the file with the same name into /lib/systemd/system/.



      There is a way to enable a service file automatically just to putting it in some directory ?










      share|improve this question













      I am using systemd to handle some tasks and I have a service file which works fine once enabled with systemctl.



      Now, I would like to enable it automatically from the first boot.



      I know that putting a replacement file into /etc/systemd/system/ replaces the behavior of the file with the same name into /lib/systemd/system/.



      There is a way to enable a service file automatically just to putting it in some directory ?







      systemd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 28 '16 at 16:43









      simozz

      19912




      19912




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          sudo systemctl enable <service-name> will enable service at boot time.



          http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/ has a list of useful commands. And there's always man systemctl and man systemd.






          share|improve this answer
















          • 1




            Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
            – Mahn
            Jul 13 '16 at 0:45


















          up vote
          0
          down vote













          You could use systems.preset for default enabled units.



          Systems.preset allows to configure set of units to be enabled/disabled



          vendor preset in systemctl status unit refers to this.



          For more info how use this refer linked man page






          share|improve this answer



























            up vote
            0
            down vote














            IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get your closer to your goal.




            In most case, you want to install it in the multi-user.target using the install section as follow:



            [Install]
            WantedBy=multi-user.target


            This means the your-package.postinst script will automatically start the daemon for you.



            Note that if you have your own your-package.postinst script, you have to make sure to include the Debian helper as in:



            #!/bin/sh

            #DEBHELPER#

            ...your own script here...


            Without the #DEBHELPER# pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:



            systemctl enable <service-name>
            systemctl start <service-name>


            unless the service is static (does not have an [Install] section as shown above.) A static service requires a special command line to be enabled and that's not available by default:



            systemctl add-wants multi-user.target <service-name>


            As we can see, the command includes multi-user.target which the default #DEBHELPER# (systemd, really) has no clue about unless you have an [Install] section.



            The package must also be built with the systemd extension. This means having the following in your debian/rules file:



            %:
            dh $@ --with systemd --parallel


            That should get you set.






            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%2f258316%2fsystemd-how-to-enable-a-service-automatically-from-the-first-boot%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote













              sudo systemctl enable <service-name> will enable service at boot time.



              http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/ has a list of useful commands. And there's always man systemctl and man systemd.






              share|improve this answer
















              • 1




                Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
                – Mahn
                Jul 13 '16 at 0:45















              up vote
              1
              down vote













              sudo systemctl enable <service-name> will enable service at boot time.



              http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/ has a list of useful commands. And there's always man systemctl and man systemd.






              share|improve this answer
















              • 1




                Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
                – Mahn
                Jul 13 '16 at 0:45













              up vote
              1
              down vote










              up vote
              1
              down vote









              sudo systemctl enable <service-name> will enable service at boot time.



              http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/ has a list of useful commands. And there's always man systemctl and man systemd.






              share|improve this answer












              sudo systemctl enable <service-name> will enable service at boot time.



              http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/ has a list of useful commands. And there's always man systemctl and man systemd.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 28 '16 at 17:33









              Munir

              2,097419




              2,097419







              • 1




                Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
                – Mahn
                Jul 13 '16 at 0:45













              • 1




                Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
                – Mahn
                Jul 13 '16 at 0:45








              1




              1




              Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
              – Mahn
              Jul 13 '16 at 0:45





              Note that you need at least the statement WantedBy=multi-user.target under [Install] in the unit file for it to start on boot in addition to enabling it via systemctl, otherwise the enable command won't do anything.
              – Mahn
              Jul 13 '16 at 0:45













              up vote
              0
              down vote













              You could use systems.preset for default enabled units.



              Systems.preset allows to configure set of units to be enabled/disabled



              vendor preset in systemctl status unit refers to this.



              For more info how use this refer linked man page






              share|improve this answer
























                up vote
                0
                down vote













                You could use systems.preset for default enabled units.



                Systems.preset allows to configure set of units to be enabled/disabled



                vendor preset in systemctl status unit refers to this.



                For more info how use this refer linked man page






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You could use systems.preset for default enabled units.



                  Systems.preset allows to configure set of units to be enabled/disabled



                  vendor preset in systemctl status unit refers to this.



                  For more info how use this refer linked man page






                  share|improve this answer












                  You could use systems.preset for default enabled units.



                  Systems.preset allows to configure set of units to be enabled/disabled



                  vendor preset in systemctl status unit refers to this.



                  For more info how use this refer linked man page







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 14 '17 at 15:41









                  AbdulKareem

                  1011




                  1011




















                      up vote
                      0
                      down vote














                      IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get your closer to your goal.




                      In most case, you want to install it in the multi-user.target using the install section as follow:



                      [Install]
                      WantedBy=multi-user.target


                      This means the your-package.postinst script will automatically start the daemon for you.



                      Note that if you have your own your-package.postinst script, you have to make sure to include the Debian helper as in:



                      #!/bin/sh

                      #DEBHELPER#

                      ...your own script here...


                      Without the #DEBHELPER# pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:



                      systemctl enable <service-name>
                      systemctl start <service-name>


                      unless the service is static (does not have an [Install] section as shown above.) A static service requires a special command line to be enabled and that's not available by default:



                      systemctl add-wants multi-user.target <service-name>


                      As we can see, the command includes multi-user.target which the default #DEBHELPER# (systemd, really) has no clue about unless you have an [Install] section.



                      The package must also be built with the systemd extension. This means having the following in your debian/rules file:



                      %:
                      dh $@ --with systemd --parallel


                      That should get you set.






                      share|improve this answer
























                        up vote
                        0
                        down vote














                        IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get your closer to your goal.




                        In most case, you want to install it in the multi-user.target using the install section as follow:



                        [Install]
                        WantedBy=multi-user.target


                        This means the your-package.postinst script will automatically start the daemon for you.



                        Note that if you have your own your-package.postinst script, you have to make sure to include the Debian helper as in:



                        #!/bin/sh

                        #DEBHELPER#

                        ...your own script here...


                        Without the #DEBHELPER# pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:



                        systemctl enable <service-name>
                        systemctl start <service-name>


                        unless the service is static (does not have an [Install] section as shown above.) A static service requires a special command line to be enabled and that's not available by default:



                        systemctl add-wants multi-user.target <service-name>


                        As we can see, the command includes multi-user.target which the default #DEBHELPER# (systemd, really) has no clue about unless you have an [Install] section.



                        The package must also be built with the systemd extension. This means having the following in your debian/rules file:



                        %:
                        dh $@ --with systemd --parallel


                        That should get you set.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote










                          IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get your closer to your goal.




                          In most case, you want to install it in the multi-user.target using the install section as follow:



                          [Install]
                          WantedBy=multi-user.target


                          This means the your-package.postinst script will automatically start the daemon for you.



                          Note that if you have your own your-package.postinst script, you have to make sure to include the Debian helper as in:



                          #!/bin/sh

                          #DEBHELPER#

                          ...your own script here...


                          Without the #DEBHELPER# pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:



                          systemctl enable <service-name>
                          systemctl start <service-name>


                          unless the service is static (does not have an [Install] section as shown above.) A static service requires a special command line to be enabled and that's not available by default:



                          systemctl add-wants multi-user.target <service-name>


                          As we can see, the command includes multi-user.target which the default #DEBHELPER# (systemd, really) has no clue about unless you have an [Install] section.



                          The package must also be built with the systemd extension. This means having the following in your debian/rules file:



                          %:
                          dh $@ --with systemd --parallel


                          That should get you set.






                          share|improve this answer













                          IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get your closer to your goal.




                          In most case, you want to install it in the multi-user.target using the install section as follow:



                          [Install]
                          WantedBy=multi-user.target


                          This means the your-package.postinst script will automatically start the daemon for you.



                          Note that if you have your own your-package.postinst script, you have to make sure to include the Debian helper as in:



                          #!/bin/sh

                          #DEBHELPER#

                          ...your own script here...


                          Without the #DEBHELPER# pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:



                          systemctl enable <service-name>
                          systemctl start <service-name>


                          unless the service is static (does not have an [Install] section as shown above.) A static service requires a special command line to be enabled and that's not available by default:



                          systemctl add-wants multi-user.target <service-name>


                          As we can see, the command includes multi-user.target which the default #DEBHELPER# (systemd, really) has no clue about unless you have an [Install] section.



                          The package must also be built with the systemd extension. This means having the following in your debian/rules file:



                          %:
                          dh $@ --with systemd --parallel


                          That should get you set.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 23 at 18:44









                          Alexis Wilke

                          854614




                          854614



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f258316%2fsystemd-how-to-enable-a-service-automatically-from-the-first-boot%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