Answer the question
In order to leave comments, you need to log in
How to fix bash script to start all services when logging into WSL?
WSL v1 does not automatically start services at startup because there is no start itself. Instead, it is recommended to add the launch of the necessary services to the end of the ~/.bashrc file. This works, but is unsatisfactory: each login is delayed due to the start of all services, even when they are already running; duplicate lines are added to the file.
sudo service nginx start
sudo service php7.0-fpm start
sudo service php7.1-fpm start
sudo service php7.2-fpm start
sudo service php7.3-fpm start
sudo service mysql start
sudo service redis-server start
#!/bin/bash
# run custom services
services_list=("nginx", "mysql")
for i in "${services_list[@]}"
do
service_status=$(service $i status)
if ; then
sudo service $i --full-restart
fi
done
Answer the question
In order to leave comments, you need to log in
each login is delayed due to the start of all services, even when they are already running;
duplicate lines are added to the file.
#!/bin/bash
# run custom services
services_list="nginx mysql"
for svc in ${services_list}
do
service_status=$(service $svc status)
if ; then
sudo service $svc --full-restart
fi
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question