WSL Tips: Starting Linux Background Services on Windows Login

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

WSL Tips: Starting Linux Background Services on Windows Login

文章 yehlu »

https://dev.to/ironfroggy/wsl-tips-star ... login-3o98

代碼: 選擇全部

mkdir -p ~/.local/bin/
echo "service postgresql start" >> ~/.local/bin/start_postgresql.sh
chmod +x ~/.local/bin/start_postgresql.sh
sudo visudo

代碼: 選擇全部

calvin ALL=(root) NOPASSWD: /home/calvin/.local/bin/start_postgresql.sh


Now, click “Task Scheduler Library” on the left and then “Create Task…” on the right to create a new task you can configure to run your script with these steps:

Name the task anything you want, like “Start Postgres”
Under the “Triggers” tab, click “New…” to add a new trigger for this task
In the “Begin the task” dropdown select “At log on”
Select “Any user”
Under the “Actions” tab, click “New…” to add a new action for this task
Pick “Start a program” for the action type and then enter C:\Windows\System32\bash.exe as the program to run
Finally, as the last and most important step, at “Add arguments (optional)” set this argument string to run the command with: -c "sudo ~/.local/bin/start_postgresql.sh"
回覆文章

回到「10」