netdata.in 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. #
  4. # Netdata LSB start script
  5. ### BEGIN INIT INFO
  6. # Provides: netdata
  7. # Required-Start: $local_fs $remote_fs $network $named $time
  8. # Required-Stop: $local_fs $remote_fs $network $named $time
  9. # Should-Start: $local_fs $network $named $remote_fs $time $all
  10. # Should-Stop: $local_fs $network $named $remote_fs $time $all
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: Start and stop the netdata real-time monitoring server daemon
  14. # Description: Controls the main netdata monitoring server daemon "netdata".
  15. # and all its plugins.
  16. ### END INIT INFO
  17. #
  18. set -e
  19. set -u
  20. ${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
  21. DAEMON="netdata"
  22. DAEMON_PATH=@sbindir_POST@
  23. PIDFILE_PATH=@localstatedir_POST@/run/netdata
  24. PIDFILE=$PIDFILE_PATH/$DAEMON.pid
  25. DAEMONOPTS="-P $PIDFILE"
  26. test -x $DAEMON_PATH/$DAEMON || exit 0
  27. . /lib/lsb/init-functions
  28. # Safeguard (relative paths, core dumps..)
  29. cd /
  30. umask 022
  31. service_start() {
  32. if [ ! -d $PIDFILE_PATH ]; then
  33. mkdir -p $PIDFILE_PATH
  34. fi
  35. chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH
  36. log_success_msg "Starting real-time performance monitoring"
  37. start_daemon -p $PIDFILE $DAEMON_PATH/$DAEMON $DAEMONOPTS
  38. RETVAL=$?
  39. case "${RETVAL}" in
  40. 0) log_success_msg "Started real-time performance monitoring" ;;
  41. *) log_error_msg "Failed to start real-time performance monitoring" ;;
  42. esac
  43. return $RETVAL
  44. }
  45. service_stop() {
  46. log_success_msg "Stopping real-time performance monitoring"
  47. killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON
  48. RETVAL=$?
  49. case "${RETVAL}" in
  50. 0) log_success_msg "Stopped real-time performance monitoring" ;;
  51. *) log_error_msg "Failed to stop real-time performance monitoring" ;;
  52. esac
  53. if [ $RETVAL -eq 0 ]; then
  54. rm -f ${PIDFILE}
  55. fi
  56. return $RETVAL
  57. }
  58. condrestart() {
  59. if ! service_status > /dev/null; then
  60. RETVAL=$1
  61. return
  62. fi
  63. service_stop
  64. service_start
  65. }
  66. service_status() {
  67. pidofproc -p $PIDFILE $DAEMON_PATH/$DAEMON
  68. }
  69. #
  70. # main()
  71. #
  72. case "${1:-''}" in
  73. 'start')
  74. service_start
  75. ;;
  76. 'stop')
  77. service_stop
  78. ;;
  79. 'restart')
  80. service_stop
  81. service_start
  82. ;;
  83. 'try-restart')
  84. condrestart 0
  85. ;;
  86. 'force-reload')
  87. condrestart 7
  88. ;;
  89. 'status')
  90. service_status && exit 0 || exit $?
  91. ;;
  92. *)
  93. echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
  94. exit 1
  95. esac