DEV Community

Abhishek Sisodiya
Abhishek Sisodiya

Posted on • Edited on

1 1

Start mongodb/mysql services automatically in wsl2

  • First open a script using nano in your WSL terminal by running this command:
sudo nano ~/.local/bin/start_script
Enter fullscreen mode Exit fullscreen mode
  • Copy the following command in that scipt:
service mysql start
service mongodb start
Enter fullscreen mode Exit fullscreen mode

commands inside script

  • Press ctrl+o and then ctrl+x to save and exit the script.
  • Go to Windows start menu and type Task Scheduler to open Task Scheduler.
  • Under the Actions tab on the right hand side, click Create Task... to open create task window
  • On this window give your task a specific name and make sure Run only when user is logged on is selected as shown below. Task Name
  • Then click on Triggers tab and create a New Trigger by selecting Begin the Task At log on from the dropdown menu and under settings any user and select Enabled under Advanced Settings. Trigger
  • Then go to Actions Tab and create a New Action as Start a Program and under Settings set Program/Script as C:\Windows\System32\bash.exe and in the Add arguments -c "sudo ~/.local/bin/start_services.sh" as shown below. Actions

That's all. The next time Windows starts, task will be triggered and it will run your custom script as root and start mongodb and mysql. You can also add any other services to this script.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (1)

Collapse
 
vasudeveloper001 profile image
Saurabh Srivastava
  1. Difference in script file name: "start_script" and "start_services.sh".
  2. Doesn't work either; asks for the password rather than running in silent mode.

Have you tried this yourself?

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay