Blob Blame History Raw
#!/bin/bash -eu

. /etc/sysconfig/grafana-server

# setup permissions at the first start of the container with a volume mount
if [ ! -f "${DATA_DIR}/grafana.db" ]; then
  touch "${DATA_DIR}/grafana.db"
  chmod 640 "${DATA_DIR}/grafana.db"
fi

if [ ! -d "${PLUGINS_DIR}" ]; then
  mkdir "${PLUGINS_DIR}"
fi

# only for upgrades: delete the old plugin directory inside the volume
if [ -d "${PLUGINS_DIR}/grafana-pcp" ]; then
  rm -rf "${PLUGINS_DIR}/grafana-pcp"
fi
if [ -d "${PLUGINS_DIR}/performancecopilot-pcp-app" ] && [ ! -L "${PLUGINS_DIR}/performancecopilot-pcp-app" ]; then
  rm -rf "${PLUGINS_DIR}/performancecopilot-pcp-app"
fi

# /var/lib/grafana is mounted as a volume to persist the grafana.db database and any additional installed plugins
# let's place a symlink (in the volume) to the actual location of the grafana-pcp plugin (not in the volume)
ln -sf /usr/share/performancecopilot-pcp-app "${PLUGINS_DIR}"

exec /usr/sbin/grafana-server \
    --homepath="${GRAFANA_HOME}" \
    --config="${CONF_FILE}" \
    --packaging="docker" \
    cfg:default.log.mode="console" \
    cfg:default.paths.logs="${LOG_DIR}" \
    cfg:default.paths.data="${DATA_DIR}" \
    cfg:default.paths.plugins="${PLUGINS_DIR}" \
    cfg:default.paths.provisioning="${PROVISIONING_CFG_DIR}" \
    "$@"