devilbox/autostart/run-blackfire-agent.sh-example

192 lines
4.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -e
set -u
set -o pipefail
###
### Pre-flight check
###
if ! command -v blackfire-agent >/dev/null 2>&1; then
echo "No blackfire-agent binary available, skipping initialization"
exit 0
fi
###
2019-01-27 13:04:59 +00:00
### Blackfire Server (Agent) Variables
###
2019-01-27 13:04:59 +00:00
# Blackfire Server ID via env: BLACKFIRE_SERVER_ID
BF_SERVER_ID=
# Blackfire Server Token via env: BLACKFIRE_SERVER_TOKEN
BF_SERVER_TOKEN=
# Blackfire Server Loglevel (4: debug, 3: info, 2: warning, 1: error)
BF_SERVER_LOGLEVEL=2
###
2019-01-27 13:04:59 +00:00
### Blackfire Client (cli) Variables
###
2019-01-27 13:04:59 +00:00
# Blackfire Client ID via env: BLACKFIRE_SERVER_ID
BF_CLIENT_ID=
# Blackfire Client Token via env: BLACKFIRE_SERVER_TOKEN
BF_CLIENT_TOKEN=
###
### Get Server ID and Server Token
###
if BF_SERVER_ID="$( env | grep -Eo '^BLACKFIRE_SERVER_ID=.*$' )"; then
BF_SERVER_ID="${BF_SERVER_ID#*=}"
fi
if BF_SERVER_TOKEN="$( env | grep -Eo '^BLACKFIRE_SERVER_TOKEN=.*$' )"; then
BF_SERVER_TOKEN="${BF_SERVER_TOKEN#*=}"
fi
2019-01-27 13:04:59 +00:00
###
### Get Client ID and Client Token
###
if BF_CLIENT_ID="$( env | grep -Eo '^BLACKFIRE_CLIENT_ID=.*$' )"; then
BF_CLIENT_ID="${BF_CLIENT_ID#*=}"
fi
if BF_CLIENT_TOKEN="$( env | grep -Eo '^BLACKFIRE_CLIENT_TOKEN=.*$' )"; then
BF_CLIENT_TOKEN="${BF_CLIENT_TOKEN#*=}"
fi
###
2019-01-27 13:04:59 +00:00
### Create Server (Agent) Config
###
{
echo "[blackfire]";
echo ";";
echo "; This is a configuration file for Blackfire's Agent.";
echo ";";
echo "";
echo ";";
echo "; setting: ca-cert";
echo "; desc : Sets the PEM encoded certificates";
echo "; default:";
echo "ca-cert=";
echo "";
echo ";";
echo "; setting: collector";
echo "; desc : Sets the URL of Blackfire's data collector";
echo "; default: https://blackfire.io";
echo "collector=https://blackfire.io";
echo "";
echo ";";
echo "; setting: http-proxy";
echo "; desc : Sets the HTTP proxy to use";
echo "; default:";
echo "http-proxy=";
echo "";
echo ";";
echo "; setting: https-proxy";
echo "; desc : Sets the HTTPS proxy to use";
echo "; default:";
echo "https-proxy=";
echo "";
echo ";";
echo "; setting: log-file";
echo "; desc : Sets the path of the log file. Use stderr to log to stderr";
echo "; default: stderr";
echo "log-file=stderr";
echo "";
echo ";";
echo "; setting: log-level";
echo "; desc : log verbosity level (4: debug, 3: info, 2: warning, 1: error)";
echo "; default: 1";
2019-01-27 13:04:59 +00:00
echo "log-level=${BF_SERVER_LOGLEVEL}";
echo "";
echo ";";
echo "; setting: server-id";
echo "; desc : Sets the server id used to authenticate with Blackfire API";
echo "; default:";
2019-01-27 13:04:59 +00:00
echo "server-id=${BF_SERVER_ID}";
echo "";
echo ";";
echo "; setting: server-token";
echo "; desc : Sets the server token used to authenticate with Blackfire API. It is unsafe to set this from the command line";
echo "; default:";
2019-01-27 13:04:59 +00:00
echo "server-token=${BF_SERVER_TOKEN}";
echo "";
echo ";";
echo "; setting: socket";
echo "; desc : Sets the socket the agent should read traces from. Possible value can be a unix socket or a TCP address. ie: unix:///var/run/blackfire/agent.sock or tcp://127.0.0.1:8307";
echo "; default: unix:///var/run/blackfire/agent.sock";
echo "socket=unix:///var/run/blackfire/agent.sock";
echo "";
echo ";";
echo "; setting: spec";
echo "; desc : Sets the path to the JSON specifications file";
echo "; default:";
echo "spec=";
} > /etc/blackfire/agent
2019-01-27 13:04:59 +00:00
###
### Create Client (cli) Config
###
{
echo "[blackfire]";
echo ";";
echo "; This is a configuration file for Blackfire.";
echo ";";
echo "";
echo ";";
echo "; setting: ca-cert";
echo "; desc : Sets the PEM encoded certificates to use";
echo "; default:";
echo "ca-cert=";
echo "";
echo ";";
echo "; setting: client-id";
echo "; desc : Sets the Client ID used for API authentication";
echo "; default:";
echo "client-id=${BF_CLIENT_ID}";
echo "";
echo ";";
echo "; setting: client-token";
echo "; desc : Sets the Client Token used for API authentication";
echo "; default:";
echo "client-token=${BF_CLIENT_TOKEN}";
echo "";
echo ";";
echo "; setting: endpoint";
echo "; desc : Sets the API endpoint";
echo "; default: https://blackfire.io";
echo "endpoint=https://blackfire.io";
echo "";
echo ";";
echo "; setting: http-proxy";
echo "; desc : Sets the HTTP proxy to use";
echo "; default:";
echo "http-proxy=";
echo "";
echo ";";
echo "; setting: https-proxy";
echo "; desc : Sets the HTTPS proxy to use";
echo "; default:";
echo "https-proxy=";
echo "";
echo ";";
echo "; setting: timeout";
echo "; desc : Sets the Blackfire API connection timeout";
echo "; default: 15s";
echo "timeout=15s";
} > /home/devilbox/.blackfire.ini
chown devilbox:devilbox /home/devilbox/.blackfire.ini
chmod 0600 /home/devilbox/.blackfire.ini
###
### Start agent
###
2019-01-27 13:04:59 +00:00
/etc/init.d/blackfire-agent restart || true