2

I have activated the Developer Platform in Windows and installed Ubuntu VIA Windows Store which works fabulous! Only thing I need is when I "Activate" Ubuntu Apache2 and MySql does not autostart.

Is there a simple way to make this happen under this Platform? When I open Bash, I can just manually start the Services but Auto Start would be preferred. I have tried using a cron job but the services never started, perhaps my syntax was wrong?

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot . $HOME/.profile; /usr/sbin/sshd -D
@reboot . $HOME/.profile; service mysql start
@reboot . $HOME/.profile; service apache2 start

2 Answers2

7

Found It!!!!! Although not elegant.

Instead of looping or sleeping just add "bash" to the end of the shell script. Here are my scripts for apache and mysql to run on startup.

VBS file (runs on startup) Win + r shell:startup create autostart.vbs

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run "C:\Windows\System32\bash.exe -c ~/autostart.sh",0
Set WshShell = Nothing

autostart.sh file (Just make this in your Home Folder, chmod +x runnable)

#!/bin/bash
sudo service mysql start
sudo service apache2 start
bash

and in /etc/sudoers (Append to the end of the file)

# Allow apache2 and mysql to start without a sudo password
%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service apache2 *
%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service mysql *

If I need to kill it all I can find the bash process in Task Manager and kill that.

Credit: https://github.com/mstrelan

pa4080
  • 29,831
2

Found this article which uses a similar method with EODCraft's solution. But instead of using a VB script, this uses Windows "Task Scheduler" program to run the shell script at login.

RZKY
  • 131
  • 1
    While those links might answer the question, please include all relevant details in your answer directly, so that it still stays relevant even if the linked content gets (re)moved. You can still add the links as reference and for further reading. Thanks. – Byte Commander Aug 16 '19 at 10:30
  • Task Scheduler would work fine. A lot of Software Uses the Task Scheduler to Auto start. Just point to Bash and execute the script. it's actually pretty self-explanatory. – EODCraft Staff Aug 19 '19 at 12:01
  • The relevant steps from the proposed article are extracted here: https://askubuntu.com/a/1166012/566421 – pa4080 Aug 23 '19 at 08:41