Coder Social home page Coder Social logo

wsl-autostart's Introduction

WSL Autostart

Support for starting the Linux services in Windows Subsystem for Linux (WSL) on Windows startup.

README | 中文文档

Table of Contents

Installation

  • Clone to any directory using the git command: (e.g C:\wsl-autostart)
git clone https://github.com/troytse/wsl-autostart
  • Add a startup item to the registry. run-regedit

  • Add a string item under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (e.g WSLAutostart) regedit-new-item

  • Set the path to the script (e.g C:\wsl-autostart\start.vbs) regedit-set-path

Usage

  • Modify /etc/sudoers in the WSL to specify the service commands calling on startup without a password.

  • For example,

    • for the distribution Ubuntu and other Debian derivates:

      %sudo ALL=NOPASSWD: /etc/init.d/cron
      %sudo ALL=NOPASSWD: /etc/init.d/ssh
      %sudo ALL=NOPASSWD: /etc/init.d/mysql
      %sudo ALL=NOPASSWD: /etc/init.d/apache2
      
    • for the distribution Opensuse:

      %users ALL=(ALL) NOPASSWD: /usr/sbin/cron
      
  • Modify commands.txt in the wsl-autostart directory to specify the service commands accordingly. For example,

    • for the distribution Ubuntu and other Debian derivates:

      /etc/init.d/cron
      /etc/init.d/ssh
      /etc/init.d/mysql
      /etc/init.d/apache2
    • for the distribution Opensuse:

      /usr/sbin/cron

Other methods

  • Using gpedit.msc, it is possible to define a program that runs when the computer starts

    Note that the configured program will run as the system user.

  • Using taskschd.msc, it is possible to schedule a task after the startup of the computer.

    You may configure which user will run the program, a delay before a run and a number of retries. the same taskschd.msc program will show a specific log regarding the execution of the task

See here how to avoid the UAC prompt. One option is:

  1. create an elevated shortcut by https://winaero.com/blog/create-elevated-shortcut-to-skip-uac-prompt-in-windows-10/ (or more conveniently by the Winaero Tweaker as pointed out at the end of these instruction) and
  2. put it into the startup folder %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

wsl-autostart's People

Contributors

konfekt avatar troytse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wsl-autostart's Issues

does this commands.txt support systemd?

does this commands.txt support systemd?
eg:
my systemd service is pm2-user.service
to start custom service:

sudo systemctl start pm2-user.service

the systemd conf file path:

/etc/systemd/system/pm2-user.service

content:

[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=user
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/go/bin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/user/.pm2
PIDFile=/home/user/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

how to set the commands.txt file for this?

README.md may include instructions to use windows admin tools instead of modifying registry

The README.md suggests an installation that modify the windows registry. Instead of that option, it is possible to configure Windows 10 to run a program when the computer starts using a startup policy or a scheduled task using administrative tools.

  • Using gpedit.msc, it is possible to define a program that run when the computer starts
    • Note that the configured program will run as the SYSTEMuser.
  • Using taskschd.msc, it is possible to schedule a task after the startup of the computer.
    • You may configure which user will run the program, a delay before run and a number of retries.
    • the same taskschd.msc program will show a specific log regarding the execution of the task

In addition, note that the scheduled task can be created programmatically using Powershell. An user may run a .ps1 script to installs the wsl-autostart as a scheduled task very easily.

Windows scheduler ubuntu autostart

I've added ubuntu2004.exe to Scheduler (after user login).
It starts fine. But I have a UAC popup:

Do you want to allow this app to make changes to your device?
C:\work\wsl-autostart\control.bat

How to fix this? I've seen a similar thread. But I think it addresses not control.bat but something else.

Switch from "wsl sudo" to "wsl -u root"

The wsl command lets you specify what "Linux" user will be used to run a command. Rather then setting up sudo, why not just use "wsl -u root" in your control.bat file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.