You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.4 KiB

  1. #!/bin/sh
  2. set -a
  3. ### BEGIN INIT INFO
  4. # Provides: etcd
  5. # Required-Start: $local_fs $network $syslog
  6. # Required-Stop:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: etcd distributed k/v store
  10. # Description:
  11. # etcd is a distributed, consistent key-value store for shared configuration and service discovery
  12. ### END INIT INFO
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="etcd k/v store"
  15. NAME=etcd
  16. DAEMON={{ bin_dir }}/etcd
  17. SCRIPTNAME=/etc/init.d/$NAME
  18. DAEMON_USER=etcd
  19. STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"
  20. PID=/var/run/etcd.pid
  21. # Exit if the binary is not present
  22. [ -x "$DAEMON" ] || exit 0
  23. # Read configuration variable file if it is present
  24. [ -f /etc/etcd.env ] && . /etc/etcd.env
  25. # Define LSB log_* functions.
  26. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  27. # and status_of_proc is working.
  28. . /lib/lsb/init-functions
  29. do_status()
  30. {
  31. status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
  32. }
  33. # Function that starts the daemon/service
  34. #
  35. do_start()
  36. {
  37. start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON -- \
  38. $DAEMON_ARGS \
  39. || return 2
  40. }
  41. #
  42. # Function that stops the daemon/service
  43. #
  44. do_stop()
  45. {
  46. start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
  47. RETVAL="$?"
  48. sleep 1
  49. return "$RETVAL"
  50. }
  51. case "$1" in
  52. start)
  53. log_daemon_msg "Starting $DESC" "$NAME"
  54. do_start
  55. case "$?" in
  56. 0|1) log_end_msg 0 || exit 0 ;;
  57. 2) log_end_msg 1 || exit 1 ;;
  58. esac
  59. ;;
  60. stop)
  61. log_daemon_msg "Stopping $DESC" "$NAME"
  62. if do_stop; then
  63. log_end_msg 0
  64. else
  65. log_failure_msg "Can't stop etcd"
  66. log_end_msg 1
  67. fi
  68. ;;
  69. status)
  70. if do_status; then
  71. log_end_msg 0
  72. else
  73. log_failure_msg "etcd is not running"
  74. log_end_msg 1
  75. fi
  76. ;;
  77. restart|force-reload)
  78. log_daemon_msg "Restarting $DESC" "$NAME"
  79. if do_stop; then
  80. if do_start; then
  81. log_end_msg 0
  82. exit 0
  83. else
  84. rc="$?"
  85. fi
  86. else
  87. rc="$?"
  88. fi
  89. log_failure_msg "Can't restart etcd"
  90. log_end_msg ${rc}
  91. ;;
  92. *)
  93. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  94. exit 3
  95. ;;
  96. esac