postinst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 [ ! -d $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. if [ ! -d $PROVISIONING_CFG_DIR/notifiers ]; then
  32. mkdir -p $PROVISIONING_CFG_DIR/notifiers
  33. cp /usr/share/grafana/conf/provisioning/notifiers/sample.yaml $PROVISIONING_CFG_DIR/notifiers/sample.yaml
  34. fi
  35. # configuration files should not be modifiable by grafana user, as this can be a security issue
  36. chown -Rh root:$GRAFANA_GROUP /etc/grafana/*
  37. chmod 755 /etc/grafana
  38. find /etc/grafana -type f -exec chmod 640 {} ';'
  39. find /etc/grafana -type d -exec chmod 755 {} ';'
  40. # If $1=configure and $2 is set, this is an upgrade
  41. if [ "$2" != "" ]; then
  42. IS_UPGRADE=true
  43. fi
  44. if [ "x$IS_UPGRADE" != "xtrue" ]; then
  45. if command -v systemctl >/dev/null; then
  46. echo "### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd"
  47. echo " sudo /bin/systemctl daemon-reload"
  48. echo " sudo /bin/systemctl enable grafana-server"
  49. echo "### You can start grafana-server by executing"
  50. echo " sudo /bin/systemctl start grafana-server"
  51. elif command -v update-rc.d >/dev/null; then
  52. echo "### NOT starting grafana-server by default on bootup, please execute"
  53. echo " sudo update-rc.d grafana-server defaults 95 10"
  54. echo "### In order to start grafana-server, execute"
  55. echo " sudo service grafana-server start"
  56. fi
  57. elif [ "$RESTART_ON_UPGRADE" = "true" ]; then
  58. echo -n "Restarting grafana-server service..."
  59. if command -v systemctl >/dev/null; then
  60. systemctl daemon-reload
  61. systemctl restart grafana-server || true
  62. elif [ -x /etc/init.d/grafana-server ]; then
  63. if command -v invoke-rc.d >/dev/null; then
  64. invoke-rc.d grafana-server restart || true
  65. else
  66. /etc/init.d/grafana-server restart || true
  67. fi
  68. fi
  69. echo " OK"
  70. fi
  71. ;;
  72. esac