postinst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. set -e
  3. [ -f /etc/default/grafana-server ] && . /etc/default/grafana-server
  4. IS_UPGRADE=false
  5. case "$1" in
  6. configure)
  7. [ -z "$GRAFANA_USER" ] && GRAFANA_USER="grafana"
  8. [ -z "$GRAFANA_GROUP" ] && GRAFANA_GROUP="grafana"
  9. if ! getent group "$GRAFANA_GROUP" > /dev/null 2>&1 ; then
  10. addgroup --system "$GRAFANA_GROUP" --quiet
  11. fi
  12. if ! id $GRAFANA_USER > /dev/null 2>&1 ; then
  13. adduser --system --home /usr/share/grafana --no-create-home \
  14. --ingroup "$GRAFANA_GROUP" --disabled-password --shell /bin/false \
  15. "$GRAFANA_USER"
  16. fi
  17. # Set user permissions on /var/log/grafana, /var/lib/grafana
  18. mkdir -p /var/log/grafana /var/lib/grafana
  19. chown -R $GRAFANA_USER:$GRAFANA_GROUP /var/log/grafana /var/lib/grafana
  20. chmod 755 /var/log/grafana /var/lib/grafana
  21. # copy user config files
  22. if [ ! -f $CONF_FILE ]; then
  23. cp /usr/share/grafana/conf/sample.ini $CONF_FILE
  24. cp /usr/share/grafana/conf/ldap.toml /etc/grafana/ldap.toml
  25. fi
  26. if [ ! -f $PROVISIONING_CFG_DIR ]; then
  27. mkdir -p $PROVISIONING_CFG_DIR/dashboards $PROVISIONING_CFG_DIR/datasources
  28. cp /usr/share/grafana/conf/provisioning/dashboards/sample.yaml $PROVISIONING_CFG_DIR/dashboards/sample.yaml
  29. cp /usr/share/grafana/conf/provisioning/datasources/sample.yaml $PROVISIONING_CFG_DIR/datasources/sample.yaml
  30. fi
  31. # configuration files should not be modifiable by grafana user, as this can be a security issue
  32. chown -Rh root:$GRAFANA_GROUP /etc/grafana/*
  33. chmod 755 /etc/grafana
  34. find /etc/grafana -type f -exec chmod 640 {} ';'
  35. find /etc/grafana -type d -exec chmod 755 {} ';'
  36. # If $1=configure and $2 is set, this is an upgrade
  37. if [ "$2" != "" ]; then
  38. IS_UPGRADE=true
  39. fi
  40. if [ "x$IS_UPGRADE" != "xtrue" ]; then
  41. if command -v systemctl >/dev/null; then
  42. echo "### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd"
  43. echo " sudo /bin/systemctl daemon-reload"
  44. echo " sudo /bin/systemctl enable grafana-server"
  45. echo "### You can start grafana-server by executing"
  46. echo " sudo /bin/systemctl start grafana-server"
  47. elif command -v update-rc.d >/dev/null; then
  48. echo "### NOT starting grafana-server by default on bootup, please execute"
  49. echo " sudo update-rc.d grafana-server defaults 95 10"
  50. echo "### In order to start grafana-server, execute"
  51. echo " sudo service grafana-server start"
  52. fi
  53. elif [ "$RESTART_ON_UPGRADE" = "true" ]; then
  54. echo -n "Restarting grafana-server service..."
  55. if command -v systemctl >/dev/null; then
  56. systemctl daemon-reload
  57. systemctl restart grafana-server || true
  58. elif [ -x /etc/init.d/grafana-server ]; then
  59. if command -v invoke-rc.d >/dev/null; then
  60. invoke-rc.d grafana-server restart || true
  61. else
  62. /etc/init.d/grafana-server restart || true
  63. fi
  64. fi
  65. echo " OK"
  66. fi
  67. ;;
  68. esac