diff --git a/dokuwikiinstall b/dokuwikiinstall index dfe4189..04b71c9 100755 --- a/dokuwikiinstall +++ b/dokuwikiinstall @@ -34,10 +34,27 @@ usage () { } # -# Function to check if a service is already running or not +# Function check if a service is running or stopped, including php-fpm # -serviceno () { printf "\n%s" "$service" ; printf " is not running cannot continue...\n\n"; } -servicedead () { status=$(systemctl is-active "$service"); if [[ "$status" != "active" ]]; then serviceno ; exit 1 ; fi; } +checkservice() { + local svc="$1" ; local mode="$2" + + if [[ "$svc" == php*-fpm ]] && ! systemctl list-unit-files --type=service | grep -q "^${svc}.service" ; then + svc="php-fpm" + fi + + if [[ "$mode" == "mustberunning" ]]; then + if ! systemctl is-active --quiet "$svc" 2>/dev/null; then + printf "\nService %s is not running, aborting...\n\n" "$svc" + exit 1 + fi + elif [[ "$mode" == "mustnotberunning" ]]; then + if systemctl is-active --quiet "$svc" 2>/dev/null; then + printf "\nService %s is already running, aborting...\n\n" "$svc" + exit 1 + fi + fi +} # # Function input check @@ -45,9 +62,9 @@ servicedead () { status=$(systemctl is-active "$service"); if [[ "$status" != " inputcheck () { if [[ -z "$1" ]]; then usage ; printf "ERROR: DOMAIN CANNOT BE EMPTY!\n\n" ; exit; fi; } # -# If Nginx is not running then die +# If Nginx or PHP-Fpm version is not found or not running the die. # -service="nginx" ; servicedead +checkservice nginx running ; checkservice "$phpfpm" running # # Let's go