Public repo to distribute scripts and config's
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

77 lignes
1.8 KiB

  1. #!/bin/sh -e
  2. VERSION=1.7.0
  3. RELEASE=node_exporter-${VERSION}.linux-amd64
  4. _check_root () {
  5. if [ $(id -u) -ne 0 ]; then
  6. echo "Please run as root" >&2;
  7. exit 1;
  8. fi
  9. }
  10. _install_curl () {
  11. if [ -x "$(command -v curl)" ]; then
  12. return
  13. fi
  14. if [ -x "$(command -v apt-get)" ]; then
  15. apt-get update
  16. apt-get -y install curl
  17. elif [ -x "$(command -v yum)" ]; then
  18. yum -y install curl
  19. else
  20. echo "No known package manager found" >&2;
  21. exit 1;
  22. fi
  23. }
  24. _check_root
  25. _install_curl
  26. cd /tmp
  27. curl -sSL https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/${RELEASE}.tar.gz | tar xz
  28. #mkdir -p /opt/node_exporter
  29. cp ${RELEASE}/node_exporter /usr/local/bin/
  30. rm -rf /tmp/${RELEASE}
  31. useradd --system --no-create-home --shell /usr/sbin/nologin prometheus
  32. if [ -x "$(command -v systemctl)" ]; then
  33. cat << EOF > /etc/systemd/system/node-exporter.service
  34. [Unit]
  35. Description=Prometheus exporter for machine metrics
  36. [Service]
  37. Restart=always
  38. User=prometheus
  39. ExecStart=/usr/local/bin/node_exporter
  40. ExecReload=/bin/kill -HUP $MAINPID
  41. TimeoutStopSec=20s
  42. SendSIGKILL=no
  43. [Install]
  44. WantedBy=multi-user.target
  45. EOF
  46. systemctl daemon-reload
  47. systemctl enable node-exporter
  48. systemctl start node-exporter
  49. systemctl status node-exporter
  50. fi
  51. #elif [ -x "$(command -v chckconfig)" ]; then
  52. # cat << EOF >> /etc/inittab
  53. #::respawn:/opt/node_exporter/node_exporter
  54. #EOF
  55. #elif [ -x "$(command -v initctl)" ]; then
  56. # cat << EOF > /etc/init/node-exporter.conf
  57. #start on runlevel [23456]
  58. #stop on runlevel [016]
  59. #exec /opt/node_exporter/node_exporter
  60. #respawn
  61. #EOF
  62. #
  63. # initctl reload-configuration
  64. # stop node-exporter || true && start node-exporter
  65. #else
  66. # echo "No known service management found" >&2;
  67. # exit 1;
  68. #fi