postinst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. set -e
  3. [ -f /etc/default/grafana ] && . /etc/default/grafana
  4. startGrafana() {
  5. if [ -x /bin/systemctl ] ; then
  6. /bin/systemctl daemon-reload
  7. /bin/systemctl start grafana.service
  8. elif [ -x "/etc/init.d/grafana" ]; then
  9. if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  10. invoke-rc.d grafana start || true
  11. else
  12. /etc/init.d/grafana start || true
  13. fi
  14. fi
  15. }
  16. case "$1" in
  17. configure)
  18. [ -z "$GRAFANA_USER" ] && GRAFANA_USER="grafana"
  19. [ -z "$GRAFANA_GROUP" ] && GRAFANA_GROUP="grafana"
  20. if ! getent group "$GRAFANA_GROUP" > /dev/null 2>&1 ; then
  21. addgroup --system "$GRAFANA_GROUP" --quiet
  22. fi
  23. if ! id $GRAFANA_USER > /dev/null 2>&1 ; then
  24. adduser --system --home /usr/share/grafana --no-create-home \
  25. --ingroup "$GRAFANA_GROUP" --disabled-password --shell /bin/false \
  26. "$GRAFANA_USER"
  27. fi
  28. # Set user permissions on /var/log/grafana, /opt/grafana/data
  29. mkdir -p /var/log/grafana /opt/grafana/data
  30. chown -R $GRAFANA_USER:$GRAFANA_GROUP /var/log/grafana /opt/grafana/data
  31. chmod 755 /var/log/grafana /opt/grafana/data
  32. # configuration files should not be modifiable by elasticsearch user, as this can be a security issue
  33. chown -Rh root:root /etc/grafana/*
  34. chmod 755 /etc/grafana
  35. find /etc/grafana -type f -exec chmod 644 {} ';'
  36. find /etc/grafana -type d -exec chmod 755 {} ';'
  37. # if $2 is set, this is an upgrade
  38. if ( [ -n $2 ] && [ "$RESTART_ON_UPGRADE" = "true" ] ) ; then
  39. startGrafana
  40. # this is a fresh installation
  41. elif [ -z $2 ] ; then
  42. if [ -x /bin/systemctl ] ; then
  43. echo "### NOT starting on installation, please execute the following statements to configure elasticsearch to start automatically using systemd"
  44. echo " sudo /bin/systemctl daemon-reload"
  45. echo " sudo /bin/systemctl enable grafana.service"
  46. echo "### You can start grafana by executing"
  47. echo " sudo /bin/systemctl start grafana.service"
  48. elif [ -x /usr/sbin/update-rc.d ] ; then
  49. echo "### NOT starting grafana by default on bootup, please execute"
  50. echo " sudo update-rc.d grafana defaults 95 10"
  51. echo "### In order to start grafana, execute"
  52. echo " sudo /etc/init.d/grafana start"
  53. fi
  54. fi
  55. ;;
  56. esac