netdata.in 2.5 KB

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