How to run init.d scripts on Windows WSL?












1















Windows Subsystem for Linux, as of May 2018 still doesn't support init.d or systemd service management, and I ran into issues with services and several options online, with non working optimally for all cases










share|improve this question

























  • Is there a reason why you can't create a Windows service for them?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:42











  • @IgnacioVazquez-Abrams can you please provide an explanation to how that works?

    – Olubodun Agbalaya
    May 26 '18 at 13:45











  • As to how services on Windows work?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:46











  • As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

    – Olubodun Agbalaya
    May 26 '18 at 13:52


















1















Windows Subsystem for Linux, as of May 2018 still doesn't support init.d or systemd service management, and I ran into issues with services and several options online, with non working optimally for all cases










share|improve this question

























  • Is there a reason why you can't create a Windows service for them?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:42











  • @IgnacioVazquez-Abrams can you please provide an explanation to how that works?

    – Olubodun Agbalaya
    May 26 '18 at 13:45











  • As to how services on Windows work?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:46











  • As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

    – Olubodun Agbalaya
    May 26 '18 at 13:52
















1












1








1








Windows Subsystem for Linux, as of May 2018 still doesn't support init.d or systemd service management, and I ran into issues with services and several options online, with non working optimally for all cases










share|improve this question
















Windows Subsystem for Linux, as of May 2018 still doesn't support init.d or systemd service management, and I ran into issues with services and several options online, with non working optimally for all cases







windows-subsystem-for-linux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 26 '18 at 14:03









Anaksunaman

5,23821222




5,23821222










asked May 26 '18 at 13:40









Olubodun AgbalayaOlubodun Agbalaya

363




363













  • Is there a reason why you can't create a Windows service for them?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:42











  • @IgnacioVazquez-Abrams can you please provide an explanation to how that works?

    – Olubodun Agbalaya
    May 26 '18 at 13:45











  • As to how services on Windows work?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:46











  • As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

    – Olubodun Agbalaya
    May 26 '18 at 13:52





















  • Is there a reason why you can't create a Windows service for them?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:42











  • @IgnacioVazquez-Abrams can you please provide an explanation to how that works?

    – Olubodun Agbalaya
    May 26 '18 at 13:45











  • As to how services on Windows work?

    – Ignacio Vazquez-Abrams
    May 26 '18 at 13:46











  • As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

    – Olubodun Agbalaya
    May 26 '18 at 13:52



















Is there a reason why you can't create a Windows service for them?

– Ignacio Vazquez-Abrams
May 26 '18 at 13:42





Is there a reason why you can't create a Windows service for them?

– Ignacio Vazquez-Abrams
May 26 '18 at 13:42













@IgnacioVazquez-Abrams can you please provide an explanation to how that works?

– Olubodun Agbalaya
May 26 '18 at 13:45





@IgnacioVazquez-Abrams can you please provide an explanation to how that works?

– Olubodun Agbalaya
May 26 '18 at 13:45













As to how services on Windows work?

– Ignacio Vazquez-Abrams
May 26 '18 at 13:46





As to how services on Windows work?

– Ignacio Vazquez-Abrams
May 26 '18 at 13:46













As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

– Olubodun Agbalaya
May 26 '18 at 13:52







As to how to create a service to run a Linux service/start up script from windows @IgnacioVazquez-Abrams

– Olubodun Agbalaya
May 26 '18 at 13:52












2 Answers
2






active

oldest

votes


















1














The following bash script works for me.. Note the continue operator is needed to skip scripts that fail, and the start argument is needed by most service scripts.. i believe



for f in /etc/init.d/*; do sh "$f" start || continue; done ;





share|improve this answer































    0














    This is just a general direction (it is how I did it) - maybe someone can improve the idea.



    Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security



    Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon
    Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon



    If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)



    Program/script: C:WindowsSystem32wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)



    On the linux side create .sh file to start your service within Linux (this is how I did it):



    create apache.sh and put it into /usr/bin/



    My apache.sh looks like:



    #!/bin/sh 
    sudo service apache2 start


    If your script requires linux authentication you can use



    ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.



    For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support



    This seems like nice automated hussle free method (at least to me)






    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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/3.0/"u003ecc by-sa 3.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%2fsuperuser.com%2fquestions%2f1326169%2fhow-to-run-init-d-scripts-on-windows-wsl%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









      1














      The following bash script works for me.. Note the continue operator is needed to skip scripts that fail, and the start argument is needed by most service scripts.. i believe



      for f in /etc/init.d/*; do sh "$f" start || continue; done ;





      share|improve this answer




























        1














        The following bash script works for me.. Note the continue operator is needed to skip scripts that fail, and the start argument is needed by most service scripts.. i believe



        for f in /etc/init.d/*; do sh "$f" start || continue; done ;





        share|improve this answer


























          1












          1








          1







          The following bash script works for me.. Note the continue operator is needed to skip scripts that fail, and the start argument is needed by most service scripts.. i believe



          for f in /etc/init.d/*; do sh "$f" start || continue; done ;





          share|improve this answer













          The following bash script works for me.. Note the continue operator is needed to skip scripts that fail, and the start argument is needed by most service scripts.. i believe



          for f in /etc/init.d/*; do sh "$f" start || continue; done ;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 26 '18 at 13:44









          Olubodun AgbalayaOlubodun Agbalaya

          363




          363

























              0














              This is just a general direction (it is how I did it) - maybe someone can improve the idea.



              Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security



              Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon
              Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon



              If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)



              Program/script: C:WindowsSystem32wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)



              On the linux side create .sh file to start your service within Linux (this is how I did it):



              create apache.sh and put it into /usr/bin/



              My apache.sh looks like:



              #!/bin/sh 
              sudo service apache2 start


              If your script requires linux authentication you can use



              ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.



              For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support



              This seems like nice automated hussle free method (at least to me)






              share|improve this answer






























                0














                This is just a general direction (it is how I did it) - maybe someone can improve the idea.



                Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security



                Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon
                Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon



                If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)



                Program/script: C:WindowsSystem32wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)



                On the linux side create .sh file to start your service within Linux (this is how I did it):



                create apache.sh and put it into /usr/bin/



                My apache.sh looks like:



                #!/bin/sh 
                sudo service apache2 start


                If your script requires linux authentication you can use



                ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.



                For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support



                This seems like nice automated hussle free method (at least to me)






                share|improve this answer




























                  0












                  0








                  0







                  This is just a general direction (it is how I did it) - maybe someone can improve the idea.



                  Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security



                  Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon
                  Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon



                  If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)



                  Program/script: C:WindowsSystem32wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)



                  On the linux side create .sh file to start your service within Linux (this is how I did it):



                  create apache.sh and put it into /usr/bin/



                  My apache.sh looks like:



                  #!/bin/sh 
                  sudo service apache2 start


                  If your script requires linux authentication you can use



                  ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.



                  For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support



                  This seems like nice automated hussle free method (at least to me)






                  share|improve this answer















                  This is just a general direction (it is how I did it) - maybe someone can improve the idea.



                  Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security



                  Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon
                  Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon



                  If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)



                  Program/script: C:WindowsSystem32wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)



                  On the linux side create .sh file to start your service within Linux (this is how I did it):



                  create apache.sh and put it into /usr/bin/



                  My apache.sh looks like:



                  #!/bin/sh 
                  sudo service apache2 start


                  If your script requires linux authentication you can use



                  ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.



                  For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support



                  This seems like nice automated hussle free method (at least to me)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 13 at 13:12

























                  answered Jan 13 at 13:04









                  MishaMisha

                  11




                  11






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • 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%2fsuperuser.com%2fquestions%2f1326169%2fhow-to-run-init-d-scripts-on-windows-wsl%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

                      Probability when a professor distributes a quiz and homework assignment to a class of n students.

                      Aardman Animations

                      Are they similar matrix