Browse Source

New `bin/blackfire` script to enable, disable, or check status of Blackfire extension.

Mark Shust 1 year ago
parent
commit
e6d11d47e7
3 changed files with 59 additions and 2 deletions
  1. 2 1
      README.md
  2. 2 1
      compose/Makefile
  3. 55 0
      compose/bin/blackfire

+ 2 - 1
README.md

@@ -286,6 +286,7 @@ It is recommended to keep your root docker config files in one repository, and y
 
 - `bin/analyse`: Run `phpstan analyse` within the container to statically analyse code, passing in directory to analyse. Ex. `bin/analyse app/code`
 - `bin/bash`: Drop into the bash prompt of your Docker container. The `phpfpm` container should be mainly used to access the filesystem within Docker.
+- `bin/blackfire`: Disable or enable Blackfire. Accepts argument `disable`, `enable`, or `status`. Ex. `bin/blackfire enable`
 - `bin/cache-clean`: Access the [cache-clean](https://github.com/mage2tv/magento-cache-clean) CLI. Note the watcher is automatically started at startup in `bin/start`. Ex. `bin/cache-clean config full_page`
 - `bin/check-dependencies`: Provides helpful recommendations for dependencies tailored to the chosen Magento version.
 - `bin/cli`: Run any CLI command without going into the bash prompt. Ex. `bin/cli ls`
@@ -346,7 +347,7 @@ It is recommended to keep your root docker config files in one repository, and y
 - `bin/stop`: Stop all project containers.
 - `bin/stopall`: Stop all docker running containers
 - `bin/update`: Update your project to the most recent version of `docker-magento`.
-- `bin/xdebug`: Disable or enable Xdebug. Accepts params `disable` (default) or `enable`. Ex. `bin/xdebug enable`
+- `bin/xdebug`: Disable or enable Xdebug. Accepts argument `disable`, `enable`, or `status`. Ex. `bin/xdebug enable`
 
 ## Misc Info
 

+ 2 - 1
compose/Makefile

@@ -21,6 +21,7 @@ help:
 	@echo "$(call red,===============================)"
 	@echo "$(call format,analyse,'Run `phpstan analyse` within the container to statically analyse code, passing in directory to analyse.')"
 	@echo "$(call format,bash,'Drop into the bash prompt of your Docker container.')"
+	@echo "$(call format,blackfire,'Disable or enable Blackfire. Accepts argument `disable`, `enable`, or `status`.')"
 	@echo "$(call format,cache-clean,'Access the cache-clean CLI.')"
 	@echo "$(call format,check-dependencies,'Provides helpful recommendations for dependencies.')"
 	@echo "$(call format,cli,'Run any CLI command without going into the bash prompt.')"
@@ -81,7 +82,7 @@ help:
 	@echo "$(call format,stop,'Stop all project containers.')"
 	@echo "$(call format,stopall,'Stop all docker running containers.')"
 	@echo "$(call format,update,'Update your project to the latest version of docker-magento.')"
-	@echo "$(call format,xdebug,'Disable or enable Xdebug.')"
+	@echo "$(call format,xdebug,'Disable or enable Xdebug. Accepts argument `disable`, `enable`, or `status`.')"
 
 
 analyse:

+ 55 - 0
compose/bin/blackfire

@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+S=$(bin/clinotty cat /usr/local/etc/php/conf.d/blackfire.ini | grep -iGc '\;extension=blackfire.so');
+
+blackfire_status() {
+    if [[ $S == 1 ]]; then
+        echo "Blackfire is disabled."
+    else
+        echo "Blackfire is enabled."
+    fi
+}
+
+blackfire_toggle() {
+    if [[ $S == 1 ]]; then
+        blackfire_enable
+    else
+        blackfire_disable
+    fi
+}
+
+blackfire_enable() {
+    if [[ $S == 1 ]]; then
+        bin/root sed -i -e 's/^;extension=blackfire.so/extension=blackfire.so/g' /usr/local/etc/php/conf.d/blackfire.ini
+        sleep 1
+        bin/restart phpfpm
+        echo "Blackfire has been enabled."
+    else
+        echo "Blackfire is already enabled."
+    fi
+}
+
+blackfire_disable() {
+    if [[ $S == 0 ]]; then
+        bin/root sed -i -e 's/^extension=blackfire.so/;extension=blackfire.so/g' /usr/local/etc/php/conf.d/blackfire.ini
+        sleep 1
+        bin/restart phpfpm
+        echo "Blackfire has been disabled."
+    else
+        echo "Blackfire is already disabled."
+    fi
+}
+
+firstArgLetter="$(echo "$1" | head -c 1)"
+
+if [[ $firstArgLetter == "d" ]]; then
+    blackfire_disable
+elif [[ $firstArgLetter == "e" ]]; then
+    blackfire_enable
+elif [[ $firstArgLetter == "t" ]]; then
+    blackfire_toggle
+elif [[ $firstArgLetter == "s" ]]; then
+    blackfire_status
+else
+    printf "Please specify either 'disable', 'enable', 'status' or 'toggle' as an argument.\nEx: bin/blackfire status\n"
+fi