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.

113 lines
2.5 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. {% if inventory_hostname in groups['etcd'] %}
  18. DAEMON_ARGS=""
  19. {% else %}
  20. DAEMON_ARGS="-proxy on"
  21. {% endif %}
  22. SCRIPTNAME=/etc/init.d/$NAME
  23. DAEMON_USER=etcd
  24. STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"
  25. PID=/var/run/etcd.pid
  26. # Exit if the binary is not present
  27. [ -x "$DAEMON" ] || exit 0
  28. # Read configuration variable file if it is present
  29. [ -f /etc/etcd.env ] && . /etc/etcd.env
  30. # Define LSB log_* functions.
  31. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  32. # and status_of_proc is working.
  33. . /lib/lsb/init-functions
  34. do_status()
  35. {
  36. status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
  37. }
  38. # Function that starts the daemon/service
  39. #
  40. do_start()
  41. {
  42. start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON \
  43. $DAEMON_OPTS \
  44. || return 2
  45. }
  46. #
  47. # Function that stops the daemon/service
  48. #
  49. do_stop()
  50. {
  51. start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
  52. RETVAL="$?"
  53. sleep 1
  54. return "$RETVAL"
  55. }
  56. case "$1" in
  57. start)
  58. log_daemon_msg "Starting $DESC" "$NAME"
  59. do_start
  60. case "$?" in
  61. 0|1) log_end_msg 0 || exit 0 ;;
  62. 2) log_end_msg 1 || exit 1 ;;
  63. esac
  64. ;;
  65. stop)
  66. log_daemon_msg "Stopping $DESC" "$NAME"
  67. if do_stop; then
  68. log_end_msg 0
  69. else
  70. log_failure_msg "Can't stop etcd"
  71. log_end_msg 1
  72. fi
  73. ;;
  74. status)
  75. if do_status; then
  76. log_end_msg 0
  77. else
  78. log_failure_msg "etcd is not running"
  79. log_end_msg 1
  80. fi
  81. ;;
  82. restart|force-reload)
  83. log_daemon_msg "Restarting $DESC" "$NAME"
  84. if do_stop; then
  85. if do_start; then
  86. log_end_msg 0
  87. exit 0
  88. else
  89. rc="$?"
  90. fi
  91. else
  92. rc="$?"
  93. fi
  94. log_failure_msg "Can't restart etcd"
  95. log_end_msg ${rc}
  96. ;;
  97. *)
  98. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  99. exit 3
  100. ;;
  101. esac