diff --git a/.gitignore b/.gitignore index df4ef460a..a70dc53bf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ Icon\r\r # Because this really is a working directory, ignore vagrant's files /.vagrant +vagrant.log # This is a file intended for hooking in a custom Vagrant configuration on up /Customfile diff --git a/CHANGELOG.md b/CHANGELOG.md index 769588c9a..298d2156f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,13 @@ permalink: /docs/en-US/changelog/ ### Enhancements * Upgraded MariaDB from 10.5 to 10.11 ( #2728 ) +* Only start services that aren't running in post-up scripts ( #2732 ) ### Bug Fixes * VVV will check if Parallels is installed before defaulting to docker on Arm64/Apple Silicon due to issues with Docker detection ( #2722 ) * Switched from Rackspace to Starburst services for MariaDB mirrors ( #2728 ) +* Fixes for service starts under some situations in Docker ( #2732 ) * Fixed an issue with trailing slashes and site provisioners introduced in an earlier version (#2731) ### Maintenance diff --git a/config/homebin/db_backup b/config/homebin/db_backup index 92669d485..a7244f364 100755 --- a/config/homebin/db_backup +++ b/config/homebin/db_backup @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Create individual SQL files for each database. These files # are imported automatically during an initial provision if @@ -10,7 +10,7 @@ if [ -z "${VVV_LOG+x}" ]; then export VVV_LOG="" fi -trap 'rm -rf $TMPFIFODIR' EXIT; TMPFIFODIR=$(mktemp -d); mkfifo $TMPFIFODIR/dbnames +trap 'rm -rf $TMPFIFODIR' EXIT; TMPFIFODIR=$(mktemp -d); mkfifo "${TMPFIFODIR}/dbnames" source /srv/provision/provision-helpers.sh @@ -21,7 +21,7 @@ gzip=$(get_config_value "general.db_backup.gzip") exclude_list=$(get_config_values "general.db_backup.exclude") vvv_info " * Fetching Database names" -mysql -e 'show databases' | grep -v -F "Database" > $TMPFIFODIR/dbnames & +mysql -e 'show databases' | grep -v -F "Database" > "${TMPFIFODIR}/dbnames" & while read db_name; do # skip these databases [ "${db_name}" == "mysql" ] && vvv_info " - skipped ${db_name}" && continue; @@ -32,7 +32,7 @@ while read db_name; do [ "${db_name}" == "wordpress_unit_tests" ] && vvv_info " - skipped ${db_name}" && continue; skip="false" - for exclude in ${exclude_list[@]}; do + for exclude in "${exclude_list[@]}"; do if [ "${exclude}" == "${db_name}" ]; then skip="true" fi @@ -51,7 +51,7 @@ while read db_name; do fi fi databases+=( "${db_name}" ) -done < $TMPFIFODIR/dbnames +done < "${TMPFIFODIR}/dbnames" ext=".sql" if [[ "${gzip}" == "True" ]]; then @@ -67,7 +67,7 @@ do else mysqldump "${db}" > "/srv/database/backups/${db}.sql"; fi - let "count=count+1" + count=$((count+1)) done vvv_success " * Finished backing up databases to the database/sql/backups folder" diff --git a/config/homebin/db_restore b/config/homebin/db_restore index 0b969cd70..713a2d4d0 100755 --- a/config/homebin/db_restore +++ b/config/homebin/db_restore @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Restore individual SQL files for each database. . /srv/database/import-sql.sh diff --git a/config/homebin/is_utility_installed b/config/homebin/is_utility_installed index a131fa433..a6be9fc7b 100755 --- a/config/homebin/is_utility_installed +++ b/config/homebin/is_utility_installed @@ -1,8 +1,8 @@ -#!/bin/bash +#!/usr/bin/env bash utilities=$(shyaml get-values "utilities.${1}" 2> /dev/null < "${VVV_CONFIG}") for utility in ${utilities}; do if [[ "${utility}" == "${2}" ]]; then - exit 0 + exit 0 fi done exit 1 diff --git a/config/homebin/makepot b/config/homebin/makepot index 7b9361b17..b113385de 100755 --- a/config/homebin/makepot +++ b/config/homebin/makepot @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # Convenience script to run makepot.php php /srv/www/wordpress-develop/tools/i18n/makepot.php $1 $2 $3 $4 diff --git a/config/homebin/tideways_off b/config/homebin/tideways_off index bf7ce5c5c..35606cf4e 100755 --- a/config/homebin/tideways_off +++ b/config/homebin/tideways_off @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash switch_php_debugmod none diff --git a/config/homebin/tideways_on b/config/homebin/tideways_on index 88e0d8535..e2ebc0848 100755 --- a/config/homebin/tideways_on +++ b/config/homebin/tideways_on @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash switch_php_debugmod tideways diff --git a/config/homebin/vagrant b/config/homebin/vagrant index 6cf4d405b..f851b178a 100755 --- a/config/homebin/vagrant +++ b/config/homebin/vagrant @@ -12,4 +12,4 @@ echo -e "${YELLOW} █░░█░░░░░░▄▀ ${CRESET}" echo -e "${YELLOW}──────────────────────${CRESET}" echo "" echo -e "${PURPLE} ! You're still SSH'd into the VVV virtual machine!${CRESET}" -echo -e "${PURPLE} Run exit and try again${CRESET}" \ No newline at end of file +echo -e "${PURPLE} Run exit and try again${CRESET}" diff --git a/config/homebin/vagrant_destroy b/config/homebin/vagrant_destroy index 8174ee99f..a59152964 100755 --- a/config/homebin/vagrant_destroy +++ b/config/homebin/vagrant_destroy @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # This script is run whenever `vagrant destroy` is used to destroy # the virtual machine. To customize this behavior, include a file @@ -18,9 +18,9 @@ else fi # Check if backups are turned on or off - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable) if [[ -z "$run_backups" ]]; then - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup) fi if [[ $run_backups != "False" ]]; then diff --git a/config/homebin/vagrant_halt b/config/homebin/vagrant_halt index ec4241d0b..7d3940cff 100755 --- a/config/homebin/vagrant_halt +++ b/config/homebin/vagrant_halt @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # This script is run whenever `vagrant halt` is used to power off # the virtual machine. To customize this behavior, include a file @@ -18,9 +18,9 @@ else fi # Check if backups are turned on or off - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable) if [[ -z "$run_backups" ]]; then - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup) fi if [[ $run_backups != "False" ]]; then diff --git a/config/homebin/vagrant_provision b/config/homebin/vagrant_provision index 84903f1c0..aab0cde51 100755 --- a/config/homebin/vagrant_provision +++ b/config/homebin/vagrant_provision @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # This script is run after a provision. To customize this behavior, # include a file in your local VVV/config/homebin @@ -22,10 +22,18 @@ if [[ -f /srv/config/homebin/vagrant_provision_custom ]]; then fi vvv_info " * Restarting Nginx service" -sudo service nginx restart +if sudo service nginx status > /dev/null; then + sudo service nginx restart +else + sudo service nginx start +fi vvv_info " * Restarting MariaDB service" -sudo service mariadb restart +if sudo service mariadb status > /dev/null; then + sudo service mariadb restart +else + sudo service mariadb start +fi if [ ! -f /.dockerenv ]; then if [ -x "$(command -v ntpdate)" ]; then diff --git a/config/homebin/vagrant_suspend b/config/homebin/vagrant_suspend index c5fa47e77..e27df0f93 100755 --- a/config/homebin/vagrant_suspend +++ b/config/homebin/vagrant_suspend @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # This script is run whenever `vagrant suspend` is used to suspend # the virtual machine. To customize this behavior, include a file @@ -18,13 +18,13 @@ else fi # Check if backups are turned on or off - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup.enable) if [[ -z "$run_backups" ]]; then - run_backups=`cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup` + run_backups=$(cat ${VVV_CONFIG} | shyaml -q get-value general.db_backup) fi if [[ $run_backups != "False" ]]; then - /srv/config/homebin/db_backup + /srv/config/homebin/db_backup fi RED="\033[38;5;9m" diff --git a/config/homebin/vagrant_up b/config/homebin/vagrant_up index 4ec3e6b6b..ca1527ec4 100755 --- a/config/homebin/vagrant_up +++ b/config/homebin/vagrant_up @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # This script is run whenever `vagrant up` is used to power on # the virtual machine. To customize this behavior, include a file @@ -25,23 +25,30 @@ URL="\033[4;38;5;3m" 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 + vvv_info " * Custom vagrant up script finished" fi # /etc/host doesn't survive restart on docker -vvv_info " * Reinit /etc/hosts" +vvv_info " * Updatin Guest VM /etc/hosts" vvv_update_guest_hosts -vvv_info " * Restarting Nginx" -sudo service nginx restart +if ! sudo service nginx status > /dev/null; then + vvv_info " * Starting Nginx service" + sudo service nginx start +fi -vvv_info " * Restarting MariaDB" -sudo service mariadb restart +if ! sudo service mariadb status > /dev/null; then + vvv_info " * Starting MariaDB service" + sudo service mariadb start +fi -vvv_info " * Restarting PHP-FPM" -find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; +vvv_info " * Checking PHP-FPM Services" +find /etc/init.d/ -name "php*-fpm" -exec bash -c 'if ! sudo service "$(basename "$0")" status > /dev/null; then sudo service "$(basename "$0")" start; fi' {} \; -vvv_info " * Restarting Memcache" -sudo service memcached restart +if ! sudo service memcached status > /dev/null; then + vvv_info " * Starting memcached service" + sudo service memcached start +fi vvv_info " * Restarting Mailhog" /usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 & @@ -50,7 +57,7 @@ if [ ! -f /.dockerenv ]; then if [ -x "$(command -v ntpdate)" ]; then vvv_info " * Syncing clocks" if sudo ntpdate -u ntp.ubuntu.com; then - vvv_info " * clocks synced" + vvv_succss " * clocks synced" else vvv_warn " - clock synchronisation failed" fi diff --git a/config/homebin/xdebug_off b/config/homebin/xdebug_off index c469ddbdd..6b0fb1825 100755 --- a/config/homebin/xdebug_off +++ b/config/homebin/xdebug_off @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash switch_php_debugmod none diff --git a/config/homebin/xdebug_on b/config/homebin/xdebug_on index e3f9fe7ae..78d5d0db1 100755 --- a/config/homebin/xdebug_on +++ b/config/homebin/xdebug_on @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash switch_php_debugmod xdebug diff --git a/provision/core/mariadb/provision.sh b/provision/core/mariadb/provision.sh index 7c3edf216..1077c5a3b 100644 --- a/provision/core/mariadb/provision.sh +++ b/provision/core/mariadb/provision.sh @@ -126,21 +126,21 @@ function mysql_setup() { # Due to systemd dependencies, in docker, mysql service is not auto started vvv_info " * Ensuring MariaDB service is started" - service mariadb restart + service mariadb status > /dev/null || service mariadb start - if [ "${VVV_DOCKER}" != 1 ]; then + if [ ! -f /.dockerenv ]; then check_mysql_root_password fi # 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 [ $(service mariadb status|grep 'Uptime' | wc -l) -ne 1 ]; then + if service mariadb status > /dev/null; then vvv_info " * Starting the mariadb service" - service mariadb start + service mariadb restart else vvv_info " * Restarting mariadb service" - service mariadb restart + service mariadb start fi # IMPORT SQL diff --git a/provision/core/memcached/provision.sh b/provision/core/memcached/provision.sh index a8dde3bcc..752d0d25f 100644 --- a/provision/core/memcached/provision.sh +++ b/provision/core/memcached/provision.sh @@ -22,8 +22,10 @@ export -f vvv_memcached_setup vvv_add_hook after_packages vvv_memcached_setup 60 function vvv_memcached_restart() { - if [ "${VVV_DOCKER}" != 1 ]; then + if service memcached status > /dev/null; then service memcached restart + else + service memcached start fi } diff --git a/provision/core/nginx/provision.sh b/provision/core/nginx/provision.sh index 7d0f74a8b..75aede29e 100644 --- a/provision/core/nginx/provision.sh +++ b/provision/core/nginx/provision.sh @@ -105,8 +105,10 @@ export -f nginx_setup vvv_add_hook after_packages nginx_setup 40 function vvv_nginx_restart() { - if [ "${VVV_DOCKER}" != 1 ]; then + if service nginx status > /dev/null; then service nginx restart + else + service nginx start fi } diff --git a/provision/core/php/provision.sh b/provision/core/php/provision.sh index 009193f12..6aabd175a 100644 --- a/provision/core/php/provision.sh +++ b/provision/core/php/provision.sh @@ -137,7 +137,7 @@ vvv_add_hook finalize phpfpm_finalize function phpfpm_services_restart() { # Restart all php-fpm versions - if [ "${VVV_DOCKER}" != 1 ]; then + if [ ! -f /.dockerenv ]; then find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; fi } diff --git a/provision/core/vvv/provision.sh b/provision/core/vvv/provision.sh index 65c4024a2..b362a41b9 100644 --- a/provision/core/vvv/provision.sh +++ b/provision/core/vvv/provision.sh @@ -105,7 +105,7 @@ export -f shyaml_setup vvv_add_hook after_packages shyaml_setup 0 function vvv_ntp_restart() { - if [ "${VVV_DOCKER}" != 1 ]; then + if [ ! -f /.dockerenv ]; then service ntp restart fi } diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh index 775b518a4..966d1c682 100755 --- a/provision/provision-helpers.sh +++ b/provision/provision-helpers.sh @@ -637,7 +637,11 @@ function vvv_maybe_install_nginx_config() { return 1 fi - sudo service nginx reload + if sudo service nginx status > /dev/null; then + sudo service nginx reload + else + sudo service nginx start + fi return 0 }