Skip to content

Commit 30b8230

Browse files
Attempt to dynamically get mysql service name
1 parent bbcf60d commit 30b8230

File tree

4 files changed

+34
-56
lines changed

4 files changed

+34
-56
lines changed

config/homebin/vagrant_provision

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ source /srv/provision/provision-helpers.sh
1616

1717
vvv_success " ▷ Post provision script"
1818

19+
mysql_service_name=$(vvv_get_mysql_service_name)
20+
1921
if [[ -f /srv/config/homebin/vagrant_provision_custom ]]; then
2022
vvv_info " * Custom vagrant provision script found, executing vagrant_provision_custom"
2123
/srv/config/homebin/vagrant_provision_custom
@@ -29,19 +31,11 @@ else
2931
fi
3032

3133
vvv_info " * Restarting MariaDB service"
32-
if [ ! -f /.dockerenv ]; then
33-
if sudo service mariadb status > /dev/null; then
34-
sudo service mariadb restart
35-
else
36-
sudo service mariadb start
37-
fi
38-
else
39-
if sudo service mysql status > /dev/null; then
40-
sudo service mysql restart
34+
if sudo service "${mysql_service_name[@]}" status > /dev/null; then
35+
sudo service "${mysql_service_name[@]}" restart
4136
else
42-
sudo service mysql start
37+
sudo service "${mysql_service_name[@]}" start
4338
fi
44-
fi
4539

4640
if [ ! -f /.dockerenv ]; then
4741
if [ -x "$(command -v ntpdate)" ]; then

config/homebin/vagrant_up

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ TEARS="${CYAN}░${RED}"
2222
EYE="${CYAN}${RED}"
2323
URL="\033[4;38;5;3m"
2424

25+
mysql_service_name=$(vvv_get_mysql_service_name)
26+
2527
if [[ -f /srv/config/homebin/vagrant_up_custom ]]; then
2628
vvv_info " * Custom vagrant up script found, executing vagrant_up_custom"
2729
/srv/config/homebin/vagrant_up_custom
@@ -39,13 +41,8 @@ fi
3941

4042

4143
vvv_info " * Starting MariaDB service"
42-
if [ ! -f /.dockerenv ]; then
43-
if ! sudo service mariadb status > /dev/null; then
44-
sudo service mariadb start
45-
fi
46-
else
47-
if ! sudo service mysql status > /dev/null; then
48-
sudo service mysql start
44+
if ! sudo service "${mysql_service_name[@]}" status > /dev/null; then
45+
sudo service "${mysql_service_name[@]}" start
4946
fi
5047
fi
5148

provision/core/mariadb/provision.sh

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,9 @@ function mysql_setup() {
126126

127127
# Due to systemd dependencies, in docker, mysql service is not auto started
128128
# also docker isn't systemd based, so thee service name is different: see: https://mariadb.com/kb/en/systemd/ vs https://mariadb.com/kb/en/sysvinit/
129+
mysql_service_name=$(vvv_get_mysql_service_name)
129130
vvv_info " * Ensuring MariaDB service is started"
130-
if [ ! -f /.dockerenv ]; then
131-
service mariadb status > /dev/null || service mariadb start
132-
else
133-
service mysql status > /dev/null || service mysql start
134-
fi
131+
service "${mysql_service_name[@]}" status > /dev/null || service "${mysql_service_name[@]}" start
135132

136133
if [ ! -f /.dockerenv ]; then
137134
check_mysql_root_password
@@ -140,40 +137,21 @@ function mysql_setup() {
140137
# MySQL gives us an error if we restart a non running service, which
141138
# happens after a `vagrant halt`. Check to see if it's running before
142139
# deciding whether to start or restart.
143-
if [ ! -f /.dockerenv ]; then
144-
if service mariadb status > /dev/null; then
145-
vvv_info " * Restarting the mariadb service"
146-
if ! service mariadb restart; then
147-
vvv_error " * Restarting the MariaDB failed! Fetching service status."
148-
service mariadb status
149-
exit 1
150-
fi
151-
else
152-
vvv_info " * Restarting mariadb service"
153-
service mariadb start
154-
if ! service mariadb start; then
155-
vvv_error " * Starting MariaDB failed! Fetching service status."
156-
service mariadb status
157-
exit 1
158-
fi
159-
fi
140+
if service "${mysql_service_name[@]}" status > /dev/null; then
141+
vvv_info " * Restarting the mariadb service"
142+
if ! service "${mysql_service_name[@]}" restart; then
143+
vvv_error " * Restarting the MariaDB failed! Fetching service status."
144+
service "${mysql_service_name[@]}" status
145+
exit 1
146+
fi
160147
else
161-
if service mysql status > /dev/null; then
162-
vvv_info " * Restarting the mariadb service"
163-
if ! service mysql restart; then
164-
vvv_error " * Restarting the MariaDB failed! Fetching service status."
165-
service mysql status
166-
exit 1
167-
fi
168-
else
169-
vvv_info " * Restarting mariadb service"
170-
service mysql start
171-
if ! service mysql start; then
172-
vvv_error " * Starting MariaDB failed! Fetching service status."
173-
service mysql status
174-
exit 1
175-
fi
176-
fi
148+
vvv_info " * Restarting mariadb service"
149+
service "${mysql_service_name[@]}" start
150+
if ! service "${mysql_service_name[@]}" start; then
151+
vvv_error " * Starting MariaDB failed! Fetching service status."
152+
service "${mysql_service_name[@]}" status
153+
exit 1
154+
fi
177155
fi
178156

179157
# IMPORT SQL

provision/provision-helpers.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,12 @@ function vvv_search_replace_in_file() {
732732
fi
733733
}
734734
export -f vvv_search_replace_in_file
735+
736+
# @description Uses service
737+
function vvv_get_mysql_service_name() {
738+
if [ ! -f /etc/init.d/mariadb ]; then
739+
echo "mariadb"
740+
fi
741+
echo "mysql"
742+
}
743+
export -f vvv_get_mysql_service_name

0 commit comments

Comments
 (0)