Skip to content

Commit

Permalink
Attempt to dynamically get mysql service name
Browse files Browse the repository at this point in the history
  • Loading branch information
pentatonicfunk committed Oct 19, 2024
1 parent bbcf60d commit 30b8230
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 56 deletions.
16 changes: 5 additions & 11 deletions config/homebin/vagrant_provision
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ source /srv/provision/provision-helpers.sh

vvv_success " ▷ Post provision script"

mysql_service_name=$(vvv_get_mysql_service_name)

if [[ -f /srv/config/homebin/vagrant_provision_custom ]]; then
vvv_info " * Custom vagrant provision script found, executing vagrant_provision_custom"
/srv/config/homebin/vagrant_provision_custom
Expand All @@ -29,19 +31,11 @@ else
fi

vvv_info " * Restarting MariaDB service"
if [ ! -f /.dockerenv ]; then
if sudo service mariadb status > /dev/null; then
sudo service mariadb restart
else
sudo service mariadb start
fi
else
if sudo service mysql status > /dev/null; then
sudo service mysql restart
if sudo service "${mysql_service_name[@]}" status > /dev/null; then
sudo service "${mysql_service_name[@]}" restart
else
sudo service mysql start
sudo service "${mysql_service_name[@]}" start
fi
fi

if [ ! -f /.dockerenv ]; then
if [ -x "$(command -v ntpdate)" ]; then
Expand Down
11 changes: 4 additions & 7 deletions config/homebin/vagrant_up
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ TEARS="${CYAN}░${RED}"
EYE="${CYAN}${RED}"
URL="\033[4;38;5;3m"

mysql_service_name=$(vvv_get_mysql_service_name)

if [[ -f /srv/config/homebin/vagrant_up_custom ]]; then
vvv_info " * Custom vagrant up script found, executing vagrant_up_custom"
/srv/config/homebin/vagrant_up_custom
Expand All @@ -39,13 +41,8 @@ fi


vvv_info " * Starting MariaDB service"
if [ ! -f /.dockerenv ]; then
if ! sudo service mariadb status > /dev/null; then
sudo service mariadb start
fi
else
if ! sudo service mysql status > /dev/null; then
sudo service mysql start
if ! sudo service "${mysql_service_name[@]}" status > /dev/null; then
sudo service "${mysql_service_name[@]}" start
fi
fi

Expand Down
54 changes: 16 additions & 38 deletions provision/core/mariadb/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,9 @@ function mysql_setup() {

# Due to systemd dependencies, in docker, mysql service is not auto started
# 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/
mysql_service_name=$(vvv_get_mysql_service_name)
vvv_info " * Ensuring MariaDB service is started"
if [ ! -f /.dockerenv ]; then
service mariadb status > /dev/null || service mariadb start
else
service mysql status > /dev/null || service mysql start
fi
service "${mysql_service_name[@]}" status > /dev/null || service "${mysql_service_name[@]}" start

if [ ! -f /.dockerenv ]; then
check_mysql_root_password
Expand All @@ -140,40 +137,21 @@ function mysql_setup() {
# MySQL gives us an error if we restart a non running service, which
# happens after a `vagrant halt`. Check to see if it's running before
# deciding whether to start or restart.
if [ ! -f /.dockerenv ]; then
if service mariadb status > /dev/null; then
vvv_info " * Restarting the mariadb service"
if ! service mariadb restart; then
vvv_error " * Restarting the MariaDB failed! Fetching service status."
service mariadb status
exit 1
fi
else
vvv_info " * Restarting mariadb service"
service mariadb start
if ! service mariadb start; then
vvv_error " * Starting MariaDB failed! Fetching service status."
service mariadb status
exit 1
fi
fi
if service "${mysql_service_name[@]}" status > /dev/null; then
vvv_info " * Restarting the mariadb service"
if ! service "${mysql_service_name[@]}" restart; then
vvv_error " * Restarting the MariaDB failed! Fetching service status."
service "${mysql_service_name[@]}" status
exit 1
fi
else
if service mysql status > /dev/null; then
vvv_info " * Restarting the mariadb service"
if ! service mysql restart; then
vvv_error " * Restarting the MariaDB failed! Fetching service status."
service mysql status
exit 1
fi
else
vvv_info " * Restarting mariadb service"
service mysql start
if ! service mysql start; then
vvv_error " * Starting MariaDB failed! Fetching service status."
service mysql status
exit 1
fi
fi
vvv_info " * Restarting mariadb service"
service "${mysql_service_name[@]}" start
if ! service "${mysql_service_name[@]}" start; then
vvv_error " * Starting MariaDB failed! Fetching service status."
service "${mysql_service_name[@]}" status
exit 1
fi
fi

# IMPORT SQL
Expand Down
9 changes: 9 additions & 0 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,12 @@ function vvv_search_replace_in_file() {
fi
}
export -f vvv_search_replace_in_file

# @description Uses service
function vvv_get_mysql_service_name() {
if [ ! -f /etc/init.d/mariadb ]; then
echo "mariadb"
fi
echo "mysql"
}
export -f vvv_get_mysql_service_name

0 comments on commit 30b8230

Please sign in to comment.